Skip to content

Commit

Permalink
Merge pull request #55 from hotungkhanh/kan-93/endpoints
Browse files Browse the repository at this point in the history
KAN-93 chore: clean endpoints, enable openapi export
  • Loading branch information
FlyingPufferFish authored Oct 26, 2024
2 parents 490aa7c + 78da922 commit 135b93c
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 68 deletions.
27 changes: 17 additions & 10 deletions backend/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.acme</groupId>
Expand Down Expand Up @@ -56,6 +55,14 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-agroal</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-openapi</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-swagger-ui</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
Expand All @@ -78,23 +85,23 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.26.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql</artifactId>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm-panache</artifactId>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm-panache</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
Expand Down
1 change: 0 additions & 1 deletion backend/src/main/java/org/acme/domain/Unit.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 0 additions & 26 deletions backend/src/main/java/org/acme/rest/StudentResource.java

This file was deleted.

37 changes: 9 additions & 28 deletions backend/src/main/java/org/acme/rest/TimetableResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public Response timetableUpdate(List<Unit> 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<Unit> dbUnits) {
Expand Down Expand Up @@ -129,8 +128,6 @@ public Room findRoom(Room inputRoom) {
return null;
}


@Path("/view")
@GET
@RolesAllowed({"user"})
@Produces(MediaType.APPLICATION_JSON)
Expand All @@ -147,6 +144,7 @@ public void findByCampusAndDelete(String campusName) {
}
}

@Path("/example")
@GET
@RolesAllowed({"user"})
@Transactional
Expand Down Expand Up @@ -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;
}
Expand Down
11 changes: 11 additions & 0 deletions backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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=[email protected]
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
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/GanttChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
});

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/Enrolment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/TimetableMod.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 135b93c

Please sign in to comment.