From 685a40e5d147404b7fa3d61e632af9e77caa1195 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sat, 9 Mar 2024 15:07:42 +0100 Subject: [PATCH 01/32] Containerfile fix for new path to main --- container/Containerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/container/Containerfile b/container/Containerfile index 23d177c..ecd2f84 100644 --- a/container/Containerfile +++ b/container/Containerfile @@ -27,7 +27,7 @@ ADD backend . RUN make migrate # RUN go build -o server -RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -o ./server ./cmd/ +RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -o ./server ./main.go # Strip the binary for a smaller image RUN strip ./server @@ -54,4 +54,4 @@ EXPOSE 8080 USER nonroot:nonroot # Run the server -CMD ["./server"] \ No newline at end of file +CMD ["./server"] From 07b9f6fca4023892d01e45104778094d38e00cdb Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sat, 9 Mar 2024 15:07:42 +0100 Subject: [PATCH 02/32] Containerfile fix for new path to main --- container/Containerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/container/Containerfile b/container/Containerfile index 23d177c..ecd2f84 100644 --- a/container/Containerfile +++ b/container/Containerfile @@ -27,7 +27,7 @@ ADD backend . RUN make migrate # RUN go build -o server -RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -o ./server ./cmd/ +RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -o ./server ./main.go # Strip the binary for a smaller image RUN strip ./server @@ -54,4 +54,4 @@ EXPOSE 8080 USER nonroot:nonroot # Run the server -CMD ["./server"] \ No newline at end of file +CMD ["./server"] From 1672b100d91dc83105a1a62cc3b23d10a5bc1c7b Mon Sep 17 00:00:00 2001 From: Peter KW Date: Thu, 7 Mar 2024 17:48:43 +0100 Subject: [PATCH 03/32] added new page for admin and path in main --- .../src/Pages/AdminPages/AdminMenuPage.tsx | 27 +++++++++++++++++++ frontend/src/main.tsx | 5 ++++ 2 files changed, 32 insertions(+) create mode 100644 frontend/src/Pages/AdminPages/AdminMenuPage.tsx diff --git a/frontend/src/Pages/AdminPages/AdminMenuPage.tsx b/frontend/src/Pages/AdminPages/AdminMenuPage.tsx new file mode 100644 index 0000000..1b32ed4 --- /dev/null +++ b/frontend/src/Pages/AdminPages/AdminMenuPage.tsx @@ -0,0 +1,27 @@ +import { Link } from "react-router-dom"; +import BasicWindow from "../../Components/BasicWindow"; + +function AdminMenuPage(): JSX.Element { + const content = ( + <> +

Administrator Menu

+
+ +

+ Manage Users +

+ + +

+ Manage Projects +

+ +
+ + ); + + const buttons = <>; + + return ; +} +export default AdminMenuPage; diff --git a/frontend/src/main.tsx b/frontend/src/main.tsx index d5616c7..03091a2 100644 --- a/frontend/src/main.tsx +++ b/frontend/src/main.tsx @@ -5,6 +5,7 @@ import { createBrowserRouter, RouterProvider } from "react-router-dom"; import LoginPage from "./Pages/LoginPage.tsx"; import YourProjectsPage from "./Pages/YourProjectsPage.tsx"; import UserProjectPage from "./Pages/UserPages/UserProjectPage.tsx"; +import AdminMenuPage from "./Pages/AdminPages/AdminMenuPage.tsx"; // This is where the routes are mounted const router = createBrowserRouter([ @@ -20,6 +21,10 @@ const router = createBrowserRouter([ path: "/project", element: , }, + { + path: "/admin-menu", + element: , + }, ]); // Semi-hacky way to get the root element From 41674c39695adae637d095df53c7808f1cd5d3be Mon Sep 17 00:00:00 2001 From: Mattias Date: Fri, 8 Mar 2024 11:36:36 +0100 Subject: [PATCH 04/32] Removed example pages Home and Settings aswell as the react-logo --- frontend/src/Pages/Home.tsx | 36 --------------------------------- frontend/src/Pages/Settings.tsx | 17 ---------------- frontend/src/assets/react.svg | 1 - 3 files changed, 54 deletions(-) delete mode 100644 frontend/src/Pages/Home.tsx delete mode 100644 frontend/src/Pages/Settings.tsx delete mode 100644 frontend/src/assets/react.svg diff --git a/frontend/src/Pages/Home.tsx b/frontend/src/Pages/Home.tsx deleted file mode 100644 index 7ce73a6..0000000 --- a/frontend/src/Pages/Home.tsx +++ /dev/null @@ -1,36 +0,0 @@ -import reactLogo from "../assets/react.svg"; -import viteLogo from "/vite.svg"; -import "../index.css"; -import { CountButton } from "../Components/CountButton"; -import { Link } from "react-router-dom"; - -/** - * The home page of the application - * @returns {JSX.Element} The home page - */ -export default function HomePage(): JSX.Element { - return ( - <> - -

Vite + React

-
- - To Settings -
-

- Click on the Vite and React logos to learn more -

- - ); -} diff --git a/frontend/src/Pages/Settings.tsx b/frontend/src/Pages/Settings.tsx deleted file mode 100644 index b5bf81c..0000000 --- a/frontend/src/Pages/Settings.tsx +++ /dev/null @@ -1,17 +0,0 @@ -import "../index.css"; -import { Link } from "react-router-dom"; - -/** - * The settings page of the application - * @returns {JSX.Element} The settings page - */ -export default function SettingsPage(): JSX.Element { - return ( - <> -

Very Fancy Settings Page

-
- To Home -
- - ); -} diff --git a/frontend/src/assets/react.svg b/frontend/src/assets/react.svg deleted file mode 100644 index 6c87de9..0000000 --- a/frontend/src/assets/react.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file From 6b09cfbf232ca717642741b5f408f92cb55a7b73 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Wed, 13 Mar 2024 16:25:50 +0100 Subject: [PATCH 05/32] New directories for Types and API in frontned --- frontend/src/API/README.md | 3 +++ frontend/src/Types/README.md | 4 ++++ 2 files changed, 7 insertions(+) create mode 100644 frontend/src/API/README.md create mode 100644 frontend/src/Types/README.md diff --git a/frontend/src/API/README.md b/frontend/src/API/README.md new file mode 100644 index 0000000..cba9b03 --- /dev/null +++ b/frontend/src/API/README.md @@ -0,0 +1,3 @@ +# API + +This file contains the high-level API interface and implementation. diff --git a/frontend/src/Types/README.md b/frontend/src/Types/README.md new file mode 100644 index 0000000..8ea4251 --- /dev/null +++ b/frontend/src/Types/README.md @@ -0,0 +1,4 @@ +# Types + +This directory contains TypeScript type definitions for the frontend. +This is primarily used by, but not limited to, the API responses and requests. From 3a7663124d92fcfdefb02103119e0c9aec8afed2 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Wed, 13 Mar 2024 17:06:26 +0100 Subject: [PATCH 06/32] Basic api funcitonality in frontend --- frontend/src/API/API.ts | 32 ++++++++++++++++++++++++++++++++ frontend/src/Types/Users.ts | 11 +++++++++++ 2 files changed, 43 insertions(+) create mode 100644 frontend/src/API/API.ts create mode 100644 frontend/src/Types/Users.ts diff --git a/frontend/src/API/API.ts b/frontend/src/API/API.ts new file mode 100644 index 0000000..2dbd51e --- /dev/null +++ b/frontend/src/API/API.ts @@ -0,0 +1,32 @@ +import { NewUser, User } from "../Types/Users"; + +// Defines all the methods that an instance of the API must implement +interface API { + /** Register a new user */ + registerUser(user: NewUser): Promise; + /** Remove a user */ + removeUser(username: string): Promise; +} + +// Export an instance of the API +export const api: API = { + async registerUser(user: NewUser): Promise { + return fetch("/api/register", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(user), + }).then((res) => res.json() as Promise); + }, + + async removeUser(username: string): Promise { + return fetch("/api/userdelete", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(username), + }).then((res) => res.json() as Promise); + }, +}; diff --git a/frontend/src/Types/Users.ts b/frontend/src/Types/Users.ts new file mode 100644 index 0000000..2a195b2 --- /dev/null +++ b/frontend/src/Types/Users.ts @@ -0,0 +1,11 @@ +// This is how the API responds +export interface User { + id: number; + name: string; +} + +// Used to create a new user +export interface NewUser { + name: string; + password: string; +} From 1c87380db76e8ad8ff6ff6b87df220fa3a07b412 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Wed, 13 Mar 2024 17:52:37 +0100 Subject: [PATCH 07/32] Mounting handler for adding project --- backend/main.go | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/main.go b/backend/main.go index 1aaca45..bba3fa6 100644 --- a/backend/main.go +++ b/backend/main.go @@ -71,6 +71,7 @@ func main() { server.Post("/api/loginrenew", gs.LoginRenew) server.Delete("/api/userdelete", gs.UserDelete) // Perhaps just use POST to avoid headaches + server.Post("/api/project", gs.CreateProject) // Announce the port we are listening on and start the server err = server.Listen(fmt.Sprintf(":%d", conf.Port)) From b5c29872818184fa95e2bd029dc83e0b35fb7898 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Wed, 13 Mar 2024 17:52:56 +0100 Subject: [PATCH 08/32] Add project API interface in frontend --- frontend/src/API/API.ts | 13 +++++++++++++ frontend/src/Types/Project.ts | 13 +++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 frontend/src/Types/Project.ts diff --git a/frontend/src/API/API.ts b/frontend/src/API/API.ts index 2dbd51e..24854c0 100644 --- a/frontend/src/API/API.ts +++ b/frontend/src/API/API.ts @@ -1,3 +1,4 @@ +import { NewProject, Project } from "../Types/Project"; import { NewUser, User } from "../Types/Users"; // Defines all the methods that an instance of the API must implement @@ -6,6 +7,8 @@ interface API { registerUser(user: NewUser): Promise; /** Remove a user */ removeUser(username: string): Promise; + /** Create a project */ + createProject(project: NewProject): Promise; } // Export an instance of the API @@ -29,4 +32,14 @@ export const api: API = { body: JSON.stringify(username), }).then((res) => res.json() as Promise); }, + + async createProject(project: NewProject): Promise { + return fetch("/api/project", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(project), + }).then((res) => res.json() as Promise); + }, }; diff --git a/frontend/src/Types/Project.ts b/frontend/src/Types/Project.ts new file mode 100644 index 0000000..bb4f8c7 --- /dev/null +++ b/frontend/src/Types/Project.ts @@ -0,0 +1,13 @@ +export interface Project { + id: number; + name: string; + description: string; + owner: string; + created: string; // This is a date +} + +export interface NewProject { + name: string; + description: string; + owner: string; +} From a4b19e32eb39b5d4d26324bf897eaa1bd1ce985a Mon Sep 17 00:00:00 2001 From: Hollgy Date: Wed, 13 Mar 2024 17:56:04 +0100 Subject: [PATCH 09/32] Boilerplate added for register, non functional --- frontend/src/Components/Register.tsx | 82 ++++++++++++++++++++++++++++ frontend/src/Pages/LoginPage.tsx | 9 +++ frontend/src/Types/Users.ts | 4 +- frontend/src/main.tsx | 5 ++ 4 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 frontend/src/Components/Register.tsx diff --git a/frontend/src/Components/Register.tsx b/frontend/src/Components/Register.tsx new file mode 100644 index 0000000..e0caf46 --- /dev/null +++ b/frontend/src/Components/Register.tsx @@ -0,0 +1,82 @@ +import { useState } from "react"; +import { NewUser, User } from "../Types/Users"; + +export default function Register() { +const [username, setUsername] = useState('') +const [password, setPassword] = useState('') +const [error, setError] = useState('') + + + + const handleRegister = async () => { + try { + const newUser: NewUser = { username, password }; + const registeredUser: User = await api.registerUser(newUser); + console.log("User registered:", registeredUser); + // Optionally, you can navigate to another page or show a success message here + } catch (error) { + setError("Registration failed. Please try again."); // Handle error appropriately + } + }; + + return ( +
+
+
{ + e.preventDefault(); + handleRegister(); + }} + > +

Register new user

+
+ + setUsername(e.target.value)} + /> +
+
+ + setPassword(e.target.value)} + /> +

+ Please choose a password. +

+
+
+ +
+ {error &&

{error}

} +
+

+
+
+ ); +} diff --git a/frontend/src/Pages/LoginPage.tsx b/frontend/src/Pages/LoginPage.tsx index d8ea651..11a7da2 100644 --- a/frontend/src/Pages/LoginPage.tsx +++ b/frontend/src/Pages/LoginPage.tsx @@ -3,6 +3,7 @@ import Logo from "/src/assets/TTIMElogo.png"; import "./LoginPage.css"; import { useEffect } from "react"; import { Link } from "react-router-dom"; +import Register from "../Components/Register"; const PreloadBackgroundAnimation = (): JSX.Element => { useEffect(() => { @@ -69,6 +70,14 @@ function LoginPage(): JSX.Element { }} /> + +