From 9141e7b464fd9ecaf00fdd059480f928fe7f66d7 Mon Sep 17 00:00:00 2001 From: Eden Xu <130119691+FlyingPufferFish@users.noreply.github.com> Date: Wed, 23 Oct 2024 21:22:38 +1100 Subject: [PATCH 1/4] build(api): implement openapi specs generation --- backend/pom.xml | 27 ++++++++++++------- .../src/main/resources/application.properties | 11 ++++++++ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/backend/pom.xml b/backend/pom.xml index 0dc9d4c..06f6f56 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -1,6 +1,5 @@ - + 4.0.0 org.acme @@ -56,6 +55,14 @@ io.quarkus quarkus-agroal + + io.quarkus + quarkus-smallrye-openapi + + + io.quarkus + quarkus-swagger-ui + io.quarkus quarkus-junit5 @@ -78,23 +85,23 @@ test - org.awaitility - awaitility + org.awaitility + awaitility test - org.assertj - assertj-core + org.assertj + assertj-core 3.26.3 test - io.quarkus - quarkus-jdbc-postgresql + io.quarkus + quarkus-jdbc-postgresql - io.quarkus - quarkus-hibernate-orm-panache + io.quarkus + quarkus-hibernate-orm-panache io.quarkus diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index ea01c7f..5b69cb6 100644 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -32,6 +32,17 @@ quarkus.datasource.jdbc.initial-size=10 quarkus.datasource.jdbc.idle-removal-interval=5M quarkus.datasource.jdbc.max-lifetime=30M +# Swagger UI for endpoint descriptions +quarkus.swagger-ui.always-include=true +quarkus.smallrye-openapi.info-title=Timetabling for VIT +%dev.quarkus.smallrye-openapi.info-title=Timetabling for VIT (development) +%test.quarkus.smallrye-openapi.info-title=Timetabling for VIT (test) +quarkus.smallrye-openapi.info-version=1.0.1 +quarkus.smallrye-openapi.info-description=AI-powered timetabling solution for VIT +quarkus.smallrye-openapi.info-contact-email=techsupport@example.com +quarkus.smallrye-openapi.info-contact-name=JetEdge Customer Support +quarkus.smallrye-openapi.info-license-name=Apache 2.0 +quarkus.smallrye-openapi.info-license-url=https://www.apache.org/licenses/LICENSE-2.0.html # ------------------------------------------- # Debuggers From 89025a2ebe603b7445b53779631bdee6836b6e7a Mon Sep 17 00:00:00 2001 From: Eden Xu <130119691+FlyingPufferFish@users.noreply.github.com> Date: Wed, 23 Oct 2024 21:38:10 +1100 Subject: [PATCH 2/4] refactor(api): rename api endpoints for consistency --- .../java/org/acme/rest/TimetableResource.java | 37 +++++-------------- frontend/src/components/GanttChart.tsx | 2 +- frontend/src/pages/Enrolment.tsx | 2 +- frontend/src/pages/TimetableMod.tsx | 2 +- 4 files changed, 12 insertions(+), 31 deletions(-) diff --git a/backend/src/main/java/org/acme/rest/TimetableResource.java b/backend/src/main/java/org/acme/rest/TimetableResource.java index 7e86739..07ba1c5 100644 --- a/backend/src/main/java/org/acme/rest/TimetableResource.java +++ b/backend/src/main/java/org/acme/rest/TimetableResource.java @@ -82,7 +82,6 @@ public Response timetableUpdate(List updatedUnits) { * @param dbUnits List of all Unit objects in the database * @return The updated Unit, null otherwise */ - @PUT @Transactional @Consumes(MediaType.APPLICATION_JSON) public Unit unitUpdate(Unit updatedUnit, List dbUnits) { @@ -129,8 +128,6 @@ public Room findRoom(Room inputRoom) { return null; } - - @Path("/view") @GET @RolesAllowed({"user"}) @Produces(MediaType.APPLICATION_JSON) @@ -147,6 +144,7 @@ public void findByCampusAndDelete(String campusName) { } } + @Path("/example") @GET @RolesAllowed({"user"}) @Transactional @@ -175,48 +173,31 @@ public Timetable solveExample() throws ExecutionException, InterruptedException var problem = new Timetable("Adelaide", List.of( u1, u2, u3, u4 -// new Unit(5, "5", Duration.ofHours(2), List.of(c, d, e)), -// new Unit(6, "6", Duration.ofHours(2), List.of(f, g, h, i)) ), List.of( DayOfWeek.MONDAY, DayOfWeek.TUESDAY, - DayOfWeek.WEDNESDAY -// DayOfWeek.THURSDAY, -// DayOfWeek.FRIDAY + DayOfWeek.WEDNESDAY, + DayOfWeek.THURSDAY, + DayOfWeek.FRIDAY ), List.of( - LocalTime.of(15, 0) -// LocalTime.of(17, 0) -// LocalTime.of(16,0), -// LocalTime.of(23,0) + LocalTime.of(15, 0), + LocalTime.of(17, 0), + LocalTime.of(16,0), + LocalTime.of(23,0) ), List.of(r1, r2, r3) ); - /* - * During this solving phase, new Unit objects will be created with the - * allotted date and Room assignment. - * - * Currently, the 'old' Unit objects in the 'problem' variable and the - * 'new' Unit objects in the 'solution' variable are stored as different - * Units in the database due to our inability to control the behaviour - * of solverManager.solve - * - * i.e. after solving, there will be 2 copies of each Unit in the - * database, where the 'old' Unit has the list of students but no - * timetable assignment, while the 'new' Unit does not have the list - * of students enrolled, but does have the assigned date and room - */ - findByCampusAndDelete(problem.campusName); Timetable solution = solverManager.solve("job 1", problem).getFinalBestSolution(); - solution.persist(); // saves the solution timetable and all related entities to database + solution.persist(); return solution; } diff --git a/frontend/src/components/GanttChart.tsx b/frontend/src/components/GanttChart.tsx index 6364c4c..97eba5b 100644 --- a/frontend/src/components/GanttChart.tsx +++ b/frontend/src/components/GanttChart.tsx @@ -240,7 +240,7 @@ export default function GanttChart() { moddedUnits.current = []; // Second fetch request (GET) only runs after the first one completes - const viewResponse = await fetch(REMOTE_API_URL + "/timetabling/view", { + const viewResponse = await fetch(REMOTE_API_URL + "/timetabling", { headers: { Authorization: authHeader }, }); diff --git a/frontend/src/pages/Enrolment.tsx b/frontend/src/pages/Enrolment.tsx index 8bc3996..bc1df37 100644 --- a/frontend/src/pages/Enrolment.tsx +++ b/frontend/src/pages/Enrolment.tsx @@ -26,7 +26,7 @@ export default function StarterPage() { }; const { authHeader } = useAuthContext(); useEffect(() => { - fetch(REMOTE_API_URL + "/timetabling/view", { + fetch(REMOTE_API_URL + "/timetabling", { headers: { Authorization: authHeader }, }) .then((response) => { diff --git a/frontend/src/pages/TimetableMod.tsx b/frontend/src/pages/TimetableMod.tsx index 45d8544..d17b07a 100644 --- a/frontend/src/pages/TimetableMod.tsx +++ b/frontend/src/pages/TimetableMod.tsx @@ -20,7 +20,7 @@ export default function TimetableMod() { const { authHeader } = useAuthContext(); useEffect(() => { - fetch(REMOTE_API_URL + "/timetabling/view", { headers: { 'Authorization': authHeader } }) + fetch(REMOTE_API_URL + "/timetabling", { headers: { 'Authorization': authHeader } }) .then((response) => { if (!response.ok) { throw new Error("Network response was not ok"); From 34894d686c113f4a301269e17f20c674089c8650 Mon Sep 17 00:00:00 2001 From: Eden Xu <130119691+FlyingPufferFish@users.noreply.github.com> Date: Thu, 24 Oct 2024 10:48:30 +1100 Subject: [PATCH 3/4] chore(database): :fire: remove deprecated student endpoints --- .../java/org/acme/rest/StudentResource.java | 26 ------------------- 1 file changed, 26 deletions(-) delete mode 100644 backend/src/main/java/org/acme/rest/StudentResource.java diff --git a/backend/src/main/java/org/acme/rest/StudentResource.java b/backend/src/main/java/org/acme/rest/StudentResource.java deleted file mode 100644 index 7c75d27..0000000 --- a/backend/src/main/java/org/acme/rest/StudentResource.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.acme.rest; - -import jakarta.transaction.Transactional; -import jakarta.ws.rs.*; -import jakarta.ws.rs.core.MediaType; -import jakarta.ws.rs.core.Response; -import org.acme.domain.Student; - -import java.util.List; - -@Path("/students") -public class StudentResource { - @GET - @Produces(MediaType.APPLICATION_JSON) - public List list() { - return Student.listAll(); - } - - @POST - @Transactional - @Consumes(MediaType.APPLICATION_JSON) - public Response createCampus(Student student) { - student.persist(); - return Response.status(Response.Status.CREATED).entity(student).build(); - } -} From 78da9224b88c7059355580842a8906ce4cb5d852 Mon Sep 17 00:00:00 2001 From: Eden Xu <130119691+FlyingPufferFish@users.noreply.github.com> Date: Fri, 25 Oct 2024 21:36:29 +1100 Subject: [PATCH 4/4] chore: clean comments --- backend/src/main/java/org/acme/domain/Unit.java | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/src/main/java/org/acme/domain/Unit.java b/backend/src/main/java/org/acme/domain/Unit.java index eb4cef6..771e660 100644 --- a/backend/src/main/java/org/acme/domain/Unit.java +++ b/backend/src/main/java/org/acme/domain/Unit.java @@ -38,7 +38,6 @@ public class Unit extends PanacheEntity { @PlanningVariable public LocalTime startTime; - // TODO: change unit to be the owner, rather than the student being owner @Transient @JsonIgnoreProperties("units") @ManyToMany(mappedBy = "units", fetch = FetchType.LAZY, cascade = CascadeType.ALL)