diff --git a/backend/internal/database/db.go b/backend/internal/database/db.go index 7410b16..fd0a083 100644 --- a/backend/internal/database/db.go +++ b/backend/internal/database/db.go @@ -36,7 +36,6 @@ type Database interface { GetUserRole(username string, projectname string) (string, error) GetWeeklyReport(username string, projectName string, week int) (types.WeeklyReport, error) GetWeeklyReportsUser(username string, projectname string) ([]types.WeeklyReportList, error) - GetUnsignedWeeklyReports(projectName string) ([]types.WeeklyReport, error) SignWeeklyReport(reportId int, projectManagerId int) error IsSiteAdmin(username string) (bool, error) IsProjectManager(username string, projectname string) (bool, error) @@ -354,51 +353,6 @@ func (d *Db) SignWeeklyReport(reportId int, projectManagerId int) error { return err } -func (d *Db) GetUnsignedWeeklyReports(projectName string) ([]types.WeeklyReport, error) { - // Define the SQL query to fetch unsigned reports for a given user - query := ` - SELECT - report_id, - user_id, - project_id, - week, - development_time, - meeting_time, - admin_time, - own_work_time, - study_time, - testing_time, - signed_by - FROM - weekly_reports - WHERE - signed_by IS NULL - AND project_id = (SELECT id FROM projects WHERE name = ?) - ` - - // Execute the query - rows, err := d.Queryx(query, projectName) - if err != nil { - return nil, err - } - defer rows.Close() - - // Iterate over the rows and populate the result slice - var reports []types.WeeklyReport - for rows.Next() { - var report types.WeeklyReport - if err := rows.StructScan(&report); err != nil { - return nil, err - } - reports = append(reports, report) - } - if err := rows.Err(); err != nil { - return nil, err - } - - return reports, nil -} - // IsSiteAdmin checks if a given username is a site admin func (d *Db) IsSiteAdmin(username string) (bool, error) { // Define the SQL query to check if the user is a site admin diff --git a/backend/internal/database/db_test.go b/backend/internal/database/db_test.go index cff70a0..139fba9 100644 --- a/backend/internal/database/db_test.go +++ b/backend/internal/database/db_test.go @@ -470,37 +470,6 @@ func TestGetWeeklyReport(t *testing.T) { // Check other fields similarly } -func TestGetUnsignedWeeklyReports(t *testing.T) { - db, err := setupAdvancedState() - if err != nil { - t.Error("setupState failed:", err) - } - - err = db.AddUser("testuser", "password") - if err != nil { - t.Error("AddUser failed:", err) - } - - err = db.AddProject("testproject", "description", "testuser") - if err != nil { - t.Error("AddProject failed:", err) - } - - err = db.AddWeeklyReport("testproject", "testuser", 1, 1, 1, 1, 1, 1, 1) - if err != nil { - t.Error("AddWeeklyReport failed:", err) - } - - reports, err := db.GetUnsignedWeeklyReports("testproject") - if err != nil { - t.Error("GetUnsignedWeeklyReports failed:", err) - } - - if reports == nil { - t.Error("Expected non-nil reports, got nil") - } -} - // TestSignWeeklyReport tests SignWeeklyReport function of the database func TestSignWeeklyReport(t *testing.T) { db, err := setupState() diff --git a/backend/internal/handlers/global_state.go b/backend/internal/handlers/global_state.go index 6b197bb..b88bdcd 100644 --- a/backend/internal/handlers/global_state.go +++ b/backend/internal/handlers/global_state.go @@ -28,7 +28,6 @@ type GlobalState interface { ProjectRoleChange(c *fiber.Ctx) error // To change a users role in a project ChangeUserName(c *fiber.Ctx) error // WIP GetAllUsersProject(c *fiber.Ctx) error // WIP - GetUnsignedReports(c *fiber.Ctx) error // } // "Constructor" diff --git a/backend/internal/handlers/handlers_report_related.go b/backend/internal/handlers/handlers_report_related.go index 534050a..47d076d 100644 --- a/backend/internal/handlers/handlers_report_related.go +++ b/backend/internal/handlers/handlers_report_related.go @@ -32,7 +32,7 @@ func (gs *GState) SubmitWeeklyReport(c *fiber.Ctx) error { } if err := gs.Db.AddWeeklyReport(report.ProjectName, username, report.Week, report.DevelopmentTime, report.MeetingTime, report.AdminTime, report.OwnWorkTime, report.StudyTime, report.TestingTime); err != nil { - log.Info("Error adding weekly report to db:", err) + log.Info("Error adding weekly report") return c.Status(500).SendString(err.Error()) } @@ -115,42 +115,6 @@ func (gs *GState) SignReport(c *fiber.Ctx) error { return c.Status(200).SendString("Weekly report signed successfully") } -func (gs *GState) GetUnsignedReports(c *fiber.Ctx) error { - // Extract the necessary parameters from the token - user := c.Locals("user").(*jwt.Token) - claims := user.Claims.(jwt.MapClaims) - projectManagerUsername := claims["name"].(string) - - // Extract project name and week from query parameters - projectName := c.Query("projectName") - - log.Info("Getting unsigned reports for") - - if projectName == "" { - log.Info("Missing project name") - return c.Status(400).SendString("Missing project name") - } - - // Get the project manager's ID - isProjectManager, err := gs.Db.IsProjectManager(projectManagerUsername, projectName) - if err != nil { - log.Info("Failed to get project manager ID") - return c.Status(500).SendString("Failed to get project manager ID") - } - log.Info("User is Project Manager: ", isProjectManager) - - // Call the database function to get the unsigned weekly reports - reports, err := gs.Db.GetUnsignedWeeklyReports(projectName) - if err != nil { - log.Info("Error getting unsigned weekly reports:", err) - return c.Status(500).SendString(err.Error()) - } - - log.Info("Returning unsigned reports") - // Return the list of unsigned reports - return c.JSON(reports) -} - // GetWeeklyReportsUserHandler retrieves all weekly reports for a user in a specific project func (gs *GState) GetWeeklyReportsUserHandler(c *fiber.Ctx) error { // Extract the necessary parameters from the token diff --git a/backend/main.go b/backend/main.go index 835524c..ff6b94e 100644 --- a/backend/main.go +++ b/backend/main.go @@ -92,7 +92,6 @@ func main() { server.Get("/api/project/:projectId", gs.GetProject) server.Get("/api/project/getAllUsers", gs.GetAllUsersProject) server.Get("/api/getWeeklyReport", gs.GetWeeklyReport) - server.Get("/api/getUnsignedReports", gs.GetUnsignedReports) server.Post("/api/signReport", gs.SignReport) server.Put("/api/addUserToProject", gs.AddUserToProjectHandler) server.Put("/api/changeUserName", gs.ChangeUserName) diff --git a/frontend/src/Components/AllTimeReportsInProject.tsx b/frontend/src/Components/AllTimeReportsInProject.tsx index 14d3af9..fcd0f8f 100644 --- a/frontend/src/Components/AllTimeReportsInProject.tsx +++ b/frontend/src/Components/AllTimeReportsInProject.tsx @@ -30,7 +30,7 @@ function AllTimeReportsInProject(): JSX.Element { // Call getProjects when the component mounts useEffect(() => { void getWeeklyReports(); - }, []); + }); return ( <> diff --git a/testing.py b/testing.py index 3350497..384d7ce 100644 --- a/testing.py +++ b/testing.py @@ -41,7 +41,6 @@ getWeeklyReportsUserPath = base_url + "/api/getWeeklyReportsUser" checkIfProjectManagerPath = base_url + "/api/checkIfProjectManager" ProjectRoleChangePath = base_url + "/api/ProjectRoleChange" getUsersProjectPath = base_url + "/api/getUsersProject" -getUsignedReportsPath = base_url + "/api/getUsignedReports" #ta bort auth i handlern för att få testet att gå igenom def test_ProjectRoleChange(): @@ -275,7 +274,7 @@ def test_sign_report(): submitReportPath, json={ "projectName": projectName, - "week": 2, + "week": 1, "developmentTime": 10, "meetingTime": 5, "adminTime": 5, @@ -330,47 +329,6 @@ def test_get_weekly_reports_user(): assert response.status_code == 200, "Get weekly reports for user failed" gprint("test_get_weekly_reports_user successful") -def test_get_usigned_reports(): - # Log in as the user - - token = login(username, "always_same").json()["token"] - response = requests.post( - submitReportPath, - json={ - "projectName": projectName, - "week": 3, - "developmentTime": 10, - "meetingTime": 5, - "adminTime": 5, - "ownWorkTime": 10, - "studyTime": 10, - "testingTime": 10, - }, - headers={"Authorization": "Bearer " + token}, - ) - dprint(response.text) - assert response.status_code == 200, "Submit report failed" - - - # Get weekly reports for the user in the project - response = requests.get( - getWeeklyReportsUserPath + "/" + projectName, - headers={"Authorization": "Bearer " + token}, - ) - - dprint(response.text) - assert response.status_code == 200, "Get weekly reports for user failed" - - response = requests.get( - getUsignedReportsPath + "/" + projectName, - headers={"Authorization": "Bearer " + token}, - ) - dprint(response.text) - assert response.status_code == 200, "Get unsigned reports for user failed" - gprint("test_get_usigned_reports successful") - - - # Test function to check if a user is a project manager def test_check_if_project_manager(): # Log in as the user @@ -411,7 +369,6 @@ def test_ensure_manager_of_created_project(): if __name__ == "__main__": - test_get_usigned_reports() test_get_user_projects() test_create_user() test_login()