From b69f8d82ff43f440320eb74797b9f511f9f03613 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sun, 17 Mar 2024 03:46:16 +0100 Subject: [PATCH 1/5] Better testing comments --- testing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testing.py b/testing.py index fa97567..ff9534f 100644 --- a/testing.py +++ b/testing.py @@ -22,7 +22,7 @@ loginPath = base_url + "/api/login" addProjectPath = base_url + "/api/project" -# Define a function to prform POST request with data and return response +# Posts the username and password to the register endpoint def register(username: string, password: string): print("Registering with username: ", username, " and password: ", password) response = requests.post( @@ -32,6 +32,7 @@ def register(username: string, password: string): return response +# Posts the username and password to the login endpoint def login(username: string, password: string): print("Logging in with username: ", username, " and password: ", password) response = requests.post( @@ -48,7 +49,6 @@ def test_login(): return response.json()["token"] -# Define a function to test the POST request def test_create_user(): response = register(username, "always_same") assert response.status_code == 200, "Registration failed" From 23dd22eab59c152cf13b3b11db58e27b39fe502e Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sun, 17 Mar 2024 04:14:40 +0100 Subject: [PATCH 2/5] Json field alias for WeeklyReport --- backend/internal/types/WeeklyReport.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/backend/internal/types/WeeklyReport.go b/backend/internal/types/WeeklyReport.go index 23624db..e0ea1ef 100644 --- a/backend/internal/types/WeeklyReport.go +++ b/backend/internal/types/WeeklyReport.go @@ -3,19 +3,19 @@ package types // This is what should be submitted to the server, the username will be derived from the JWT token type NewWeeklyReport struct { // The name of the project, as it appears in the database - ProjectName string + ProjectName string `json:"projectName"` // The week number - Week int + Week int `json:"week"` // Total time spent on development - DevelopmentTime int + DevelopmentTime int `json:"developmentTime"` // Total time spent in meetings - MeetingTime int + MeetingTime int `json:"meetingTime"` // Total time spent on administrative tasks - AdminTime int + AdminTime int `json:"adminTime"` // Total time spent on personal projects - OwnWorkTime int + OwnWorkTime int `json:"ownWorkTime"` // Total time spent on studying - StudyTime int + StudyTime int `json:"studyTime"` // Total time spent on testing - TestingTime int + TestingTime int `json:"testingTime"` } From 0d053add5e93669b71d13d97a08108ce9a5a9ef4 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sun, 17 Mar 2024 04:16:26 +0100 Subject: [PATCH 3/5] Add some sanity checking in SubmitWeeklyReport route --- backend/internal/handlers/global_state.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/backend/internal/handlers/global_state.go b/backend/internal/handlers/global_state.go index 415b215..2378f7b 100644 --- a/backend/internal/handlers/global_state.go +++ b/backend/internal/handlers/global_state.go @@ -267,6 +267,14 @@ func (gs *GState) SubmitWeeklyReport(c *fiber.Ctx) error { return c.Status(400).SendString(err.Error()) } + // Make sure all the fields of the report are valid + if report.Week < 1 || report.Week > 52 { + return c.Status(400).SendString("Invalid week number") + } + if report.DevelopmentTime < 0 || report.MeetingTime < 0 || report.AdminTime < 0 || report.OwnWorkTime < 0 || report.StudyTime < 0 || report.TestingTime < 0 { + return c.Status(400).SendString("Invalid time report") + } + if err := gs.Db.AddWeeklyReport(report.ProjectName, username, report.Week, report.DevelopmentTime, report.MeetingTime, report.AdminTime, report.OwnWorkTime, report.StudyTime, report.TestingTime); err != nil { return c.Status(500).SendString(err.Error()) } From dbb2ff84e56ae60f0d1bba64e1487e0e7d605e02 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sun, 17 Mar 2024 04:16:54 +0100 Subject: [PATCH 4/5] WeeklyReport testing --- testing.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/testing.py b/testing.py index ff9534f..d2c64fe 100644 --- a/testing.py +++ b/testing.py @@ -11,7 +11,7 @@ def randomString(len=10): # Defined once per test run username = randomString() -token = None +projectName = randomString() # The base URL of the API base_url = "http://localhost:8080" @@ -20,6 +20,7 @@ base_url = "http://localhost:8080" registerPath = base_url + "/api/register" loginPath = base_url + "/api/login" addProjectPath = base_url + "/api/project" +submitReportPath = base_url + "/api/submitReport" # Posts the username and password to the register endpoint @@ -58,7 +59,6 @@ def test_create_user(): def test_add_project(): loginResponse = login(username, "always_same") token = loginResponse.json()["token"] - projectName = randomString() response = requests.post( addProjectPath, json={"name": projectName, "description": "This is a project"}, @@ -69,7 +69,29 @@ def test_add_project(): print("Add project successful") +def test_submit_report(): + token = login(username, "always_same").json()["token"] + response = requests.post( + submitReportPath, + json={ + "projectName": "report1", + "week": 1, + "developmentTime": 10, + "meetingTime": 5, + "adminTime": 5, + "ownWorkTime": 10, + "studyTime": 10, + "testingTime": 10, + }, + headers={"Authorization": "Bearer " + token}, + ) + print(response.text) + assert response.status_code == 200, "Submit report failed" + print("Submit report successful") + + if __name__ == "__main__": test_create_user() test_login() test_add_project() + test_submit_report() From 887f31dde001a477c1b0048064df618779762299 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sun, 17 Mar 2024 04:23:26 +0100 Subject: [PATCH 5/5] goTypes generated from go code with tygo --- frontend/src/Types/goTypes.ts | 88 +++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 frontend/src/Types/goTypes.ts diff --git a/frontend/src/Types/goTypes.ts b/frontend/src/Types/goTypes.ts new file mode 100644 index 0000000..89084b7 --- /dev/null +++ b/frontend/src/Types/goTypes.ts @@ -0,0 +1,88 @@ +// Code generated by tygo. DO NOT EDIT. + +////////// +// source: WeeklyReport.go + +/** + * This is what should be submitted to the server, the username will be derived from the JWT token + */ +export interface NewWeeklyReport { + /** + * The name of the project, as it appears in the database + */ + projectName: string; + /** + * The week number + */ + week: number /* int */; + /** + * Total time spent on development + */ + developmentTime: number /* int */; + /** + * Total time spent in meetings + */ + meetingTime: number /* int */; + /** + * Total time spent on administrative tasks + */ + adminTime: number /* int */; + /** + * Total time spent on personal projects + */ + ownWorkTime: number /* int */; + /** + * Total time spent on studying + */ + studyTime: number /* int */; + /** + * Total time spent on testing + */ + testingTime: number /* int */; +} + +////////// +// source: project.go + +/** + * Project is a struct that holds the information about a project + */ +export interface Project { + id: number /* int */; + name: string; + description: string; + owner: string; +} +/** + * As it arrives from the client, Owner is derived from the JWT token + */ +export interface NewProject { + name: string; + description: string; +} + +////////// +// source: users.go + +/** + * User struct represents a user in the system + */ +export interface User { + userId: string; + username: string; + password: string; +} +/** + * Should be used when registering, for example + */ +export interface NewUser { + username: string; + password: string; +} +/** + * PublicUser represents a user that is safe to send over the API (no password) + */ +export interface PublicUser { + userId: string; + username: string; +}