Merge branch 'dev' into frontend
This commit is contained in:
commit
7cc74866fc
6 changed files with 59 additions and 98 deletions
|
@ -37,13 +37,16 @@ func (gs *GState) SubmitWeeklyReport(c *fiber.Ctx) error {
|
||||||
// Handler for retrieving weekly report
|
// Handler for retrieving weekly report
|
||||||
func (gs *GState) GetWeeklyReport(c *fiber.Ctx) error {
|
func (gs *GState) GetWeeklyReport(c *fiber.Ctx) error {
|
||||||
// Extract the necessary parameters from the request
|
// Extract the necessary parameters from the request
|
||||||
|
println("GetWeeklyReport")
|
||||||
user := c.Locals("user").(*jwt.Token)
|
user := c.Locals("user").(*jwt.Token)
|
||||||
claims := user.Claims.(jwt.MapClaims)
|
claims := user.Claims.(jwt.MapClaims)
|
||||||
username := claims["name"].(string)
|
username := claims["name"].(string)
|
||||||
|
|
||||||
// Extract project name and week from query parameters
|
// Extract project name and week from query parameters
|
||||||
projectName := c.Query("projectName")
|
projectName := c.Query("projectName")
|
||||||
|
println(projectName)
|
||||||
week := c.Query("week")
|
week := c.Query("week")
|
||||||
|
println(week)
|
||||||
|
|
||||||
// Convert week to integer
|
// Convert week to integer
|
||||||
weekInt, err := strconv.Atoi(week)
|
weekInt, err := strconv.Atoi(week)
|
||||||
|
|
|
@ -78,6 +78,7 @@ func main() {
|
||||||
server.Post("/api/loginrenew", gs.LoginRenew)
|
server.Post("/api/loginrenew", gs.LoginRenew)
|
||||||
server.Delete("/api/userdelete/:username", gs.UserDelete) // Perhaps just use POST to avoid headaches
|
server.Delete("/api/userdelete/:username", gs.UserDelete) // Perhaps just use POST to avoid headaches
|
||||||
server.Post("/api/project", gs.CreateProject)
|
server.Post("/api/project", gs.CreateProject)
|
||||||
|
server.Get("/api/getWeeklyReport", gs.GetWeeklyReport)
|
||||||
|
|
||||||
// Announce the port we are listening on and start the server
|
// Announce the port we are listening on and start the server
|
||||||
err = server.Listen(fmt.Sprintf(":%d", conf.Port))
|
err = server.Listen(fmt.Sprintf(":%d", conf.Port))
|
||||||
|
|
|
@ -1,87 +0,0 @@
|
||||||
import { describe, expect, test } from "@jest/globals";
|
|
||||||
import { api } from "../API/API";
|
|
||||||
import { NewUser, NewWeeklyReport } from "../Types/goTypes";
|
|
||||||
|
|
||||||
describe("API", () => {
|
|
||||||
test("registerUser", async () => {
|
|
||||||
const user: NewUser = {
|
|
||||||
username: "lol", // Add the username property
|
|
||||||
password: "lol",
|
|
||||||
};
|
|
||||||
const response = await api.registerUser(user);
|
|
||||||
console.log(response.message);
|
|
||||||
expect(response.success).toBe(true);
|
|
||||||
expect(response.data).toHaveProperty("userId");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("createProject", async () => {
|
|
||||||
const project = {
|
|
||||||
name: "Project X",
|
|
||||||
description: "This is a test project",
|
|
||||||
};
|
|
||||||
const token =
|
|
||||||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhZG1pbiI6ZmFsc2UsImV4cCI6MTcxMDk0MDIwMywibmFtZSI6InJyZ3VtZHpwbWMifQ.V9NHoYMYV61t";
|
|
||||||
|
|
||||||
const response = await api.createProject(project, token);
|
|
||||||
console.log(response.message);
|
|
||||||
expect(response.success).toBe(true);
|
|
||||||
expect(response.data).toHaveProperty("projectId");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("renewToken", async () => {
|
|
||||||
const refreshToken =
|
|
||||||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhZG1pbiI6ZmFsc2UsImV4cCI6MTcxMDk0MDIwMywibmFtZSI6InJyZ3VtZHpwbWMifQ.V9NHoYMYV61t";
|
|
||||||
|
|
||||||
const response = await api.renewToken(refreshToken);
|
|
||||||
console.log(response.message);
|
|
||||||
expect(response.success).toBe(true);
|
|
||||||
expect(response.data).toHaveProperty("accessToken");
|
|
||||||
expect(response.data).toHaveProperty("refreshToken");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("getUserProjects", async () => {
|
|
||||||
const token =
|
|
||||||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhZG1pbiI6ZmFsc2UsImV4cCI6MTcxMDk0MDIwMywibmFtZSI6InJyZ3VtZHpwbWMifQ.V9NHoYMYV61t";
|
|
||||||
const username = "rrgumdzpmc";
|
|
||||||
const response = await api.getUserProjects(username, token);
|
|
||||||
console.log(response.message);
|
|
||||||
expect(response.success).toBe(true);
|
|
||||||
expect(response.data).toHaveProperty("projects");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("submitWeeklyReport", async () => {
|
|
||||||
const report: NewWeeklyReport = {
|
|
||||||
projectName: "vtmosxssst",
|
|
||||||
week: 2,
|
|
||||||
developmentTime: 40,
|
|
||||||
meetingTime: 5,
|
|
||||||
adminTime: 2,
|
|
||||||
ownWorkTime: 10,
|
|
||||||
studyTime: 12,
|
|
||||||
testingTime: 41,
|
|
||||||
};
|
|
||||||
const token =
|
|
||||||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhZG1pbiI6ZmFsc2UsImV4cCI6MTcxMDk0MDIwMywibmFtZSI6InJyZ3VtZHpwbWMifQ.V9NHoYMYV61t";
|
|
||||||
|
|
||||||
const response = await api.submitWeeklyReport(report, token);
|
|
||||||
console.log(response.message);
|
|
||||||
expect(response.success).toBe(true);
|
|
||||||
expect(response.data).toHaveProperty(
|
|
||||||
"message",
|
|
||||||
"Report submitted successfully",
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("login", async () => {
|
|
||||||
const user: NewUser = {
|
|
||||||
username: "rrgumdzpmc", // Add an empty string value for the username property
|
|
||||||
password: "always_same",
|
|
||||||
};
|
|
||||||
|
|
||||||
const response = await api.login(user);
|
|
||||||
console.log(response.message);
|
|
||||||
expect(response.success).toBe(true);
|
|
||||||
expect(response.data).toHaveProperty("accessToken");
|
|
||||||
expect(response.data).toHaveProperty("refreshToken");
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -20,6 +20,10 @@ interface API {
|
||||||
registerUser(user: NewUser): Promise<APIResponse<User>>;
|
registerUser(user: NewUser): Promise<APIResponse<User>>;
|
||||||
/** Remove a user */
|
/** Remove a user */
|
||||||
removeUser(username: string, token: string): Promise<APIResponse<User>>;
|
removeUser(username: string, token: string): Promise<APIResponse<User>>;
|
||||||
|
/** Login */
|
||||||
|
login(NewUser: NewUser): Promise<APIResponse<string>>;
|
||||||
|
/** Renew the token */
|
||||||
|
renewToken(token: string): Promise<APIResponse<string>>;
|
||||||
/** Create a project */
|
/** Create a project */
|
||||||
createProject(
|
createProject(
|
||||||
project: NewProject,
|
project: NewProject,
|
||||||
|
@ -29,16 +33,19 @@ interface API {
|
||||||
submitWeeklyReport(
|
submitWeeklyReport(
|
||||||
project: NewWeeklyReport,
|
project: NewWeeklyReport,
|
||||||
token: string,
|
token: string,
|
||||||
): Promise<APIResponse<Project>>;
|
): Promise<APIResponse<NewWeeklyReport>>;
|
||||||
/** Renew the token */
|
/**Gets a weekly report*/
|
||||||
renewToken(token: string): Promise<APIResponse<string>>;
|
getWeeklyReport(
|
||||||
|
username: string,
|
||||||
|
projectName: string,
|
||||||
|
week: string,
|
||||||
|
token: string,
|
||||||
|
): Promise<APIResponse<NewWeeklyReport>>;
|
||||||
/** Gets all the projects of a user*/
|
/** Gets all the projects of a user*/
|
||||||
getUserProjects(
|
getUserProjects(
|
||||||
username: string,
|
username: string,
|
||||||
token: string,
|
token: string,
|
||||||
): Promise<APIResponse<Project[]>>;
|
): Promise<APIResponse<Project[]>>;
|
||||||
/** Login */
|
|
||||||
login(NewUser: NewUser): Promise<APIResponse<string>>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Export an instance of the API
|
// Export an instance of the API
|
||||||
|
@ -169,9 +176,9 @@ export const api: API = {
|
||||||
},
|
},
|
||||||
|
|
||||||
async submitWeeklyReport(
|
async submitWeeklyReport(
|
||||||
project: NewWeeklyReport,
|
weeklyReport: NewWeeklyReport,
|
||||||
token: string,
|
token: string,
|
||||||
): Promise<APIResponse<Project>> {
|
): Promise<APIResponse<NewWeeklyReport>> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/api/submitWeeklyReport", {
|
const response = await fetch("/api/submitWeeklyReport", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
@ -179,7 +186,7 @@ export const api: API = {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Authorization: "Bearer " + token,
|
Authorization: "Bearer " + token,
|
||||||
},
|
},
|
||||||
body: JSON.stringify(project),
|
body: JSON.stringify(weeklyReport),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
@ -189,7 +196,7 @@ export const api: API = {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = (await response.json()) as Project;
|
const data = (await response.json()) as NewWeeklyReport;
|
||||||
return { success: true, data };
|
return { success: true, data };
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return {
|
return {
|
||||||
|
@ -199,6 +206,33 @@ export const api: API = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async getWeeklyReport(
|
||||||
|
username: string,
|
||||||
|
projectName: string,
|
||||||
|
week: string,
|
||||||
|
token: string,
|
||||||
|
): Promise<APIResponse<NewWeeklyReport>> {
|
||||||
|
try {
|
||||||
|
const response = await fetch("/api/getWeeklyReport", {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
Authorization: "Bearer " + token,
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ username, projectName, week }),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
return { success: false, message: "Failed to get weekly report" };
|
||||||
|
} else {
|
||||||
|
const data = (await response.json()) as NewWeeklyReport;
|
||||||
|
return { success: true, data };
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
return { success: false, message: "Failed to get weekly report" };
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
async login(NewUser: NewUser): Promise<APIResponse<string>> {
|
async login(NewUser: NewUser): Promise<APIResponse<string>> {
|
||||||
try {
|
try {
|
||||||
const response = await fetch("/api/login", {
|
const response = await fetch("/api/login", {
|
||||||
|
|
|
@ -40,7 +40,7 @@ export default function Register(): JSX.Element {
|
||||||
|
|
||||||
const handleRegister = async (): Promise<void> => {
|
const handleRegister = async (): Promise<void> => {
|
||||||
const newUser: NewUser = {
|
const newUser: NewUser = {
|
||||||
userName: username ?? "",
|
username: username ?? "",
|
||||||
password: password ?? "",
|
password: password ?? "",
|
||||||
};
|
};
|
||||||
const response = await api.registerUser(newUser);
|
const response = await api.registerUser(newUser);
|
||||||
|
|
12
testing.py
12
testing.py
|
@ -21,6 +21,7 @@ registerPath = base_url + "/api/register"
|
||||||
loginPath = base_url + "/api/login"
|
loginPath = base_url + "/api/login"
|
||||||
addProjectPath = base_url + "/api/project"
|
addProjectPath = base_url + "/api/project"
|
||||||
submitReportPath = base_url + "/api/submitReport"
|
submitReportPath = base_url + "/api/submitReport"
|
||||||
|
getWeeklyReportPath = base_url + "/api/getWeeklyReport"
|
||||||
|
|
||||||
|
|
||||||
# Posts the username and password to the register endpoint
|
# Posts the username and password to the register endpoint
|
||||||
|
@ -74,7 +75,7 @@ def test_submit_report():
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
submitReportPath,
|
submitReportPath,
|
||||||
json={
|
json={
|
||||||
"projectName": "report1",
|
"projectName": projectName,
|
||||||
"week": 1,
|
"week": 1,
|
||||||
"developmentTime": 10,
|
"developmentTime": 10,
|
||||||
"meetingTime": 5,
|
"meetingTime": 5,
|
||||||
|
@ -89,9 +90,18 @@ def test_submit_report():
|
||||||
assert response.status_code == 200, "Submit report failed"
|
assert response.status_code == 200, "Submit report failed"
|
||||||
print("Submit report successful")
|
print("Submit report successful")
|
||||||
|
|
||||||
|
def test_get_weekly_report():
|
||||||
|
token = login(username, "always_same").json()["token"]
|
||||||
|
response = requests.get(
|
||||||
|
getWeeklyReportPath,
|
||||||
|
headers={"Authorization": "Bearer " + token},
|
||||||
|
params={"username": username, "projectName": projectName , "week": 1}
|
||||||
|
)
|
||||||
|
print(response.text)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
test_create_user()
|
test_create_user()
|
||||||
test_login()
|
test_login()
|
||||||
test_add_project()
|
test_add_project()
|
||||||
test_submit_report()
|
test_submit_report()
|
||||||
|
test_get_weekly_report()
|
Loading…
Reference in a new issue