From 685a40e5d147404b7fa3d61e632af9e77caa1195 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sat, 9 Mar 2024 15:07:42 +0100 Subject: [PATCH 1/3] 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 6b09cfbf232ca717642741b5f408f92cb55a7b73 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Wed, 13 Mar 2024 16:25:50 +0100 Subject: [PATCH 2/3] 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 3/3] 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; +}