diff --git a/src/main/java/com/uh/rainbow/controller/CampusController.java b/src/main/java/com/uh/rainbow/controller/CampusController.java index 767404c..ae95ea2 100644 --- a/src/main/java/com/uh/rainbow/controller/CampusController.java +++ b/src/main/java/com/uh/rainbow/controller/CampusController.java @@ -4,6 +4,7 @@ import com.uh.rainbow.dto.identifier.IdentifierDTO; import com.uh.rainbow.dto.response.*; import com.uh.rainbow.service.HTMLParserService; +import com.uh.rainbow.service.SchedulerService; import com.uh.rainbow.util.SourceURL; import com.uh.rainbow.util.filter.CourseFilter; import com.uh.rainbow.util.logging.Logger; @@ -34,6 +35,7 @@ public class CampusController { private final static Logger LOGGER = new Logger(CampusController.class); private final HTMLParserService htmlParserService = new HTMLParserService(); + private final SchedulerService schedulerService = new SchedulerService(); /** * Util logging method for reporting HTTP failures @@ -101,6 +103,32 @@ public ResponseEntity getAllTerms(@PathVariable String instID) { } } + /** + * GET Endpoint: /campuses/{instID}/terms/{termID}/subjects + * Get list of subjects for a given campus and term + * + * @param instID Inst ID to search for subjects + * @param termID Term ID to search for subjects + * @return List of subjects for a given campus and term + */ + @GetMapping(value = "/{instID}/terms/{termID}/schedule") + public ResponseEntity getSchedules(@PathVariable String instID, @PathVariable String termID, @RequestParam List courses) { + try { + // Get all subjects + return new ResponseEntity<>( + new IdentifierResponseDTO(new SourceURL(instID, termID), this.htmlParserService.parseSubjects(instID, termID)), + HttpStatus.OK + ); + } catch (HttpStatusException e) { + // Report and return html access failure + reportHTTPAccessError(MessageBuilder.Type.SUBJECT, e); + return new ResponseEntity<>(new BadAccessResponseDTO(e), HttpStatus.BAD_REQUEST); + } catch (IOException e) { + // Internal server error + LOGGER.error(new MessageBuilder(MessageBuilder.Type.SUBJECT).addDetails(e)); + return new ResponseEntity<>(new APIErrorResponseDTO(e), HttpStatus.INTERNAL_SERVER_ERROR); + } + } /** * GET Endpoint: /campuses/{instID}/terms/{termID}/subjects diff --git a/src/main/java/com/uh/rainbow/controller/SchedulerController.java b/src/main/java/com/uh/rainbow/controller/SchedulerController.java new file mode 100644 index 0000000..f1e377e --- /dev/null +++ b/src/main/java/com/uh/rainbow/controller/SchedulerController.java @@ -0,0 +1,52 @@ +package com.uh.rainbow.controller; + +import com.uh.rainbow.dto.request.ScheduleTemplate; +import com.uh.rainbow.dto.response.ResponseDTO; +import com.uh.rainbow.service.HTMLParserService; +import com.uh.rainbow.service.SchedulerService; +import com.uh.rainbow.util.filter.CourseFilter; +import com.uh.rainbow.util.logging.Logger; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * File: SchedulerController + *

+ * Description: + * + * @author Derek Garcia + */ +@RequestMapping("/v1/scheduler") +@RestController(value = "SchedulerController") +public class SchedulerController { + + private final static Logger LOGGER = new Logger(SchedulerController.class); + private final HTMLParserService htmlParserService = new HTMLParserService(); + private final SchedulerService schedulerService = new SchedulerService(); + + /** + * GET Endpoint: /scheduler + * Get list of University of Hawaii Campuses + * + * @return List of University of Hawaii Campuses and their ID's + */ + @GetMapping(value = "") + public ResponseEntity getSchedules( @PathVariable String instID, + @PathVariable String termID, + @PathVariable String subjectID, + @RequestParam(required = false) List crn, + @RequestParam(required = false) List code, + @RequestParam(required = false) String start_after, + @RequestParam(required = false) String end_before, + @RequestParam(required = false) String online, + @RequestParam(required = false) String sync, + @RequestParam(required = false) List day, + @RequestParam(required = false) List instructor, + @RequestParam(required = false) List keyword) { +// var cf = new CourseFilter.Builder() +// var foo = this.htmlParserService.parseCourses() + return null; + } +} diff --git a/src/main/java/com/uh/rainbow/dto/request/BufferDTO.java b/src/main/java/com/uh/rainbow/dto/request/BufferDTO.java new file mode 100644 index 0000000..17be79c --- /dev/null +++ b/src/main/java/com/uh/rainbow/dto/request/BufferDTO.java @@ -0,0 +1,11 @@ +package com.uh.rainbow.dto.request; + +/** + * File: BufferDTO.java + *

+ * Description: + * + * @author Derek Garcia + */ +public record BufferDTO() { +} diff --git a/src/main/java/com/uh/rainbow/dto/request/RulesDTO.java b/src/main/java/com/uh/rainbow/dto/request/RulesDTO.java new file mode 100644 index 0000000..a9fa7e2 --- /dev/null +++ b/src/main/java/com/uh/rainbow/dto/request/RulesDTO.java @@ -0,0 +1,11 @@ +package com.uh.rainbow.dto.request; + +/** + * File: RulesDTO.java + *

+ * Description: + * + * @author Derek Garcia + */ +public record RulesDTO() { +} diff --git a/src/main/java/com/uh/rainbow/dto/request/ScheduleTemplate.java b/src/main/java/com/uh/rainbow/dto/request/ScheduleTemplate.java new file mode 100644 index 0000000..a38f009 --- /dev/null +++ b/src/main/java/com/uh/rainbow/dto/request/ScheduleTemplate.java @@ -0,0 +1,13 @@ +package com.uh.rainbow.dto.request; + +import java.util.List; + +/** + * File: ScheduleTemplate.java + *

+ * Description: + * + * @author Derek Garcia + */ +public record ScheduleTemplate(String instID, String termID, List courses) { +} diff --git a/src/main/java/com/uh/rainbow/dto/response/ScheduleResponseDTO.java b/src/main/java/com/uh/rainbow/dto/response/ScheduleResponseDTO.java new file mode 100644 index 0000000..4af3de5 --- /dev/null +++ b/src/main/java/com/uh/rainbow/dto/response/ScheduleResponseDTO.java @@ -0,0 +1,24 @@ +package com.uh.rainbow.dto.response; + +import com.uh.rainbow.dto.schedule.ScheduleDTO; + +import java.util.List; + +/** + * File: ScheduleResponseDTO.java + *

+ * Description: + * + * @author Derek Garcia + */ +public class ScheduleResponseDTO extends ResponseDTO { + public final List schedules; + + /** + * Create new Schedule response with list of valid schedules + * + */ + public ScheduleResponseDTO(List schedules) { + this.schedules = schedules; + } +} diff --git a/src/main/java/com/uh/rainbow/dto/schedule/ScheduleDTO.java b/src/main/java/com/uh/rainbow/dto/schedule/ScheduleDTO.java new file mode 100644 index 0000000..de5c6a6 --- /dev/null +++ b/src/main/java/com/uh/rainbow/dto/schedule/ScheduleDTO.java @@ -0,0 +1,21 @@ +package com.uh.rainbow.dto.schedule; + +import java.util.List; + +/** + * File: ScheduleDTO.java + *

+ * Description: + * + * @author Derek Garcia + */ +public record ScheduleDTO( + List tba, + List sunday, + List monday, + List tuesday, + List wednesday, + List thursday, + List friday, + List saturday) { +} diff --git a/src/main/java/com/uh/rainbow/dto/schedule/ScheduleMeetingDTO.java b/src/main/java/com/uh/rainbow/dto/schedule/ScheduleMeetingDTO.java new file mode 100644 index 0000000..7960343 --- /dev/null +++ b/src/main/java/com/uh/rainbow/dto/schedule/ScheduleMeetingDTO.java @@ -0,0 +1,11 @@ +package com.uh.rainbow.dto.schedule; + +/** + * File: ScheduleMeetingDTO.java + *

+ * Description: + * + * @author Derek Garcia + */ +public record ScheduleMeetingDTO() { +} diff --git a/src/main/java/com/uh/rainbow/entities/PotentialSchedule.java b/src/main/java/com/uh/rainbow/entities/PotentialSchedule.java index 3d0dddb..9f11723 100644 --- a/src/main/java/com/uh/rainbow/entities/PotentialSchedule.java +++ b/src/main/java/com/uh/rainbow/entities/PotentialSchedule.java @@ -1,5 +1,7 @@ package com.uh.rainbow.entities; +import com.uh.rainbow.dto.schedule.ScheduleDTO; + import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -48,6 +50,13 @@ private PotentialSchedule(PotentialSchedule other, Section next) { this.remainingSections.removeIf((s) -> s.getCourse().equals(next.getCourse())); } + + public ScheduleDTO toScheduleDTO(){ + for(Section section : this.sections){ + section. + } + } + /** * Test to see if this schedule is complete * diff --git a/src/main/java/com/uh/rainbow/service/SchedulerService.java b/src/main/java/com/uh/rainbow/service/SchedulerService.java index 1a12a5b..45f82e4 100644 --- a/src/main/java/com/uh/rainbow/service/SchedulerService.java +++ b/src/main/java/com/uh/rainbow/service/SchedulerService.java @@ -1,6 +1,7 @@ package com.uh.rainbow.service; import com.uh.rainbow.dto.course.CourseDTO; +import com.uh.rainbow.dto.schedule.ScheduleDTO; import com.uh.rainbow.entities.Course; import com.uh.rainbow.entities.PotentialSchedule; import com.uh.rainbow.entities.Section; @@ -21,25 +22,6 @@ @Service public class SchedulerService { - /** - * Generate list of valid schedules - * - * @param courses List of courses to include in the schedule - * @return List of valid schedules - */ - public List schedule(List courses) { - // Convert course DTO back into courses - List cor = new ArrayList<>(); - courses.forEach((c) -> cor.add(new Course(c.cid(), c.name(), c.credits()))); - - // Convert section DTO back into sections - List

sections = new ArrayList<>(); - courses.forEach((c) -> sections.addAll(c.toSections())); // todo add buffers - - // Generate all possible schedules - return new Scheduler(cor).solve(new PotentialSchedule(sections)); - } - /** * Scheduler that generates valid schedules */ @@ -76,4 +58,23 @@ public List solve(PotentialSchedule potentialSchedule) { } + /** + * Generate list of valid schedules + * + * @param courses List of courses to include in the schedule + * @return List of valid schedules + */ + public List schedule(List courses) { + // Convert course DTO back into courses + List cor = new ArrayList<>(); + courses.forEach((c) -> cor.add(new Course(c.cid(), c.name(), c.credits()))); + + // Convert section DTO back into sections + List
sections = new ArrayList<>(); + courses.forEach((c) -> sections.addAll(c.toSections())); // todo add buffers + + // Generate all possible schedules + return new Scheduler(cor).solve(new PotentialSchedule(sections)); + } + }