Compare commits
8 commits
fdaba36d57
...
ecce80babc
Author | SHA1 | Date | |
---|---|---|---|
![]() |
ecce80babc | ||
![]() |
b7523cf04d | ||
![]() |
a2a8ccd185 | ||
![]() |
8aa9e285b8 | ||
![]() |
afa445a426 | ||
![]() |
740289decc | ||
![]() |
ddea76e24a | ||
![]() |
c4b8bef7f8 |
6 changed files with 43 additions and 13 deletions
|
@ -1,5 +1,5 @@
|
|||
CREATE TABLE IF NOT EXISTS weekly_reports (
|
||||
report_id INTEGER AUTO_INCREMENT UNIQUE,
|
||||
report_id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
user_id INTEGER NOT NULL,
|
||||
project_id INTEGER NOT NULL,
|
||||
week INTEGER NOT NULL,
|
||||
|
@ -10,8 +10,8 @@ CREATE TABLE IF NOT EXISTS weekly_reports (
|
|||
study_time INTEGER,
|
||||
testing_time INTEGER,
|
||||
signed_by INTEGER,
|
||||
UNIQUE(user_id, project_id, week),
|
||||
FOREIGN KEY (user_id) REFERENCES users(id),
|
||||
FOREIGN KEY (project_id) REFERENCES projects(id),
|
||||
FOREIGN KEY (signed_by) REFERENCES users(id),
|
||||
PRIMARY KEY (user_id, project_id, week)
|
||||
FOREIGN KEY (signed_by) REFERENCES users(id)
|
||||
);
|
|
@ -89,13 +89,13 @@ func (gs *GState) SignReport(c *fiber.Ctx) error {
|
|||
|
||||
log.Info("Signing report for: ", projectManagerUsername)
|
||||
|
||||
// Extract report ID from the request query parameters
|
||||
// reportID := c.Query("reportId")
|
||||
rid := new(ReportId)
|
||||
if err := c.BodyParser(rid); err != nil {
|
||||
return err
|
||||
// Extract report ID from the request
|
||||
rid, err := strconv.Atoi(c.Params("reportId"))
|
||||
if err != nil {
|
||||
log.Info("Invalid report ID:", err)
|
||||
return c.Status(400).SendString("Invalid report ID")
|
||||
}
|
||||
log.Info("Signing report for: ", rid.ReportId)
|
||||
log.Info("Signing report for: ", rid)
|
||||
|
||||
// Get the project manager's ID
|
||||
projectManagerID, err := gs.Db.GetUserId(projectManagerUsername)
|
||||
|
@ -106,7 +106,7 @@ func (gs *GState) SignReport(c *fiber.Ctx) error {
|
|||
log.Info("Project manager ID: ", projectManagerID)
|
||||
|
||||
// Call the database function to sign the weekly report
|
||||
err = gs.Db.SignWeeklyReport(rid.ReportId, projectManagerID)
|
||||
err = gs.Db.SignWeeklyReport(rid, projectManagerID)
|
||||
if err != nil {
|
||||
log.Info("Error signing weekly report:", err)
|
||||
return c.Status(500).SendString(err.Error())
|
||||
|
|
|
@ -92,7 +92,7 @@ func main() {
|
|||
server.Get("/api/project/:projectId", gs.GetProject)
|
||||
server.Get("/api/project/getAllUsers", gs.GetAllUsersProject)
|
||||
server.Get("/api/getWeeklyReport", gs.GetWeeklyReport)
|
||||
server.Post("/api/signReport", gs.SignReport)
|
||||
server.Post("/api/signReport/:reportId", gs.SignReport)
|
||||
server.Put("/api/addUserToProject", gs.AddUserToProjectHandler)
|
||||
server.Put("/api/changeUserName", gs.ChangeUserName)
|
||||
server.Post("/api/promoteToAdmin", gs.PromoteToAdmin)
|
||||
|
|
|
@ -127,6 +127,11 @@ interface API {
|
|||
* @returns {Promise<APIResponse<string[]>>} A promise resolving to an API response containing the list of users.
|
||||
*/
|
||||
getAllUsers(token: string): Promise<APIResponse<string[]>>;
|
||||
|
||||
/**
|
||||
* Sign a report
|
||||
*/
|
||||
signReport(reportId: number, token: string): Promise<APIResponse<boolean>>;
|
||||
}
|
||||
|
||||
/** An instance of the API */
|
||||
|
@ -448,4 +453,29 @@ export const api: API = {
|
|||
});
|
||||
}
|
||||
},
|
||||
|
||||
async signReport(
|
||||
reportId: number,
|
||||
token: string,
|
||||
): Promise<APIResponse<boolean>> {
|
||||
try {
|
||||
const response = await fetch(`/api/signReport/${reportId}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: "Bearer " + token,
|
||||
},
|
||||
});
|
||||
if (!response.ok) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Failed to sign report:" + response.status,
|
||||
};
|
||||
} else {
|
||||
return { success: true };
|
||||
}
|
||||
} catch (e) {
|
||||
return { success: false, message: "Failed to sign report" };
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
|
@ -30,7 +30,7 @@ function AllTimeReportsInProject(): JSX.Element {
|
|||
// Call getProjects when the component mounts
|
||||
useEffect(() => {
|
||||
void getWeeklyReports();
|
||||
});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
|
|
@ -274,7 +274,7 @@ def test_sign_report():
|
|||
submitReportPath,
|
||||
json={
|
||||
"projectName": projectName,
|
||||
"week": 1,
|
||||
"week": 2,
|
||||
"developmentTime": 10,
|
||||
"meetingTime": 5,
|
||||
"adminTime": 5,
|
||||
|
|
Loading…
Reference in a new issue