From b5c29872818184fa95e2bd029dc83e0b35fb7898 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Wed, 13 Mar 2024 17:52:56 +0100 Subject: [PATCH] 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; +}