diff --git a/SCRS-Backend/build.gradle b/SCRS-Backend/build.gradle index cfcc5e8..f4b429a 100644 --- a/SCRS-Backend/build.gradle +++ b/SCRS-Backend/build.gradle @@ -24,3 +24,28 @@ dependencies { test { useJUnitPlatform() } + +task integrationTests(type: Exec) { + + dependsOn 'build' + + group = "verification" + + workingDir './src/test/javascript' + + if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) + { + // for windows + commandLine 'cmd', '/c', 'node runTests.js' + } + else + { + commandLine 'node runTests.js' + } + + standardOutput = new ByteArrayOutputStream(); + + ext.output = { + return standardOutput.toString(); + } +} \ No newline at end of file diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/ScrsApplication.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/ScrsApplication.java index b97bcde..9cf4a68 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/ScrsApplication.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/ScrsApplication.java @@ -4,8 +4,8 @@ import ca.mcgill.ecse321.scrs.dao.AssistantRepository; import ca.mcgill.ecse321.scrs.model.Assistant; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.RestController; @@ -21,11 +21,6 @@ public class ScrsApplication @Autowired AssistantRepository assistantRepository; - @PostConstruct - public void init() { - staticAssistantRepository = assistantRepository; - } - public static void main(String[] args) { SpringApplication.run(ScrsApplication.class, args); @@ -39,4 +34,10 @@ public static void main(String[] args) } } + @PostConstruct + public void init() + { + staticAssistantRepository = assistantRepository; + } + } \ No newline at end of file diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/AppointmentController.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/AppointmentController.java index 1092a2b..94e3787 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/AppointmentController.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/AppointmentController.java @@ -15,12 +15,13 @@ import org.springframework.web.bind.annotation.*; import java.sql.Date; +import java.sql.Time; import java.time.LocalDate; import java.util.ArrayList; import java.util.Calendar; import java.util.List; -import static ca.mcgill.ecse321.scrs.controller.Helper.*; +import static ca.mcgill.ecse321.scrs.controller.Helper.convertToDto; @RestController @RequestMapping(path = "/api/appointment", produces = MediaType.APPLICATION_JSON_VALUE) @@ -36,29 +37,52 @@ public class AppointmentController @GetMapping(path = {"/getall/{id}", "/getall/{id}/"}) - public ResponseEntity> getAllAppointments(@PathVariable String id) { - if(id == null)return new ResponseEntity<>(null, HttpStatus.NOT_ACCEPTABLE); + @CrossOrigin(origins = "*") + public ResponseEntity> getAllAppointments(@PathVariable String id) + { + if (id == null) return new ResponseEntity<>(null, HttpStatus.NOT_ACCEPTABLE); int ID = Integer.parseInt(id); Customer customer = customerService.getCustomerByID(ID); - if(customer == null) return new ResponseEntity<>(null, HttpStatus.NOT_ACCEPTABLE); + if (customer == null) return new ResponseEntity<>(null, HttpStatus.NOT_ACCEPTABLE); List list = appointmentService.getAppointmentsByCustomer(customer); List dtoList = new ArrayList<>(); - if(list != null){ + if (list != null) + { + for (Appointment appointment : list) + { + dtoList.add(convertToDto(appointment)); + } + } + return new ResponseEntity<>(dtoList, HttpStatus.OK); + + } + + @GetMapping(path = {"/getallappointments", "/getallappointments/"}) + @CrossOrigin(origins = "*") + public ResponseEntity> getAllAppointments() + { + List list = appointmentService.getAllAppointments(); + List dtoList = new ArrayList<>(); + + if (list != null) + { for (Appointment appointment : list) { dtoList.add(convertToDto(appointment)); } } return new ResponseEntity<>(dtoList, HttpStatus.OK); + } @GetMapping(path = {"/getById/{id}", "/getById/{id}/"}) + @CrossOrigin(origins = "*") public ResponseEntity getAppointmentById(@PathVariable String id) { - if(id == null) return new ResponseEntity<>(null, HttpStatus.NOT_ACCEPTABLE); + if (id == null) return new ResponseEntity<>(null, HttpStatus.NOT_ACCEPTABLE); Appointment appointment = appointmentService.getAppointmentById(Integer.parseInt(id)); @@ -71,16 +95,19 @@ public ResponseEntity getAppointmentById(@PathVariable String id } @GetMapping(path = {"/notifications/{id}", "/notifications/{id}/"}) - public ResponseEntity> notifications(@PathVariable String id) { - if(id == null)return new ResponseEntity<>(null, HttpStatus.NOT_ACCEPTABLE); + @CrossOrigin(origins = "*") + public ResponseEntity> notifications(@PathVariable String id) + { + if (id == null) return new ResponseEntity<>(null, HttpStatus.NOT_ACCEPTABLE); int ID = Integer.parseInt(id); Customer customer = customerService.getCustomerByID(ID); - if(customer == null) return new ResponseEntity<>(null, HttpStatus.NOT_ACCEPTABLE); + if (customer == null) return new ResponseEntity<>(null, HttpStatus.NOT_ACCEPTABLE); List list = appointmentService.getAppointmentsByCustomer(customer); - if(list != null){ + if (list != null) + { //finding the same date next week Date now = new Date(LocalDate.now().toEpochDay()); Calendar calendar = Calendar.getInstance(); @@ -108,17 +135,19 @@ public ResponseEntity> notifications(@PathVariable String i } return new ResponseEntity<>(notificationList, HttpStatus.OK); - }else return new ResponseEntity<>(null, HttpStatus.OK); + } else return new ResponseEntity<>(null, HttpStatus.OK); } @PostMapping(value = {"/book", "/book/"}) + @CrossOrigin(origins = "*") public ResponseEntity bookAppointment(@RequestBody AppointmentDto appointmentDto) { if (appointmentDto == null) { return new ResponseEntity<>(null, HttpStatus.EXPECTATION_FAILED); } - try { + try + { List timeslots = timeslotService.getTimeslotsById(appointmentDto.getTimeslotsId()); if (timeslots == null) { @@ -129,29 +158,34 @@ public ResponseEntity bookAppointment(@RequestBody AppointmentDt appointmentDto.getService(), appointmentDto.getNote(), appointmentDto.getPaymentStatus(), customer, timeslots.toArray(new Timeslot[0])); return new ResponseEntity<>(convertToDto(appointment), HttpStatus.OK); - } catch (Exception e) { + } catch (Exception e) + { return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR); } } @PutMapping(value = {"/pay", "/pay/"}) + @CrossOrigin(origins = "*") public ResponseEntity payAppointment(@RequestParam(name = "appointmentId") int appointmentId) { try { Appointment appointment = appointmentService.getAppointmentById(appointmentId); - if (appointment == null) { + if (appointment == null) + { return new ResponseEntity<>(null, HttpStatus.EXPECTATION_FAILED); } appointment.setPaid(true); appointment = appointmentService.modifyAppointment(convertToDto(appointment)); return new ResponseEntity<>(convertToDto(appointment), HttpStatus.OK); - } catch (Exception e) { - return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR); + } catch (Exception e) + { + return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR); } } @PutMapping(value = {"/rate", "/rate/"}) + @CrossOrigin(origins = "*") public ResponseEntity rateAppointment(@RequestParam(name = "appointmentId") int appointmentId, @RequestParam(name = "rating") int rating) { if (rating > 10 || rating < 0) @@ -159,7 +193,8 @@ public ResponseEntity rateAppointment(@RequestParam(name = "appo return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR); } - try { + try + { Appointment appointment = appointmentService.rateAppointment(appointmentId, rating); return new ResponseEntity<>(convertToDto(appointment), HttpStatus.OK); } catch (Exception e) @@ -169,13 +204,15 @@ public ResponseEntity rateAppointment(@RequestParam(name = "appo } @PutMapping(value = {"/modifyAppointment", "/modifyAppointment/"}) + @CrossOrigin(origins = "*") public ResponseEntity modifyAppointment(@RequestBody AppointmentDto appointmentDto) { if (appointmentDto == null) { return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR); } - try { + try + { Appointment modifiedAppt = appointmentService.modifyAppointment(appointmentDto); return new ResponseEntity<>(convertToDto(modifiedAppt), HttpStatus.OK); } catch (Exception e) @@ -183,4 +220,60 @@ public ResponseEntity modifyAppointment(@RequestBody Appointment return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR); } } + + @GetMapping(value = {"/getStartAndEnd/{id}", "/getStartAndEnd/{id}/"}) + @CrossOrigin(origins = "*") + public ResponseEntity getAppointmentStartAndEnd(@PathVariable("id") int appointmentId) + { + try + { + Appointment appointment = appointmentService.getAppointmentById(appointmentId); + + if (appointment == null) + { + return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR); + } + ArrayList timeslots = new ArrayList<>(appointmentService.getAppointmentById(appointmentId).getTimeslots()); + + if (timeslots.size() == 0) + { + return new ResponseEntity(null, HttpStatus.INTERNAL_SERVER_ERROR); + } + + Date minD = timeslots.get(0).getStartDate(); + Date maxD = timeslots.get(0).getEndDate(); + + Time minT = timeslots.get(0).getStartTime(); + Time maxT = timeslots.get(0).getEndTime(); + + for (Timeslot t : timeslots) + { + if (t.getEndDate().after(maxD)) + { + maxD = t.getEndDate(); + maxT = t.getEndTime(); + + } else if (t.getEndDate().equals(maxD)) + { + if (t.getEndTime().after(maxT)) maxT = t.getEndTime(); + } else if (t.getStartDate().before(minD)) + { + minD = t.getStartDate(); + minT = t.getStartTime(); + } else if (t.getStartDate().equals(minD)) + { + if (t.getStartTime().before(minT)) minT = t.getStartTime(); + } + } + TimeslotDto output = new TimeslotDto(-1, minD, maxD, minT, maxT, -1); + + return new ResponseEntity<>(output, HttpStatus.OK); + + } catch (Exception e) + { + return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR); + } + + } + } diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/AssistantController.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/AssistantController.java index 7227c40..9c9c8b5 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/AssistantController.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/AssistantController.java @@ -9,7 +9,8 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import static ca.mcgill.ecse321.scrs.controller.Helper.*; +import static ca.mcgill.ecse321.scrs.controller.Helper.convertToDto; +import static ca.mcgill.ecse321.scrs.controller.Helper.hash; @RestController @RequestMapping(path = "/api/assistant") @@ -40,26 +41,13 @@ public ResponseEntity createAssistant(@RequestBody Assistant assis @PutMapping(value = {"/update", "/update/"}) @CrossOrigin(origins = "*") - public ResponseEntity updateAssistant(@RequestBody Assistant assistant, @CookieValue(value = "id", defaultValue = "-1") String ID) + public ResponseEntity updateAssistant(@RequestBody Assistant assistant) { - int id = Integer.parseInt(ID); - if (id == -1) - { - // TODO handle no login error with cookies (uncomment next line) - //return new ResponseEntity(new AssistantDto(), HttpStatus.UNAUTHORIZED); - // Please login to modify an assistant account. - } if (assistant == null) { return new ResponseEntity(new AssistantDto(), HttpStatus.EXPECTATION_FAILED); // Invalid assistant } - if (!isAdmin(scrsUserService.getSCRSUserByID(id))) //does not have permission to edit. - { - // TODO handle bad login error with cookies (uncomment next line) - //return new ResponseEntity(new AssistantDto(), HttpStatus.UNAUTHORIZED); - // You do not have permission to edit an admin account. - } if (assistantService.getAssistantByID(assistant.getScrsUserId()) == null) { return new ResponseEntity(new AssistantDto(), HttpStatus.NOT_ACCEPTABLE); @@ -76,28 +64,15 @@ public ResponseEntity updateAssistant(@RequestBody Assistant assis @DeleteMapping(value = {"/delete/{id}", "/delete/{id}/"}) @CrossOrigin(origins = "*") - public ResponseEntity deleteAssistant(@PathVariable String id, @CookieValue(value = "id", defaultValue = "-1") String ID) + public ResponseEntity deleteAssistant(@PathVariable String id) { int assistantID = Integer.parseInt(id); - int idCookie = Integer.parseInt(ID); - if (idCookie == -1) - { - // TODO handle no login error with cookies (uncomment next line) - //return new ResponseEntity(new AssistantDto(), HttpStatus.UNAUTHORIZED); - //Please login to delete an assistant account. - } Assistant assistant = assistantService.getAssistantByID(assistantID); if (assistant == null) { return new ResponseEntity(new AssistantDto(), HttpStatus.NOT_ACCEPTABLE); // Invalid assistant. Please submit a valid assistant account to be deleted. } - if (!isAdmin(scrsUserService.getSCRSUserByID(idCookie))) //does not have permission to edit. - { - // TODO handle bad login error with cookies (uncomment next line) - //return new ResponseEntity(new AssistantDto(), HttpStatus.UNAUTHORIZED); - // You do not have permission to edit this account. - } return new ResponseEntity<>(convertToDto(assistantService.deleteAssistant(assistant)), HttpStatus.OK); } diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/CookieController.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/CookieController.java deleted file mode 100644 index 074fd52..0000000 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/CookieController.java +++ /dev/null @@ -1,15 +0,0 @@ -package ca.mcgill.ecse321.scrs.controller; - -import org.springframework.http.MediaType; -import org.springframework.web.bind.annotation.*; - -@RestController -@RequestMapping(path = "/", produces = MediaType.APPLICATION_JSON_VALUE) -public class CookieController -{ - @GetMapping("/") - @CrossOrigin(origins = "*") - public String readCookie(@CookieValue(value = "id", defaultValue = "-1") String id){ - return id; - } -} diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/CustomerController.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/CustomerController.java index 648163d..d21a9f6 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/CustomerController.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/CustomerController.java @@ -10,7 +10,8 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import static ca.mcgill.ecse321.scrs.controller.Helper.*; +import static ca.mcgill.ecse321.scrs.controller.Helper.convertToDto; +import static ca.mcgill.ecse321.scrs.controller.Helper.hash; @RestController @RequestMapping(path = "/api/customer", produces = MediaType.APPLICATION_JSON_VALUE) @@ -41,26 +42,13 @@ public ResponseEntity createCustomer(@RequestBody Customer customer @PutMapping(value = {"/update", "/update/"}) @CrossOrigin(origins = "*") - public ResponseEntity updateCustomer(@RequestBody Customer customer, @CookieValue(value = "id", defaultValue = "-1") String ID) + public ResponseEntity updateCustomer(@RequestBody Customer customer) { - int id = Integer.parseInt(ID); - if (id == -1) - { - // TODO handle no login error with cookies (uncomment next line) - //return new ResponseEntity(new CustomerDto(), HttpStatus.UNAUTHORIZED); - // Please login to modify a customer account. - } if (customer == null) { return new ResponseEntity(new CustomerDto(), HttpStatus.EXPECTATION_FAILED); // Invalid customer. } - if (!isAdmin(scrsUserService.getSCRSUserByID(id)) && id != customer.getScrsUserId()) //does not have permission to edit. - { - // TODO handle bad login error with cookies (uncomment next line) - //return new ResponseEntity(new CustomerDto(), HttpStatus.UNAUTHORIZED); - // You cannot modify a customer account other than your own. - } if (customerService.getCustomerByID(customer.getScrsUserId()) == null) { return new ResponseEntity(new CustomerDto(), HttpStatus.NOT_ACCEPTABLE); @@ -77,28 +65,15 @@ public ResponseEntity updateCustomer(@RequestBody Customer customer @DeleteMapping(value = {"/delete/{id}", "/delete/{id}/"}) @CrossOrigin(origins = "*") - public ResponseEntity deleteCustomer(@PathVariable String id, @CookieValue(value = "id", defaultValue = "-1") String ID) + public ResponseEntity deleteCustomer(@PathVariable String id) { int customerID = Integer.parseInt(id); - int idCookie = Integer.parseInt(ID); - if (idCookie == -1) - { - // TODO handle no login error with cookies (uncomment next line) - //return new ResponseEntity(new CustomerDto(), HttpStatus.UNAUTHORIZED); - // Please login to delete a customer account. - } Customer customer = customerService.getCustomerByID(customerID); if (customer == null) { return new ResponseEntity(new CustomerDto(), HttpStatus.NOT_ACCEPTABLE); // Invalid customer. Please submit a valid customer account to be deleted. } - if (!isAdmin(scrsUserService.getSCRSUserByID(idCookie)) && idCookie != customerID) //does not have permission to edit. - { - // TODO handle bad login error with cookies (uncomment next line) - //return new ResponseEntity(new CustomerDto(), HttpStatus.UNAUTHORIZED); - // You cannot delete a customer account other than your own. - } return new ResponseEntity<>(convertToDto(customerService.deleteCustomer(customer)), HttpStatus.OK); } diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/DatabaseController.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/DatabaseController.java index 7f27265..9285e0c 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/DatabaseController.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/DatabaseController.java @@ -43,7 +43,8 @@ public void clearDatabase() } @DeleteMapping("/wipe") - public ResponseEntity loginCustomer() { + public ResponseEntity loginCustomer() + { clearDatabase(); return new ResponseEntity<>(true, HttpStatus.OK); } diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/Helper.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/Helper.java index 656240a..48acb70 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/Helper.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/Helper.java @@ -108,7 +108,7 @@ public static List convertToDtoList(List technicians) throw new IllegalArgumentException("There is no such technician list!"); } ArrayList technicianDtos = new ArrayList<>(); - for (Technician t: technicians) + for (Technician t : technicians) { technicianDtos.add(convertToDto(t)); } @@ -133,7 +133,7 @@ public static List convertToDto(List timeslots) throw new IllegalArgumentException("There is no such timeslot list!"); } ArrayList timeslotsDto = new ArrayList<>(); - for (Timeslot timeslot: timeslots) + for (Timeslot timeslot : timeslots) { timeslotsDto.add(convertToDto(timeslot)); } @@ -158,7 +158,7 @@ public static List convertListToDto(List workspaces) throw new IllegalArgumentException("There is no such workspace list!"); } ArrayList workspaceDtos = new ArrayList<>(); - for (Workspace w: workspaces) + for (Workspace w : workspaces) { workspaceDtos.add(convertToDto(w)); } diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/LoginController.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/LoginController.java index 2e67b66..be87b97 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/LoginController.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/LoginController.java @@ -14,9 +14,6 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletResponse; - @RestController @RequestMapping(path = "/api/login", produces = MediaType.APPLICATION_JSON_VALUE) public class LoginController @@ -33,7 +30,7 @@ public class LoginController @PostMapping(value = {"/customer", "/customer/"}) @CrossOrigin(origins = "*") - public ResponseEntity loginCustomer(@RequestParam("email") String email, @RequestParam("password") String password, HttpServletResponse response) + public ResponseEntity loginCustomer(@RequestParam("email") String email, @RequestParam("password") String password) { String hashedPassword = Helper.hash(password); @@ -45,16 +42,13 @@ public ResponseEntity loginCustomer(@RequestParam("email") String email return new ResponseEntity<>(-1, HttpStatus.OK); } - String id = ((Integer) customer.getScrsUserId()).toString(); - Cookie cookie = new Cookie("id", id); - response.addCookie(cookie); return new ResponseEntity<>(customer.getScrsUserId(), HttpStatus.OK); } @PostMapping(value = {"/assistant", "/assistant/"}) @CrossOrigin(origins = "*") - public ResponseEntity loginAssistant(@RequestParam("email") String email, @RequestParam("password") String password, HttpServletResponse response) + public ResponseEntity loginAssistant(@RequestParam("email") String email, @RequestParam("password") String password) { String hashedPassword = Helper.hash(password); @@ -66,44 +60,29 @@ public ResponseEntity loginAssistant(@RequestParam("email") String emai return new ResponseEntity<>(-1, HttpStatus.OK); } - String id = ((Integer) assistant.getScrsUserId()).toString(); - Cookie cookie = new Cookie("id", id); - response.addCookie(cookie); - return new ResponseEntity<>(assistant.getScrsUserId(), HttpStatus.OK); } @PostMapping(value = {"/technician", "/technician/"}) @CrossOrigin(origins = "*") - public ResponseEntity loginTechnician(@RequestParam("email") String email, @RequestParam("password") String password, HttpServletResponse response) + public ResponseEntity loginTechnician(@RequestParam("email") String email, @RequestParam("password") String password) { String hashedPassword = Helper.hash(password); - Technician technician = technicianService.getTechnicianByEmail(email); - - if (technician == null || !technician.getPassword().equals(hashedPassword)) - { - return new ResponseEntity<>(-1, HttpStatus.OK); - } + try { + Technician technician = technicianService.getTechnicianByEmail(email); - String id = ((Integer) technician.getScrsUserId()).toString(); - Cookie cookie = new Cookie("id", id); - response.addCookie(cookie); - - return new ResponseEntity<>(technician.getScrsUserId(), HttpStatus.OK); - } - - @GetMapping(value = {"/logout", "/logout/"}) - @CrossOrigin(origins = "*") - public ResponseEntity logout(HttpServletResponse response) - { + if (technician == null || !technician.getPassword().equals(hashedPassword)) + { + return new ResponseEntity<>(-1, HttpStatus.OK); + } - Cookie cookie = new Cookie("id", null); - cookie.setMaxAge(0); - response.addCookie(cookie); + return new ResponseEntity<>(technician.getScrsUserId(), HttpStatus.OK); + } catch (Exception ignored) + {} - return new ResponseEntity<>(true, HttpStatus.OK); + return new ResponseEntity<>(-1, HttpStatus.INTERNAL_SERVER_ERROR); } @GetMapping(value = {"/type/{id}", "/type/{id}/"}) @@ -134,6 +113,7 @@ public ResponseEntity getTypeByEmail(@PathVariable String email) /** * Helper for the 2 methods above. Allows to parse a user to its correct type and return the right response. + * * @param user SCRSUser object. * @return The appropriate response (String for the user type and status) */ diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/TechnicianController.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/TechnicianController.java index 4fbc73a..d515b25 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/TechnicianController.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/TechnicianController.java @@ -31,26 +31,13 @@ public class TechnicianController @PostMapping(value = {"/create", "/create/"}) @CrossOrigin(origins = "*") - public ResponseEntity createTechnician(@RequestBody Technician technician, @CookieValue(value = "id", defaultValue = "-1") String ID) + public ResponseEntity createTechnician(@RequestBody Technician technician) { - int id = Integer.parseInt(ID); - if (id == -1) - { - // TODO handle no login error with cookies (uncomment next line) - //return new ResponseEntity(new TechnicianDto(), HttpStatus.UNAUTHORIZED); - // Please login to create a technician account. - } if (technician == null) { return new ResponseEntity(new TechnicianDto(), HttpStatus.EXPECTATION_FAILED); // Invalid technician. Please submit a valid technician account to be created. } - if (!isAdmin(scrsUserService.getSCRSUserByID(id))) //does not have permission to edit. - { - // TODO handle bad login error with cookies (uncomment next line) - //return new ResponseEntity(new TechnicianDto(), HttpStatus.UNAUTHORIZED); - // You do not have permission to create a technician account. - } if (scrsUserService.getSCRSUserByEmail(technician.getEmail()) != null) { return new ResponseEntity(new TechnicianDto(), HttpStatus.ALREADY_REPORTED); @@ -62,26 +49,13 @@ public ResponseEntity createTechnician(@RequestBody Technician te @PutMapping(value = {"/update", "/update/"}) @CrossOrigin(origins = "*") - public ResponseEntity updateAssistant(@RequestBody Technician technician, @CookieValue(value = "id", defaultValue = "-1") String ID) + public ResponseEntity updateAssistant(@RequestBody Technician technician) { - int id = Integer.parseInt(ID); - if (id == -1) - { - // TODO handle no login error with cookies (uncomment next line) - //return new ResponseEntity(new TechnicianDto(), HttpStatus.UNAUTHORIZED); - // Please login to modify a technician account. - } if (technician == null) { return new ResponseEntity(new TechnicianDto(), HttpStatus.EXPECTATION_FAILED); // Invalid technician. } - if (!isAdmin(scrsUserService.getSCRSUserByID(id)) && id != technician.getScrsUserId()) //does not have permission to edit. - { - // TODO handle bad login error with cookies (uncomment next line) - //return new ResponseEntity(new TechnicianDto(), HttpStatus.UNAUTHORIZED); - // You do not have permission to create a technician account. - } if (technicianService.getTechnicianByID(technician.getScrsUserId()) == null) { return new ResponseEntity(new TechnicianDto(), HttpStatus.NOT_ACCEPTABLE); @@ -98,34 +72,21 @@ public ResponseEntity updateAssistant(@RequestBody Technician tec @DeleteMapping(value = {"/delete/{id}", "/delete/{id}/"}) @CrossOrigin(origins = "*") - public ResponseEntity deleteTechnician(@PathVariable String id, @CookieValue(value = "id", defaultValue = "-1") String ID) + public ResponseEntity deleteTechnician(@PathVariable String id) { int technicianID = Integer.parseInt(id); - int idCookie = Integer.parseInt(ID); - if (idCookie == -1) - { - // TODO handle no login error with cookies (uncomment next line) - //return new ResponseEntity(new TechnicianDto(), HttpStatus.UNAUTHORIZED); - // Please login to delete a technician account. - } Technician technician = technicianService.getTechnicianByID(technicianID); if (technician == null) { return new ResponseEntity(new TechnicianDto(), HttpStatus.NOT_ACCEPTABLE); // Invalid technician. Please submit a valid technician account to be deleted. } - if (!isAdmin(scrsUserService.getSCRSUserByID(idCookie)) && idCookie != technicianID) //does not have permission to edit. - { - // TODO handle bad login error with cookies (uncomment next line) - //return new ResponseEntity(new TechnicianDto(), HttpStatus.UNAUTHORIZED); - // You cannot delete a technician account other than your own. - } return new ResponseEntity<>(convertToDto(technicianService.deleteTechnician(technician)), HttpStatus.OK); } @GetMapping(path = {"/viewschedule/{id}/{startDate}/{endDate}"}) @CrossOrigin(origins = "*") - public ResponseEntity> getAllByDate(@PathVariable("id") int technicianId, @PathVariable("startDate") String startDate, @PathVariable("endDate") String endDate)//, @CookieValue(value = "id", defaultValue = "-1") String ID) + public ResponseEntity> getAllByDate(@PathVariable("id") int technicianId, @PathVariable("startDate") String startDate, @PathVariable("endDate") String endDate) { Date newStartDate = Date.valueOf(startDate); Date newEndDate = Date.valueOf(endDate); diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/TimeslotController.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/TimeslotController.java index 0fe428b..0096501 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/TimeslotController.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/TimeslotController.java @@ -16,7 +16,7 @@ import java.sql.Date; import java.util.List; -import static ca.mcgill.ecse321.scrs.controller.Helper.*; +import static ca.mcgill.ecse321.scrs.controller.Helper.convertToDto; @RestController @RequestMapping(path = "/api/timeslot") @@ -40,6 +40,26 @@ public ResponseEntity> getTimeslots() return new ResponseEntity<>(convertToDto(timeslots), HttpStatus.OK); } + @GetMapping(value = {"/getTimeslot/{id}", "/getTimeslot/{id}/"}) + @CrossOrigin(origins = "*") + public ResponseEntity getAllAvailableTimeslotsById(@PathVariable("id") int timeslotId) + { + try + { + Timeslot timeslot = timeslotService.getTimeslotById(timeslotId); + if (timeslot == null) + { + return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR); + } + return new ResponseEntity<>(convertToDto(timeslotService.getTimeslotById(timeslotId)), HttpStatus.OK); + } catch (Exception e) + { + return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR); + } + + } + + @GetMapping(value = {"/available/{startDate}", "/available/{startDate}/"}) @CrossOrigin(origins = "*") public ResponseEntity> getAvailableTimeslot(@PathVariable("startDate") String startDate) diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/WorkspaceController.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/WorkspaceController.java index 1e05a29..f796b02 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/WorkspaceController.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/controller/WorkspaceController.java @@ -14,7 +14,8 @@ import java.util.ArrayList; import java.util.List; -import static ca.mcgill.ecse321.scrs.controller.Helper.*; +import static ca.mcgill.ecse321.scrs.controller.Helper.convertListToDto; +import static ca.mcgill.ecse321.scrs.controller.Helper.convertToDto; @RestController @RequestMapping(path = "/api/workspace") @@ -35,9 +36,34 @@ public ResponseEntity createWorkspace(@RequestParam(value = "name" { return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR); } - try { + try + { return new ResponseEntity<>(convertToDto(workspaceService.createWorkspace(workspaceName)), HttpStatus.OK); - } catch (Exception e) { + } catch (Exception e) + { + return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR); + } + } + + @PutMapping(value = {"/update", "/update/"}) + @CrossOrigin(origins = "*") + public ResponseEntity updateWorkspaceName(@RequestBody WorkspaceDto workspace) + { + if (workspace == null) + { + return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR); + } + Workspace updated = workspaceService.getWorkspaceById(workspace.getWorkspaceId()); + if (updated == null) + { + return new ResponseEntity<>(null, HttpStatus.NOT_ACCEPTABLE); + } + try + { + updated.setSpaceName(workspace.getSpaceName()); + return new ResponseEntity<>(convertToDto(workspaceService.updateWorkspace(updated)), HttpStatus.OK); + } catch (Exception e) + { return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR); } } @@ -46,43 +72,49 @@ public ResponseEntity createWorkspace(@RequestParam(value = "name" @CrossOrigin(origins = "*") public ResponseEntity deleteWorkspace(@PathVariable("id") int workspaceId) { - try { + try + { Workspace workspace = workspaceService.getWorkspaceById(workspaceId); if (workspace == null) { return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR); } return new ResponseEntity<>(convertToDto(workspaceService.deleteWorkspace(workspace)), HttpStatus.OK); - } catch (Exception e) { + } catch (Exception e) + { return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR); } } - @GetMapping(value = {"/availabilities/{id}","/availabilities/{id}/"}) + @GetMapping(value = {"/availabilities/{id}", "/availabilities/{id}/"}) @CrossOrigin(origins = "*") public ResponseEntity> getAllAvailableTimeslotsByWorkspace(@PathVariable("id") int workspaceId) { - try { - Workspace workspace= workspaceService.getWorkspaceById(workspaceId); - if(workspace==null) + try + { + Workspace workspace = workspaceService.getWorkspaceById(workspaceId); + if (workspace == null) { return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR); } - return new ResponseEntity<>(convertToDto(timeslotService.getTimeslotsByWorkspace(workspace)),HttpStatus.OK); - } catch (Exception e) { + return new ResponseEntity<>(convertToDto(timeslotService.getTimeslotsByWorkspace(workspace)), HttpStatus.OK); + } catch (Exception e) + { return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR); } } - @GetMapping(value = {"/getall","/getall/"}) + @GetMapping(value = {"/getall", "/getall/"}) @CrossOrigin(origins = "*") public ResponseEntity> getAll() { - try { + try + { ArrayList workspaces = new ArrayList<>(workspaceService.getAllWorkspaces()); - return new ResponseEntity<>(convertListToDto(workspaces),HttpStatus.OK); - } catch (Exception e) { + return new ResponseEntity<>(convertListToDto(workspaces), HttpStatus.OK); + } catch (Exception e) + { return new ResponseEntity<>(null, HttpStatus.INTERNAL_SERVER_ERROR); } diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dao/AssistantRepository.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dao/AssistantRepository.java index 5dca373..e80715a 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dao/AssistantRepository.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dao/AssistantRepository.java @@ -1,6 +1,6 @@ package ca.mcgill.ecse321.scrs.dao; -import ca.mcgill.ecse321.scrs.model.*; +import ca.mcgill.ecse321.scrs.model.Assistant; import org.springframework.data.repository.CrudRepository; public interface AssistantRepository extends CrudRepository diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dao/CustomerRepository.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dao/CustomerRepository.java index 08f71a5..961b8a1 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dao/CustomerRepository.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dao/CustomerRepository.java @@ -1,11 +1,8 @@ package ca.mcgill.ecse321.scrs.dao; -import ca.mcgill.ecse321.scrs.model.Appointment; import ca.mcgill.ecse321.scrs.model.Customer; import org.springframework.data.repository.CrudRepository; -import java.util.List; - public interface CustomerRepository extends CrudRepository { diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dao/SCRSRepository.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dao/SCRSRepository.java index d970913..85c157f 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dao/SCRSRepository.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dao/SCRSRepository.java @@ -1,12 +1,8 @@ package ca.mcgill.ecse321.scrs.dao; -import ca.mcgill.ecse321.scrs.model.*; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Repository; +import ca.mcgill.ecse321.scrs.model.SCRS; import org.springframework.data.repository.CrudRepository; -import javax.persistence.EntityManager; - public interface SCRSRepository extends CrudRepository { diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dao/TechnicianRepository.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dao/TechnicianRepository.java index 55c4275..881e58b 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dao/TechnicianRepository.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dao/TechnicianRepository.java @@ -1,12 +1,10 @@ package ca.mcgill.ecse321.scrs.dao; import ca.mcgill.ecse321.scrs.model.Technician; -import ca.mcgill.ecse321.scrs.model.Timeslot; import org.springframework.data.repository.CrudRepository; -import java.util.List; - -public interface TechnicianRepository extends CrudRepository { +public interface TechnicianRepository extends CrudRepository +{ Technician findByScrsUserId(int id); diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dao/TimeslotRepository.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dao/TimeslotRepository.java index 72becae..a2554a3 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dao/TimeslotRepository.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dao/TimeslotRepository.java @@ -20,6 +20,6 @@ List findAllByStartDateGreaterThanEqualAndStartDateLessThanEqualOrderByStartDate(Date startDate, Date lastStartDate); List findAllByTechniciansAndStartDateGreaterThanEqualAndAndStartDateLessThanEqualOrderByStartDate(Technician technician, Date startDate, Date lastStartDate); - + List findAllByStartDateGreaterThanEqualOrderByStartDate(Date startDate); } diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dao/WorkspaceRepository.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dao/WorkspaceRepository.java index 3ebd1e2..e7347d7 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dao/WorkspaceRepository.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dao/WorkspaceRepository.java @@ -1,10 +1,10 @@ package ca.mcgill.ecse321.scrs.dao; -import ca.mcgill.ecse321.scrs.model.Timeslot; import ca.mcgill.ecse321.scrs.model.Workspace; import org.springframework.data.repository.CrudRepository; -public interface WorkspaceRepository extends CrudRepository { +public interface WorkspaceRepository extends CrudRepository +{ Workspace findByWorkspaceID(int id); diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dto/AppointmentDto.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dto/AppointmentDto.java index aa3d6e3..92b7be2 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dto/AppointmentDto.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dto/AppointmentDto.java @@ -1,6 +1,5 @@ package ca.mcgill.ecse321.scrs.dto; -import ca.mcgill.ecse321.scrs.model.Appointment; import ca.mcgill.ecse321.scrs.model.Appointment.AppointmentType; import ca.mcgill.ecse321.scrs.model.Timeslot; @@ -94,7 +93,7 @@ public ArrayList getTimeslotsId() public void setTimeslots(List timeslots) { this.timeslotsId = new ArrayList(); - for (Timeslot timeslot: timeslots) + for (Timeslot timeslot : timeslots) { timeslotsId.add(timeslot.getTimeSlotID()); } diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dto/AssistantDto.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dto/AssistantDto.java index 32761b1..b38e586 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dto/AssistantDto.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dto/AssistantDto.java @@ -39,14 +39,14 @@ public String getAssistantEmail() return email; } - public String getAssistantPhone() + public void setAssistantEmail(String email) { - return phone; + this.email = email; } - public void setAssistantEmail(String email) + public String getAssistantPhone() { - this.email = email; + return phone; } public void setAssistantPhone(String phone) diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dto/CustomerDto.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dto/CustomerDto.java index 723900e..c4d3ebb 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dto/CustomerDto.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dto/CustomerDto.java @@ -39,14 +39,14 @@ public String getCustomerEmail() return email; } - public String getCustomerPhone() + public void setCustomerEmail(String email) { - return phone; + this.email = email; } - public void setCustomerEmail(String email) + public String getCustomerPhone() { - this.email = email; + return phone; } public void setCustomerPhone(String phone) diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dto/TechnicianDto.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dto/TechnicianDto.java index 76e7c30..365cc11 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dto/TechnicianDto.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dto/TechnicianDto.java @@ -6,6 +6,7 @@ public class TechnicianDto private String name; private String email; private String phone; + public TechnicianDto() { } @@ -39,14 +40,14 @@ public String getTechnicianEmail() return email; } - public String getTechnicianPhone() + public void setTechnicianEmail(String email) { - return phone; + this.email = email; } - public void setTechnicianEmail(String email) + public String getTechnicianPhone() { - this.email = email; + return phone; } public void setTechnicianPhone(String phone) diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dto/TimeslotDto.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dto/TimeslotDto.java index ae89807..64ec4dc 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dto/TimeslotDto.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dto/TimeslotDto.java @@ -1,7 +1,6 @@ package ca.mcgill.ecse321.scrs.dto; import ca.mcgill.ecse321.scrs.model.Technician; -import ca.mcgill.ecse321.scrs.model.Timeslot; import java.sql.Date; import java.sql.Time; @@ -22,7 +21,8 @@ public TimeslotDto() { } - public TimeslotDto(int id, Date startDate, Date endDate, Time startTime, Time endTime, int workspaceId) { + public TimeslotDto(int id, Date startDate, Date endDate, Time startTime, Time endTime, int workspaceId) + { this(id, startDate, endDate, startTime, endTime, workspaceId, new ArrayList()); } @@ -31,7 +31,7 @@ public TimeslotDto(int id, Date startDate, Date endDate, Time startTime, Time en timeslotId = id; this.startDate = startDate; this.endDate = endDate; - this.startTime =startTime; + this.startTime = startTime; this.endTime = endTime; this.workspaceId = workspaceId; this.techniciansId = techniciansId; @@ -77,7 +77,7 @@ public void setTechnicians(List technicians) this.techniciansId = new ArrayList(); if (technicians != null) { - for (Technician technician: technicians) + for (Technician technician : technicians) { techniciansId.add(technician.getScrsUserId()); } diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dto/WorkspaceDto.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dto/WorkspaceDto.java index e65d7a8..24de32a 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dto/WorkspaceDto.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/dto/WorkspaceDto.java @@ -47,7 +47,7 @@ public void setTimeslotsId(List availabilities) this.timeslotsId = new ArrayList(); if (availabilities != null) { - for (Timeslot timeslot: availabilities) + for (Timeslot timeslot : availabilities) { timeslotsId.add(timeslot.getTimeSlotID()); } diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/model/Appointment.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/model/Appointment.java index 2398e49..a03ada4 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/model/Appointment.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/model/Appointment.java @@ -2,17 +2,16 @@ import org.hibernate.annotations.GenericGenerator; -import java.util.*; import javax.persistence.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; @Entity public class Appointment { - public enum AppointmentType - { - CarWash, Maintenance, OilChange, TireChange, Towing, Inspection, RoadsideAssistance, Checkup, Other - } - + @OneToMany(fetch = FetchType.EAGER) //0..1 to 1..* + private final List timeslots; // Appointment Attributes @Id @GeneratedValue(generator = "increment") @@ -24,12 +23,9 @@ public enum AppointmentType private int rating; private String feedback; private boolean paid; - // Appointment Associations @ManyToOne private Customer customer; - @OneToMany(fetch = FetchType.EAGER) //0..1 to 1..* - private List timeslots; @ManyToOne private SCRS scrs; @@ -304,8 +300,7 @@ public boolean addOrMoveTimeslotAt(Timeslot aTimeslot, int index) timeslots.remove(aTimeslot); timeslots.add(index, aTimeslot); wasAdded = true; - } - else + } else { wasAdded = addTimeslotAt(aTimeslot, index); } @@ -359,4 +354,9 @@ public String toString() + System.getProperties().getProperty("line.separator") + " " + "scrs = " + (getScrs() != null ? Integer.toHexString(System.identityHashCode(getScrs())) : "null"); } + + public enum AppointmentType + { + CarWash, Maintenance, OilChange, TireChange, Towing, Inspection, RoadsideAssistance, Checkup, Other + } } \ No newline at end of file diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/model/Customer.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/model/Customer.java index 1fadf2a..2888ed6 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/model/Customer.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/model/Customer.java @@ -1,9 +1,6 @@ package ca.mcgill.ecse321.scrs.model; -import java.util.*; - import javax.persistence.Entity; -import javax.persistence.OneToMany; @Entity public class Customer extends SCRSUser diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/model/SCRS.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/model/SCRS.java index 3addacf..30107c2 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/model/SCRS.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/model/SCRS.java @@ -2,9 +2,9 @@ import org.hibernate.annotations.GenericGenerator; -import java.util.List; -import java.util.ArrayList; import javax.persistence.*; +import java.util.ArrayList; +import java.util.List; @Entity public class SCRS @@ -161,8 +161,7 @@ public boolean addWorkspace(Workspace aWorkspace) if (isNewScrs) { aWorkspace.setScrs(this); - } - else + } else { workspaces.add(aWorkspace); } @@ -220,8 +219,7 @@ public boolean addOrMoveWorkspaceAt(Workspace aWorkspace, int index) workspaces.remove(aWorkspace); workspaces.add(index, aWorkspace); wasAdded = true; - } - else + } else { wasAdded = addWorkspaceAt(aWorkspace, index); } @@ -240,8 +238,7 @@ public boolean addUser(SCRSUser aSCRSUser) if (isNewScrs) { aSCRSUser.setScrs(this); - } - else + } else { scrsUsers.add(aSCRSUser); } @@ -298,8 +295,7 @@ public boolean addOrMoveUserAt(SCRSUser aSCRSUser, int index) scrsUsers.remove(aSCRSUser); scrsUsers.add(index, aSCRSUser); wasAdded = true; - } - else + } else { wasAdded = addUserAt(aSCRSUser, index); } @@ -326,8 +322,7 @@ public boolean addAppointment(Appointment aAppointment) if (isNewScrs) { aAppointment.setScrs(this); - } - else + } else { appointments.add(aAppointment); } @@ -384,8 +379,7 @@ public boolean addOrMoveAppointmentAt(Appointment aAppointment, int index) appointments.remove(aAppointment); appointments.add(index, aAppointment); wasAdded = true; - } - else + } else { wasAdded = addAppointmentAt(aAppointment, index); } diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/model/Technician.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/model/Technician.java index df19575..56f8f6c 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/model/Technician.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/model/Technician.java @@ -1,11 +1,6 @@ package ca.mcgill.ecse321.scrs.model; -import java.util.*; - import javax.persistence.Entity; -import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; -import javax.persistence.ManyToMany; @Entity public class Technician extends SCRSUser diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/model/Timeslot.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/model/Timeslot.java index 9eb7764..66971ef 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/model/Timeslot.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/model/Timeslot.java @@ -2,10 +2,11 @@ import org.hibernate.annotations.GenericGenerator; +import javax.persistence.*; import java.sql.Date; import java.sql.Time; -import java.util.*; -import javax.persistence.*; +import java.util.ArrayList; +import java.util.List; @Entity public class Timeslot @@ -209,8 +210,7 @@ public boolean addOrMoveTechnicianAt(Technician aTechnician, int index) technicians.remove(aTechnician); technicians.add(index, aTechnician); wasAdded = true; - } - else + } else { wasAdded = addTechnicianAt(aTechnician, index); } diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/model/Workspace.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/model/Workspace.java index 3e6af97..1992abc 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/model/Workspace.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/model/Workspace.java @@ -3,10 +3,11 @@ import org.hibernate.annotations.GenericGenerator; -import java.util.*; +import javax.persistence.*; import java.sql.Date; import java.sql.Time; -import javax.persistence.*; +import java.util.ArrayList; +import java.util.List; @Entity public class Workspace @@ -122,8 +123,7 @@ public boolean addAvailability(Timeslot aAvailability) if (isNewWorkspace) { aAvailability.setWorkspace(this); - } - else + } else { availabilities.add(aAvailability); } @@ -179,8 +179,7 @@ public boolean addOrMoveAvailabilityAt(Timeslot aAvailability, int index) availabilities.remove(aAvailability); availabilities.add(index, aAvailability); wasAdded = true; - } - else + } else { wasAdded = addAvailabilityAt(aAvailability, index); } diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/service/AppointmentService.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/service/AppointmentService.java index d844f71..5ac24c2 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/service/AppointmentService.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/service/AppointmentService.java @@ -16,7 +16,8 @@ import static ca.mcgill.ecse321.scrs.service.ServiceHelpers.toList; @Service -public class AppointmentService { +public class AppointmentService +{ @Autowired AppointmentRepository appointmentRepository; @@ -26,12 +27,15 @@ public class AppointmentService { TimeslotRepository timeslotRepository; @Transactional - public Appointment createAppointment(Appointment.AppointmentType appointmentType, String service, String note, boolean paid, Customer customer, Timeslot... timeslots) { - if(appointmentType == null) throw new IllegalArgumentException("Please submit a valid appointment type."); - if(customer == null || customerRepository.findByScrsUserId(customer.getScrsUserId()) == null) throw new IllegalArgumentException("Please submit a valid customer."); + public Appointment createAppointment(Appointment.AppointmentType appointmentType, String service, String note, boolean paid, Customer customer, Timeslot... timeslots) + { + if (appointmentType == null) throw new IllegalArgumentException("Please submit a valid appointment type."); + if (customer == null || customerRepository.findByScrsUserId(customer.getScrsUserId()) == null) + throw new IllegalArgumentException("Please submit a valid customer."); try { - if(timeslots.length == 0 || timeslotRepository.findByTimeSlotID(timeslots[0].getTimeSlotID()) == null) throw new IllegalArgumentException("Please select at least one valid timeslot."); + if (timeslots.length == 0 || timeslotRepository.findByTimeSlotID(timeslots[0].getTimeSlotID()) == null) + throw new IllegalArgumentException("Please select at least one valid timeslot."); } catch (NullPointerException e) { throw new IllegalArgumentException("Please select at least one valid timeslot."); @@ -48,27 +52,32 @@ public Appointment createAppointment(Appointment.AppointmentType appointmentType } @Transactional - public List getAllAppointments() { + public List getAllAppointments() + { return toList(appointmentRepository.findAll()); } @Transactional - public Appointment getAppointmentById(int id) { + public Appointment getAppointmentById(int id) + { return appointmentRepository.findByAppointmentID(id); } @Transactional - public List getAppointmentsByCustomer(Customer customer) { + public List getAppointmentsByCustomer(Customer customer) + { return appointmentRepository.findAppointmentsByCustomer(customer); } @Transactional - public Appointment getAppointmentByTimeslot(Timeslot timeslot) { + public Appointment getAppointmentByTimeslot(Timeslot timeslot) + { return appointmentRepository.findByTimeslotsContains(timeslot); } @Transactional - public Appointment rateAppointment(int appointmentId, int rating) { + public Appointment rateAppointment(int appointmentId, int rating) + { Appointment appointment = getAppointmentById(appointmentId); if (appointment == null) throw new IllegalArgumentException("No such appointment!"); if (rating > 10 || rating < 0) throw new IllegalArgumentException("Invalid rating"); @@ -84,9 +93,11 @@ public Appointment modifyAppointment(AppointmentDto appt) if (appt == null) throw new IllegalArgumentException("Invalid appointment"); if (appt.getAppointmentType() == null) throw new IllegalArgumentException("Invalid appointment type."); if (appt.getCustomerId() == -1) throw new IllegalArgumentException("Invalid customer."); - if (appt.getTimeslotsId() == null || appt.getTimeslotsId().size() == 0) throw new IllegalArgumentException("No valid timeslots selected."); - if (appt.getRating() != -1 && (appt.getRating() > 10 || appt.getRating() < 0)) throw new IllegalArgumentException("Invalid rating"); - + if (appt.getTimeslotsId() == null || appt.getTimeslotsId().size() == 0) + throw new IllegalArgumentException("No valid timeslots selected."); + if (appt.getRating() != -1 && (appt.getRating() > 10 || appt.getRating() < 0)) + throw new IllegalArgumentException("Invalid rating"); + Appointment apptToModify = appointmentRepository.findByAppointmentID(appt.getAppointmentId()); if (apptToModify == null) throw new IllegalArgumentException("No such appointment exists"); diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/service/AssistantService.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/service/AssistantService.java index ccf14a3..ea3e872 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/service/AssistantService.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/service/AssistantService.java @@ -1,5 +1,6 @@ package ca.mcgill.ecse321.scrs.service; +import ca.mcgill.ecse321.scrs.controller.Helper; import ca.mcgill.ecse321.scrs.dao.AssistantRepository; import ca.mcgill.ecse321.scrs.model.Assistant; import org.springframework.beans.factory.annotation.Autowired; @@ -64,10 +65,14 @@ public Assistant getAssistantByPhone(String phone) public Assistant updateAssistantInfo(Assistant assistant) { checkAccountInfoValidity(assistant); - if(assistant.getPassword() == null || assistant.getPassword().trim().length() == 0) + if (assistant.getPassword() == null || assistant.getPassword().trim().length() == 0) { assistant.setPassword(getAssistantByID(assistant.getScrsUserId()).getPassword()); } + else + { + assistant.setPassword(Helper.hash(assistant.getPassword())); + } assistantRepository.save(assistant); return assistant; } diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/service/CustomerService.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/service/CustomerService.java index ac48fa7..1ed6355 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/service/CustomerService.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/service/CustomerService.java @@ -1,6 +1,9 @@ package ca.mcgill.ecse321.scrs.service; +import ca.mcgill.ecse321.scrs.dao.AppointmentRepository; +import ca.mcgill.ecse321.scrs.controller.Helper; import ca.mcgill.ecse321.scrs.dao.CustomerRepository; +import ca.mcgill.ecse321.scrs.model.Appointment; import ca.mcgill.ecse321.scrs.model.Customer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -18,6 +21,9 @@ public class CustomerService @Autowired CustomerRepository customerRepository; + @Autowired + AppointmentRepository appointmentRepository; + @Transactional public Customer createCustomer(String email, String name, String password, String phone) { @@ -65,10 +71,14 @@ public Customer getCustomerByPhone(String phone) public Customer updateCustomerInfo(Customer customer) { checkAccountInfoValidity(customer); - if(customer.getPassword() == null || customer.getPassword().trim().length() == 0) + if (customer.getPassword() == null || customer.getPassword().trim().length() == 0) { customer.setPassword(getCustomerByID(customer.getScrsUserId()).getPassword()); } + else + { + customer.setPassword(Helper.hash(customer.getPassword())); + } customerRepository.save(customer); return customer; } @@ -76,6 +86,9 @@ public Customer updateCustomerInfo(Customer customer) @Transactional public Customer deleteCustomer(Customer customer) { + List appts = appointmentRepository.findAppointmentsByCustomer(customer); + appointmentRepository.deleteAll(appts); + customerRepository.delete(customer); return customer; } diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/service/SCRSService.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/service/SCRSService.java index 444b12e..fd01b9b 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/service/SCRSService.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/service/SCRSService.java @@ -6,7 +6,8 @@ @Service -public class SCRSService { +public class SCRSService +{ @Autowired SCRSRepository scrsRepository; diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/service/SCRSUserService.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/service/SCRSUserService.java index 22030e6..e150184 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/service/SCRSUserService.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/service/SCRSUserService.java @@ -1,7 +1,6 @@ package ca.mcgill.ecse321.scrs.service; import ca.mcgill.ecse321.scrs.dao.SCRSUserRepository; -import ca.mcgill.ecse321.scrs.model.Customer; import ca.mcgill.ecse321.scrs.model.SCRSUser; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/service/ServiceHelpers.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/service/ServiceHelpers.java index 8913f1d..4cf10bf 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/service/ServiceHelpers.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/service/ServiceHelpers.java @@ -10,9 +10,11 @@ public class ServiceHelpers { - public static List toList(Iterable iterable){ + public static List toList(Iterable iterable) + { List resultList = new ArrayList(); - for (T t : iterable) { + for (T t : iterable) + { resultList.add(t); } return resultList; @@ -20,29 +22,40 @@ public static List toList(Iterable iterable){ public static void checkAccountInfoValidity(String email, String name, String password, String phone) { - if(email == null || email.trim().length() == 0) throw new IllegalArgumentException("Please submit a valid email."); - if(name == null || name.trim().length() == 0) throw new IllegalArgumentException("Please submit a valid name."); - if(password == null || password.trim().length() == 0) throw new IllegalArgumentException("Please submit a valid password."); - if(phone == null || phone.trim().length() == 0) throw new IllegalArgumentException("Please submit a valid phone."); + if (email == null || email.trim().length() == 0) + throw new IllegalArgumentException("Please submit a valid email."); + if (name == null || name.trim().length() == 0) + throw new IllegalArgumentException("Please submit a valid name."); + if (password == null || password.trim().length() == 0) + throw new IllegalArgumentException("Please submit a valid password."); + if (phone == null || phone.trim().length() == 0) + throw new IllegalArgumentException("Please submit a valid phone."); } public static void checkAccountInfoValidity(SCRSUser user) { if (user == null) throw new IllegalArgumentException("Please submit a valid user object."); - if(user.getEmail() == null || user.getEmail().trim().length() == 0) throw new IllegalArgumentException("Please submit a valid email."); - if(user.getName() == null || user.getName().trim().length() == 0) throw new IllegalArgumentException("Please submit a valid name."); - if(user.getPhone() == null || user.getPhone().trim().length() == 0) throw new IllegalArgumentException("Please submit a valid phone."); + if (user.getEmail() == null || user.getEmail().trim().length() == 0) + throw new IllegalArgumentException("Please submit a valid email."); + if (user.getName() == null || user.getName().trim().length() == 0) + throw new IllegalArgumentException("Please submit a valid name."); + if (user.getPhone() == null || user.getPhone().trim().length() == 0) + throw new IllegalArgumentException("Please submit a valid phone."); } public static void checkDateValidity(Date startDate, Date endDate) { - if (startDate == null || endDate == null) throw new IllegalArgumentException("Please input a valid start and end date."); - if (startDate.after(endDate)) throw new IllegalArgumentException("Your start date cannot be after your end date."); + if (startDate == null || endDate == null) + throw new IllegalArgumentException("Please input a valid start and end date."); + if (startDate.after(endDate)) + throw new IllegalArgumentException("Your start date cannot be after your end date."); } public static void checkTimeValidity(Time startTime, Time endTime) { - if (startTime == null || endTime == null) throw new IllegalArgumentException("Please input a valid start and end time."); - if (startTime.after(endTime)) throw new IllegalArgumentException("Your start time cannot be after your end time."); + if (startTime == null || endTime == null) + throw new IllegalArgumentException("Please input a valid start and end time."); + if (startTime.after(endTime)) + throw new IllegalArgumentException("Your start time cannot be after your end time."); } } diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/service/TechnicianService.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/service/TechnicianService.java index 1e340a1..ebd9dd4 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/service/TechnicianService.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/service/TechnicianService.java @@ -1,5 +1,6 @@ package ca.mcgill.ecse321.scrs.service; +import ca.mcgill.ecse321.scrs.controller.Helper; import ca.mcgill.ecse321.scrs.dao.TechnicianRepository; import ca.mcgill.ecse321.scrs.model.Technician; import org.springframework.beans.factory.annotation.Autowired; @@ -62,10 +63,14 @@ public Technician getTechnicianByPhone(String phone) public Technician updateTechnicianInfo(Technician technician) { checkAccountInfoValidity(technician); - if(technician.getPassword() == null || technician.getPassword().trim().length() == 0) + if (technician.getPassword() == null || technician.getPassword().trim().length() == 0) { technician.setPassword(getTechnicianByID(technician.getScrsUserId()).getPassword()); } + else + { + technician.setPassword(Helper.hash(technician.getPassword())); + } technicianRepository.save(technician); return technician; } diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/service/TimeslotService.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/service/TimeslotService.java index 705e6e1..0741559 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/service/TimeslotService.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/service/TimeslotService.java @@ -39,7 +39,8 @@ public Timeslot createTimeslot(Date startDate, Date endDate, Time startTime, Tim { checkDateValidity(startDate, endDate); checkTimeValidity(startTime, endTime); - if (workspace == null || workspaceRepository.findByWorkspaceID(workspace.getWorkspaceID()) == null ) throw new IllegalArgumentException("Please input a valid workspace."); + if (workspace == null || workspaceRepository.findByWorkspaceID(workspace.getWorkspaceID()) == null) + throw new IllegalArgumentException("Please input a valid workspace."); Timeslot timeslot = new Timeslot(); timeslot.setStartDate(startDate); timeslot.setEndDate(endDate); @@ -65,9 +66,10 @@ public Timeslot getTimeslotById(int id) @Transactional public List getTimeslotsById(List timeslotsId) { - if (timeslotsId == null || timeslotsId.size() == 0) throw new IllegalArgumentException("Please input at least one valid timeslot ID."); + if (timeslotsId == null || timeslotsId.size() == 0) + throw new IllegalArgumentException("Please input at least one valid timeslot ID."); ArrayList timeslots = new ArrayList<>(); - for (int id: timeslotsId) + for (int id : timeslotsId) { timeslots.add(timeslotRepository.findByTimeSlotID(id)); } @@ -78,9 +80,10 @@ public List getTimeslotsById(List timeslotsId) public List getTimeslotsByTechnicianBetweenDates(Technician technician, Date startDate, Date endDate) { checkDateValidity(startDate, endDate); - if (technician == null || technicianRepository.findByScrsUserId(technician.getScrsUserId()) == null) throw new IllegalArgumentException("Invalid technician."); - List timeslotsInPeriod = timeslotRepository.findAllByTechniciansAndStartDateGreaterThanEqualAndAndStartDateLessThanEqualOrderByStartDate(technician, startDate,endDate); - List technicianTimeslots= toList(timeslotRepository.findByTechnicians(technician)); + if (technician == null || technicianRepository.findByScrsUserId(technician.getScrsUserId()) == null) + throw new IllegalArgumentException("Invalid technician."); + List timeslotsInPeriod = timeslotRepository.findAllByTechniciansAndStartDateGreaterThanEqualAndAndStartDateLessThanEqualOrderByStartDate(technician, startDate, endDate); + List technicianTimeslots = toList(timeslotRepository.findByTechnicians(technician)); technicianTimeslots.retainAll(timeslotsInPeriod); return timeslotsInPeriod; } @@ -88,7 +91,8 @@ public List getTimeslotsByTechnicianBetweenDates(Technician technician @Transactional public List getTimeslotsByWorkspace(Workspace workspace) { - if (workspace == null || workspaceRepository.findByWorkspaceID(workspace.getWorkspaceID()) == null) throw new IllegalArgumentException("Invalid workspace."); + if (workspace == null || workspaceRepository.findByWorkspaceID(workspace.getWorkspaceID()) == null) + throw new IllegalArgumentException("Invalid workspace."); return toList(timeslotRepository.findByWorkspace(workspace)); } @@ -103,8 +107,10 @@ public List getAvailableTimeslots(Date startDate) @Transactional public boolean assignTechnicianToTimeslot(Technician tech, Timeslot ts) { - if (tech == null || technicianRepository.findByScrsUserId(tech.getScrsUserId()) == null) throw new IllegalArgumentException("Invalid technician."); - if (ts == null || timeslotRepository.findByTimeSlotID(ts.getTimeSlotID()) == null) throw new IllegalArgumentException("Invalid timeslot."); + if (tech == null || technicianRepository.findByScrsUserId(tech.getScrsUserId()) == null) + throw new IllegalArgumentException("Invalid technician."); + if (ts == null || timeslotRepository.findByTimeSlotID(ts.getTimeSlotID()) == null) + throw new IllegalArgumentException("Invalid timeslot."); if (ts.getTechnicians() != null && ts.getTechnicians().contains(tech)) return false; ts.addTechnician(tech); timeslotRepository.save(ts); diff --git a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/service/WorkspaceService.java b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/service/WorkspaceService.java index c8f3243..1977fed 100644 --- a/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/service/WorkspaceService.java +++ b/SCRS-Backend/src/main/java/ca/mcgill/ecse321/scrs/service/WorkspaceService.java @@ -27,6 +27,15 @@ public Workspace createWorkspace(String name) return workspace; } + @Transactional + public Workspace updateWorkspace(Workspace workspace) + { + if (workspace == null || workspaceRepository.findByWorkspaceID(workspace.getWorkspaceID()) == null) + throw new IllegalArgumentException("Invalid workspace"); + workspaceRepository.save(workspace); + return workspace; + } + @Transactional public List getAllWorkspaces() { diff --git a/beep.txt b/beep.txt deleted file mode 100644 index e69de29..0000000 diff --git a/client/.firebase/hosting.ZGlzdA.cache b/client/.firebase/hosting.ZGlzdA.cache new file mode 100644 index 0000000..8ad3483 --- /dev/null +++ b/client/.firebase/hosting.ZGlzdA.cache @@ -0,0 +1,8 @@ +index.html,1617505772338,a71b8759341a498d7c4595a2a8ee4a3f7293bc1d490020c10286d35926f98720 +favicon.ico,1617505772338,b4d8a8901b72ef6e80d3d700416a505e3d37a423ea3a21660ac9665356cb55a8 +css/app.08781967.css,1617505772339,f1a467a093038fc9a6f20e122d51c6e057b26bfc1a01b4b7b6affc8800e42e47 +js/app.0d553110.js,1617505772341,26c388110ff800c75ad8018a3a5c6f86d5962b2ff2cdfcccb9ab119dc8f402dc +js/chunk-vendors.125e35bb.js,1617505772341,b81891b7d60c255608c324af63d67853cff013b6a8d347297ba3a58797e18e6d +js/app.0d553110.js.map,1617505772341,2d85a8d2daf5d55b8ab2500115aa7d0d2e4df9c0659b17dd6830e7e65954b72d +img/logo3.c64814a7.png,1617505772339,4586d2c10a92a92133098578f23b888f9752111406dc5e2319c7e92906c894fb +js/chunk-vendors.125e35bb.js.map,1617505772343,021e2af2afc1883ae00fb56369129afe5b82e426cc748491e19432b357e07ede diff --git a/client/.firebaserc b/client/.firebaserc new file mode 100644 index 0000000..984cae7 --- /dev/null +++ b/client/.firebaserc @@ -0,0 +1,5 @@ +{ + "projects": { + "default": "scrs-f86ed" + } +} diff --git a/client/firebase.json b/client/firebase.json new file mode 100644 index 0000000..059fe4f --- /dev/null +++ b/client/firebase.json @@ -0,0 +1,10 @@ +{ + "hosting": { + "public": "dist", + "ignore": [ + "firebase.json", + "**/.*", + "**/node_modules/**" + ] + } +} diff --git a/client/package-lock.json b/client/package-lock.json index 881829f..26ff4fa 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -1715,16 +1715,6 @@ "integrity": "sha1-/q7SVZc9LndVW4PbwIhRpsY1IPo=", "dev": true }, - "ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dev": true, - "optional": true, - "requires": { - "color-convert": "^2.0.1" - } - }, "cacache": { "version": "13.0.1", "resolved": "https://registry.npm.taobao.org/cacache/download/cacache-13.0.1.tgz", @@ -1751,53 +1741,6 @@ "unique-filename": "^1.1.1" } }, - "chalk": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.0.tgz", - "integrity": "sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==", - "dev": true, - "optional": true, - "requires": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" - } - }, - "color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dev": true, - "optional": true, - "requires": { - "color-name": "~1.1.4" - } - }, - "color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "dev": true, - "optional": true - }, - "has-flag": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "dev": true, - "optional": true - }, - "loader-utils": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.0.tgz", - "integrity": "sha512-rP4F0h2RaWSvPEkD7BLDFQnvSf+nK+wr3ESUjNTyAGobqrijmW92zc+SO6d4p4B1wh7+B/Jg1mkQe5NYUEHtHQ==", - "dev": true, - "optional": true, - "requires": { - "big.js": "^5.2.2", - "emojis-list": "^3.0.0", - "json5": "^2.1.2" - } - }, "source-map": { "version": "0.6.1", "resolved": "https://registry.npm.taobao.org/source-map/download/source-map-0.6.1.tgz", @@ -1814,16 +1757,6 @@ "minipass": "^3.1.1" } }, - "supports-color": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", - "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dev": true, - "optional": true, - "requires": { - "has-flag": "^4.0.0" - } - }, "terser-webpack-plugin": { "version": "2.3.8", "resolved": "https://registry.npm.taobao.org/terser-webpack-plugin/download/terser-webpack-plugin-2.3.8.tgz?cache=0&sync_timestamp=1610194258495&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fterser-webpack-plugin%2Fdownload%2Fterser-webpack-plugin-2.3.8.tgz", @@ -1840,18 +1773,6 @@ "terser": "^4.6.12", "webpack-sources": "^1.4.3" } - }, - "vue-loader-v16": { - "version": "npm:vue-loader@16.1.2", - "resolved": "https://registry.npmjs.org/vue-loader/-/vue-loader-16.1.2.tgz", - "integrity": "sha512-8QTxh+Fd+HB6fiL52iEVLKqE9N1JSlMXLR92Ijm6g8PZrwIxckgpqjPDWRP5TWxdiPaHR+alUWsnu1ShQOwt+Q==", - "dev": true, - "optional": true, - "requires": { - "chalk": "^4.1.0", - "hash-sum": "^2.0.0", - "loader-utils": "^2.0.0" - } } } }, @@ -11132,6 +11053,87 @@ } } }, + "vue-loader-v16": { + "version": "npm:vue-loader@16.2.0", + "resolved": "https://registry.npmjs.org/vue-loader/-/vue-loader-16.2.0.tgz", + "integrity": "sha512-TitGhqSQ61RJljMmhIGvfWzJ2zk9m1Qug049Ugml6QP3t0e95o0XJjk29roNEiPKJQBEi8Ord5hFuSuELzSp8Q==", + "dev": true, + "optional": true, + "requires": { + "chalk": "^4.1.0", + "hash-sum": "^2.0.0", + "loader-utils": "^2.0.0" + }, + "dependencies": { + "ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "optional": true, + "requires": { + "color-convert": "^2.0.1" + } + }, + "chalk": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.0.tgz", + "integrity": "sha512-qwx12AxXe2Q5xQ43Ac//I6v5aXTipYrSESdOgzrN+9XjgEpyjpKuvSGaN4qE93f7TQTlerQQ8S+EQ0EyDoVL1A==", + "dev": true, + "optional": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "optional": true, + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true, + "optional": true + }, + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true, + "optional": true + }, + "loader-utils": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-2.0.0.tgz", + "integrity": "sha512-rP4F0h2RaWSvPEkD7BLDFQnvSf+nK+wr3ESUjNTyAGobqrijmW92zc+SO6d4p4B1wh7+B/Jg1mkQe5NYUEHtHQ==", + "dev": true, + "optional": true, + "requires": { + "big.js": "^5.2.2", + "emojis-list": "^3.0.0", + "json5": "^2.1.2" + } + }, + "supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "optional": true, + "requires": { + "has-flag": "^4.0.0" + } + } + } + }, "vue-router": { "version": "3.5.1", "resolved": "https://registry.npmjs.org/vue-router/-/vue-router-3.5.1.tgz", diff --git a/client/package.json b/client/package.json index 06b2e7e..aa6f04d 100644 --- a/client/package.json +++ b/client/package.json @@ -1,5 +1,5 @@ { - "name": "client", + "name": "scrs", "version": "0.1.0", "private": true, "scripts": { diff --git a/client/public/favicon.ico b/client/public/favicon.ico index df36fcf..7dcbf1c 100644 Binary files a/client/public/favicon.ico and b/client/public/favicon.ico differ diff --git a/client/src/assets/logo3.png b/client/src/assets/logo3.png new file mode 100644 index 0000000..cd18b76 Binary files /dev/null and b/client/src/assets/logo3.png differ diff --git a/client/src/pages/AssignTechnicianSchedule.vue b/client/src/pages/AssignTechnicianSchedule.vue index 6f1039d..a603fe6 100644 --- a/client/src/pages/AssignTechnicianSchedule.vue +++ b/client/src/pages/AssignTechnicianSchedule.vue @@ -38,26 +38,29 @@ > -
- + +
+ +
+
+ +
+ +
+
+