diff --git a/src/main/java/mk/ukim/finki/konsultacii/service/ConsultationAttendanceService.java b/src/main/java/mk/ukim/finki/konsultacii/service/ConsultationAttendanceService.java index ea7863b335e464fa8a482ecc04debf0f957dfa4a..2dc5e1064f727170d071a0743791beb3fc554b30 100644 --- a/src/main/java/mk/ukim/finki/konsultacii/service/ConsultationAttendanceService.java +++ b/src/main/java/mk/ukim/finki/konsultacii/service/ConsultationAttendanceService.java @@ -20,11 +20,7 @@ public interface ConsultationAttendanceService { void registerStudentForConsultationTerm(Long consultationId, String index, String comment); - List<ConsultationAttendance> listAttendancesForCurrentProfessor(String professorId, String time, String type, String studentIndex); - - List<ConsultationAttendance> listAttendancesForCurrentStudent(String studentUsername, String time, String type); - - List<ConsultationAttendance> listAllAttendances(String time, String type, String professorId, String studentIndex); + List<ConsultationAttendance> listAttendances(String time, String type, String professorId, String studentIndex); void reportAbsentProfessor(Long attendanceId, Boolean reportAbsentProfessor, String absentProfessorComment); diff --git a/src/main/java/mk/ukim/finki/konsultacii/service/implementation/ConsultationAttendanceServiceImpl.java b/src/main/java/mk/ukim/finki/konsultacii/service/implementation/ConsultationAttendanceServiceImpl.java index d4838eb090bcfe79f0935d389942e40af0a98eb0..beee081566dcbd52d9ef3a31b104d0bbd10215af 100644 --- a/src/main/java/mk/ukim/finki/konsultacii/service/implementation/ConsultationAttendanceServiceImpl.java +++ b/src/main/java/mk/ukim/finki/konsultacii/service/implementation/ConsultationAttendanceServiceImpl.java @@ -83,101 +83,19 @@ public class ConsultationAttendanceServiceImpl implements ConsultationAttendance } @Override - public List<ConsultationAttendance> listAttendancesForCurrentProfessor(String professorId, String time, String type, String studentIndex) { - Specification<ConsultationAttendance> spec = Specification - .where(filterEqualsV(ConsultationAttendance.class, "consultation.professor.id", professorId)); - - - if (type != null && !type.isEmpty() && !type.equals("ALL")) { - spec = spec.and(filterEqualsV(ConsultationAttendance.class,"consultation.type", ConsultationType.valueOf(type))); - } - - if(studentIndex != null && !studentIndex.isEmpty() && !studentIndex.equals("ALL")){ - spec = spec.and(filterContainsText(ConsultationAttendance.class, "attendee.index", studentIndex)); - } - - List<ConsultationAttendance> attendances = attendsRepository.findAll(spec); - - LocalDateTime now = LocalDateTime.now(); - - List<ConsultationAttendance> pastAttendances = attendances.stream() - .filter(att -> att.getConsultation().getOneTimeDate().atTime(att.getConsultation().getStartTime()).isBefore(now)) - .sorted(Comparator.comparing(ConsultationAttendance::getConsultationOneTimeDate) - .thenComparing(ConsultationAttendance::getConsultationStartTime).reversed()) - .toList(); - - List<ConsultationAttendance> upcomingAttendances = attendances.stream() - .filter(att -> att.getConsultation().getOneTimeDate().atTime(att.getConsultation().getStartTime()).isAfter(now)) - .sorted(Comparator.comparing(ConsultationAttendance::getConsultationOneTimeDate) - .thenComparing(ConsultationAttendance::getConsultationStartTime)) - .toList(); - - List<ConsultationAttendance> sortedAttendances = new ArrayList<>(); - if (time == null || time.isEmpty() || time.equals("ALL")) { - sortedAttendances.addAll(upcomingAttendances); - sortedAttendances.addAll(pastAttendances); - } else if (time.equals("UPCOMING")) { - sortedAttendances = upcomingAttendances; - } else if (time.equals("PAST")) { - sortedAttendances = pastAttendances; - } - - return sortedAttendances; - } - - @Override - public List<ConsultationAttendance> listAttendancesForCurrentStudent(String studentUsername, String time, String type) { - - Specification<ConsultationAttendance> spec = Specification - .where(filterEquals(ConsultationAttendance.class, "attendee.index", studentUsername)); - - if (type != null && !type.isEmpty() && !type.equals("ALL")) { - spec = spec.and(filterEqualsV(ConsultationAttendance.class,"consultation.type", ConsultationType.valueOf(type))); - } - - List<ConsultationAttendance> attendances = attendsRepository.findAll(spec); - - LocalDateTime now = LocalDateTime.now(); - - List<ConsultationAttendance> pastAttendances = attendances.stream() - .filter(att -> att.getConsultation().getOneTimeDate().atTime(att.getConsultation().getStartTime()).isBefore(now)) - .sorted(Comparator.comparing(ConsultationAttendance::getConsultationOneTimeDate) - .thenComparing(ConsultationAttendance::getConsultationStartTime).reversed()) - .toList(); - - List<ConsultationAttendance> upcomingAttendances = attendances.stream() - .filter(att -> att.getConsultation().getOneTimeDate().atTime(att.getConsultation().getStartTime()).isAfter(now)) - .sorted(Comparator.comparing(ConsultationAttendance::getConsultationOneTimeDate) - .thenComparing(ConsultationAttendance::getConsultationStartTime)) - .toList(); - - List<ConsultationAttendance> sortedAttendances = new ArrayList<>(); - if (time == null || time.isEmpty() || time.equals("ALL")) { - sortedAttendances.addAll(upcomingAttendances); - sortedAttendances.addAll(pastAttendances); - } else if (time.equals("UPCOMING")) { - sortedAttendances = upcomingAttendances; - } else if (time.equals("PAST")) { - sortedAttendances = pastAttendances; - } - - return sortedAttendances; - } - - @Override - public List<ConsultationAttendance> listAllAttendances(String time, String type, String professorId, String studentIndex) { + public List<ConsultationAttendance> listAttendances(String time, String type, String professorId, String studentIndex) { Specification<ConsultationAttendance> spec = Specification.where(null); - if (professorId != null && !professorId.isEmpty() && !professorId.equals("ALL")) { + if (professorId != null && !professorId.isEmpty()) { spec = spec.and(filterEqualsV(ConsultationAttendance.class, "consultation.professor.id", professorId)); } - if (studentIndex != null && !studentIndex.isEmpty() && !studentIndex.equals("ALL")) { + if (studentIndex != null && !studentIndex.isEmpty()) { spec = spec.and(filterContainsText(ConsultationAttendance.class, "attendee.index", studentIndex)); } - if (type != null && !type.isEmpty() && !type.equals("ALL")) { + if (type != null && !type.isEmpty()) { spec = spec.and(filterEqualsV(ConsultationAttendance.class, "consultation.type", ConsultationType.valueOf(type))); } @@ -198,12 +116,12 @@ public class ConsultationAttendanceServiceImpl implements ConsultationAttendance .toList(); List<ConsultationAttendance> sortedAttendances = new ArrayList<>(); - if (time == null || time.isEmpty() || time.equals("ALL")) { + if (time == null || time.isEmpty()) { sortedAttendances.addAll(upcomingAttendances); sortedAttendances.addAll(pastAttendances); - } else if (time.equals("UPCOMING")) { + } else if ("UPCOMING".equalsIgnoreCase(time)) { sortedAttendances = upcomingAttendances; - } else if (time.equals("PAST")) { + } else if ("PAST".equalsIgnoreCase(time)) { sortedAttendances = pastAttendances; } diff --git a/src/main/java/mk/ukim/finki/konsultacii/service/implementation/ConsultationServiceImpl.java b/src/main/java/mk/ukim/finki/konsultacii/service/implementation/ConsultationServiceImpl.java index 304b997cc67f07a2233cdb0c807b1a830830f8f2..ad28ef9e2654490b3cf9ed2f3ad4a5057dd64e21 100644 --- a/src/main/java/mk/ukim/finki/konsultacii/service/implementation/ConsultationServiceImpl.java +++ b/src/main/java/mk/ukim/finki/konsultacii/service/implementation/ConsultationServiceImpl.java @@ -68,7 +68,7 @@ public class ConsultationServiceImpl implements ConsultationService { Specification<Consultation> spec = Specification .where(filterEquals(Consultation.class, "professor.id", id)); - if (type != null && !type.isEmpty() && !type.equals("ALL")) { + if (type != null && !type.isEmpty()) { spec = spec.and(filterEquals(Consultation.class, "type", ConsultationType.valueOf(type))); } @@ -89,7 +89,7 @@ public class ConsultationServiceImpl implements ConsultationService { .toList(); List<Consultation> sortedConsultations = new ArrayList<>(); - if (time == null || time.isEmpty() || time.equals("ALL")) { + if (time == null || time.isEmpty()) { sortedConsultations.addAll(upcomingConsultations); sortedConsultations.addAll(pastConsultations); } else if (time.equals("UPCOMING")) { diff --git a/src/main/java/mk/ukim/finki/konsultacii/web/controllers/ConsultationAttendancesController.java b/src/main/java/mk/ukim/finki/konsultacii/web/controllers/ConsultationAttendancesController.java index ab7bb85c2ab42df97fe5be66585e3200a09d67da..85da7d2b3e732bfa7f131724f805db9cfb4b8798 100644 --- a/src/main/java/mk/ukim/finki/konsultacii/web/controllers/ConsultationAttendancesController.java +++ b/src/main/java/mk/ukim/finki/konsultacii/web/controllers/ConsultationAttendancesController.java @@ -40,7 +40,7 @@ public class ConsultationAttendancesController { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); String studentUsername = authentication.getName(); - List<ConsultationAttendance> attendances = consultationAttendanceService.listAttendancesForCurrentStudent(studentUsername, time, type); + List<ConsultationAttendance> attendances = consultationAttendanceService.listAttendances(time, type, "", studentUsername); model.addAttribute("attendances", attendances); model.addAttribute("username", studentUsername); @@ -69,7 +69,7 @@ public class ConsultationAttendancesController { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); String professorUsername = authentication.getName(); - List<ConsultationAttendance> attendances = consultationAttendanceService.listAttendancesForCurrentProfessor(professorUsername, time, type, studentIndex); + List<ConsultationAttendance> attendances = consultationAttendanceService.listAttendances(time, type, professorUsername, studentIndex); model.addAttribute("attendances", attendances); model.addAttribute("professorUsername", professorUsername); @@ -99,7 +99,7 @@ public class ConsultationAttendancesController { @RequestParam(required = true) String time, @RequestParam(required = false) String professorId, @RequestParam(required = false) String studentIndex) { - List<ConsultationAttendance> attendances = consultationAttendanceService.listAllAttendances(time, type, professorId, studentIndex); + List<ConsultationAttendance> attendances = consultationAttendanceService.listAttendances(time, type, professorId, studentIndex); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); String username = authentication.getName(); diff --git a/src/main/java/mk/ukim/finki/konsultacii/web/controllers/ConsultationsController.java b/src/main/java/mk/ukim/finki/konsultacii/web/controllers/ConsultationsController.java index eadd2412b1dca2dcb956cd6c7c75d07defb7872b..29cb215ac2a5d600338640e67a98be9759f25a78 100644 --- a/src/main/java/mk/ukim/finki/konsultacii/web/controllers/ConsultationsController.java +++ b/src/main/java/mk/ukim/finki/konsultacii/web/controllers/ConsultationsController.java @@ -59,7 +59,7 @@ public class ConsultationsController { List<ConsultationAttendance> attendances = Collections.emptyList(); if(authentication.getAuthorities().stream().anyMatch(auth -> auth.getAuthority().equals("ROLE_STUDENT"))){ attendances = consultationAttendanceService - .listAttendancesForCurrentStudent(studentUsername, time, type); + .listAttendances(time, type, "", studentUsername); } boolean isAuthenticated = !authentication.getPrincipal().equals("anonymousUser"); String username = ""; diff --git a/src/main/resources/templates/bookedConsultations.html b/src/main/resources/templates/bookedConsultations.html index 04ce816df2748f87354ba562fb5f47a0b7c8287a..35cee6df67f3f0a90dd5473527359f6c2402f6be 100644 --- a/src/main/resources/templates/bookedConsultations.html +++ b/src/main/resources/templates/bookedConsultations.html @@ -14,7 +14,6 @@ <div class="col-md-4"> <select class="form-control select2" name="type"> <option value="">Филтрирање по тип</option> - <option value="ALL" th:selected="${param.type!=null && 'ALL' == param.type[0]}">ALL</option> <option value="WEEKLY" th:selected="${param.type!=null && 'WEEKLY' == param.type[0]}">WEEKLY </option> <option value="ONE_TIME" th:selected="${param.type!=null && 'ONE_TIME' == param.type[0]}">ONE @@ -26,7 +25,6 @@ <div class="col-md-4"> <select class="form-control select2" name="time"> <option value="">Филтрирање по време</option> - <option value="ALL" th:selected="${param.time!=null && 'ALL' == param.time[0]}">ALL</option> <option value="PAST" th:selected="${param.time!=null && 'PAST' == param.time[0]}">PAST</option> <option value="UPCOMING" th:selected="${param.time!=null && 'UPCOMING' == param.time[0]}"> UPCOMING @@ -72,7 +70,6 @@ <div class="col-md-4"> <select class="form-control select2" name="type"> <option value="">Филтрирање по тип</option> - <option value="ALL" th:selected="${param.type!=null && 'ALL' == param.type[0]}">ALL</option> <option value="WEEKLY" th:selected="${param.type!=null && 'WEEKLY' == param.type[0]}">WEEKLY </option> <option value="ONE_TIME" th:selected="${param.type!=null && 'ONE_TIME' == param.type[0]}">ONE @@ -84,7 +81,6 @@ <div class="col-md-4"> <select class="form-control select2" name="time"> <option value="">Филтрирање по време</option> - <option value="ALL" th:selected="${param.time!=null && 'ALL' == param.time[0]}">ALL</option> <option value="PAST" th:selected="${param.time!=null && 'PAST' == param.time[0]}">PAST</option> <option value="UPCOMING" th:selected="${param.time!=null && 'UPCOMING' == param.time[0]}"> UPCOMING diff --git a/src/main/resources/templates/bookedConsultations/adminBookedConsultations.html b/src/main/resources/templates/bookedConsultations/adminBookedConsultations.html index 2abb6ee57900edbada40306ecb16791fb9cb24d7..d116e68b39b900c0892d926ce082c4301861d1c0 100644 --- a/src/main/resources/templates/bookedConsultations/adminBookedConsultations.html +++ b/src/main/resources/templates/bookedConsultations/adminBookedConsultations.html @@ -18,7 +18,6 @@ <div class="col-md-2"> <select class="form-control select2" name="type"> <option value="">Филтрирање по тип</option> - <option value="ALL" th:selected="${param.type!=null && 'ALL' == param.type[0]}">ALL</option> <option value="WEEKLY" th:selected="${param.type!=null && 'WEEKLY' == param.type[0]}">WEEKLY </option> <option value="ONE_TIME" th:selected="${param.type!=null && 'ONE_TIME' == param.type[0]}">ONE @@ -30,7 +29,6 @@ <div class="col-md-2"> <select class="form-control select2" name="time"> <option value="">Филтрирање по време</option> - <option value="ALL" th:selected="${param.time!=null && 'ALL' == param.time[0]}">ALL</option> <option value="PAST" th:selected="${param.time!=null && 'PAST' == param.time[0]}">PAST</option> <option value="UPCOMING" th:selected="${param.time!=null && 'UPCOMING' == param.time[0]}"> UPCOMING diff --git a/src/main/resources/templates/bookedConsultations/professorBookedConsultations.html b/src/main/resources/templates/bookedConsultations/professorBookedConsultations.html index b5c1c3d4438e1730ff9bb1a75d469f0f920298b2..2a551a0536cccd9c3f575127becf00deedb15c1f 100644 --- a/src/main/resources/templates/bookedConsultations/professorBookedConsultations.html +++ b/src/main/resources/templates/bookedConsultations/professorBookedConsultations.html @@ -18,7 +18,6 @@ <div class="col-md-3"> <select class="form-control select2" name="type"> <option value="">Филтрирање по тип</option> - <option value="ALL" th:selected="${param.type!=null && 'ALL' == param.type[0]}">ALL</option> <option value="WEEKLY" th:selected="${param.type!=null && 'WEEKLY' == param.type[0]}">WEEKLY </option> <option value="ONE_TIME" th:selected="${param.type!=null && 'ONE_TIME' == param.type[0]}">ONE @@ -30,7 +29,6 @@ <div class="col-md-3"> <select class="form-control select2" name="time"> <option value="">Филтрирање по време</option> - <option value="ALL" th:selected="${param.time!=null && 'ALL' == param.time[0]}">ALL</option> <option value="PAST" th:selected="${param.time!=null && 'PAST' == param.time[0]}">PAST</option> <option value="UPCOMING" th:selected="${param.time!=null && 'UPCOMING' == param.time[0]}"> UPCOMING diff --git a/src/main/resources/templates/bookedConsultations/studentBookedConsultations.html b/src/main/resources/templates/bookedConsultations/studentBookedConsultations.html index 7a852176a85962472de1679f13c9895e1940a732..54acb3179f17e9febe37f5acdc0e57aa3938d44d 100644 --- a/src/main/resources/templates/bookedConsultations/studentBookedConsultations.html +++ b/src/main/resources/templates/bookedConsultations/studentBookedConsultations.html @@ -18,7 +18,6 @@ <div class="col-md-3"> <select class="form-control select2" name="type"> <option value="">Филтрирање по тип</option> - <option value="ALL" th:selected="${param.type!=null && 'ALL' == param.type[0]}">ALL</option> <option value="WEEKLY" th:selected="${param.type!=null && 'WEEKLY' == param.type[0]}">WEEKLY </option> <option value="ONE_TIME" th:selected="${param.type!=null && 'ONE_TIME' == param.type[0]}">ONE @@ -30,7 +29,6 @@ <div class="col-md-3"> <select class="form-control select2" name="time"> <option value="">Филтрирање по време</option> - <option value="ALL" th:selected="${param.time!=null && 'ALL' == param.time[0]}">ALL</option> <option value="PAST" th:selected="${param.time!=null && 'PAST' == param.time[0]}">PAST</option> <option value="UPCOMING" th:selected="${param.time!=null && 'UPCOMING' == param.time[0]}"> UPCOMING diff --git a/src/main/resources/templates/manageConsultations/manageConsultations.html b/src/main/resources/templates/manageConsultations/manageConsultations.html index e4473392c68ead56e1746eadb76ef00712a2f057..57e8b8cfa2dba0a395e11b7c0e211249bc0fb7b4 100644 --- a/src/main/resources/templates/manageConsultations/manageConsultations.html +++ b/src/main/resources/templates/manageConsultations/manageConsultations.html @@ -135,7 +135,6 @@ <div class="col-md-4"> <select class="form-control select2" name="type"> <option value="">Филтрирање по тип</option> - <option value="ALL" th:selected="${param.type!=null && 'ALL' == param.type[0]}">ALL</option> <option value="WEEKLY" th:selected="${param.type!=null && 'WEEKLY' == param.type[0]}">WEEKLY </option> <option value="ONE_TIME" th:selected="${param.type!=null && 'ONE_TIME' == param.type[0]}">ONE @@ -147,7 +146,6 @@ <div class="col-md-4"> <select class="form-control select2" name="time"> <option value="">Филтрирање по време</option> - <option value="ALL" th:selected="${param.time!=null && 'ALL' == param.time[0]}">ALL</option> <option value="PAST" th:selected="${param.time!=null && 'PAST' == param.time[0]}">PAST</option> <option value="UPCOMING" th:selected="${param.time!=null && 'UPCOMING' == param.time[0]}"> UPCOMING