From 5342291841c13283011fb13c03a3826a628a1d78 Mon Sep 17 00:00:00 2001 From: Agit Rubar Demir <61833677+agitrubard@users.noreply.github.com> Date: Thu, 17 Feb 2022 13:45:25 +0300 Subject: [PATCH 01/13] ModifiedDate Has Been Fixed in OfficerPersonalInfoConverter/entityToResponse Method (#54) --- .../model/dto/converter/OfficerPersonalInfoConverter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/officer/model/dto/converter/OfficerPersonalInfoConverter.java b/src/main/java/com/graduationproject/studentinformationsystem/university/officer/model/dto/converter/OfficerPersonalInfoConverter.java index 660bcce4..459d7f50 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/officer/model/dto/converter/OfficerPersonalInfoConverter.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/officer/model/dto/converter/OfficerPersonalInfoConverter.java @@ -98,7 +98,7 @@ public static OfficerPersonalInfoResponse entityToResponse(OfficerPersonalInfoEn .createdUserId(personalInfoEntity.getCreatedUserId()) .createdDate(SisUtil.getFormattedDateTime(personalInfoEntity.getCreatedDate())) .modifiedUserId(personalInfoEntity.getModifiedUserId()) - .modifiedDate(SisUtil.getFormattedDateTime(personalInfoEntity.getCreatedDate())).build(); + .modifiedDate(SisUtil.getFormattedDateTime(personalInfoEntity.getModifiedDate())).build(); } public static List entitiesToResponses(List personalInfoEntities) { From 12324ec9972da210cc88d7ea16d86e7480828358 Mon Sep 17 00:00:00 2001 From: Agit Rubar Demir <61833677+agitrubard@users.noreply.github.com> Date: Thu, 17 Feb 2022 13:45:33 +0300 Subject: [PATCH 02/13] Teacher GET APIs Responses Have Been Updated with Teacher Academic Info Response (#55) --- .../controller/TeacherLessonController.java | 4 ++-- .../TeacherLessonControllerEndpoint.java | 1 + .../converter/TeacherLessonInfoConverter.java | 3 ++- .../dto/response/TeacherLessonResponse.java | 3 ++- .../model/entity/TeacherLessonEntity.java | 4 ++++ .../impl/TeacherLessonServiceImpl.java | 24 +++++++++++++++++++ 6 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/controller/TeacherLessonController.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/controller/TeacherLessonController.java index 00b35481..bf3fc502 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/controller/TeacherLessonController.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/controller/TeacherLessonController.java @@ -38,10 +38,10 @@ public ResponseEntity>> getAllTea return successResponse(lessonResponses); } - @GetMapping(TeacherLessonControllerEndpoint.TEACHER_ID) + @GetMapping(TeacherLessonControllerEndpoint.GET) @ApiOperation(value = "Get Teacher All Lessons By Teacher ID") public ResponseEntity>> getTeacherLessonsById( - @PathVariable final Long teacherId) { + @RequestParam final Long teacherId) { final List lessonResponses = lessonService.getTeacherLessonsById(teacherId); return successResponse(lessonResponses); diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/controller/endpoint/TeacherLessonControllerEndpoint.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/controller/endpoint/TeacherLessonControllerEndpoint.java index 723272f8..6bcd5b9c 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/controller/endpoint/TeacherLessonControllerEndpoint.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/controller/endpoint/TeacherLessonControllerEndpoint.java @@ -6,6 +6,7 @@ private TeacherLessonControllerEndpoint() { } public static final String TEACHER_ID = "/{teacherId}"; + public static final String GET = "/get"; public static final String SAVE = "/save"; public static final String DELETE = "/delete"; } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/model/dto/converter/TeacherLessonInfoConverter.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/model/dto/converter/TeacherLessonInfoConverter.java index 159fb354..76d9cc65 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/model/dto/converter/TeacherLessonInfoConverter.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/model/dto/converter/TeacherLessonInfoConverter.java @@ -10,6 +10,7 @@ import com.graduationproject.studentinformationsystem.university.lesson.teacher.model.entity.TeacherLessonDeleteEntity; import com.graduationproject.studentinformationsystem.university.lesson.teacher.model.entity.TeacherLessonEntity; import com.graduationproject.studentinformationsystem.university.lesson.teacher.model.entity.TeacherLessonSaveEntity; +import com.graduationproject.studentinformationsystem.university.teacher.model.dto.converter.TeacherAcademicInfoConverter; import java.util.ArrayList; import java.util.Date; @@ -44,9 +45,9 @@ public static TeacherLessonDeleteEntity generateDeleteEntity(final TeacherLesson public static TeacherLessonResponse entityToResponse(final TeacherLessonEntity teacherLessonEntity) { return TeacherLessonResponse.builder() - .teacherId(teacherLessonEntity.getTeacherId()) .createdUserId(teacherLessonEntity.getCreatedUserId()) .createdDate(SisUtil.getFormattedDateTime(teacherLessonEntity.getCreatedDate())) + .teacherAcademicInfoResponse(TeacherAcademicInfoConverter.entityToResponse(teacherLessonEntity.getTeacherAcademicInfoEntity())) .lessonResponse(LessonInfoConverter.entityToResponse(teacherLessonEntity.getLessonEntity())).build(); } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/model/dto/response/TeacherLessonResponse.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/model/dto/response/TeacherLessonResponse.java index 4f5c6653..7ef1f65d 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/model/dto/response/TeacherLessonResponse.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/model/dto/response/TeacherLessonResponse.java @@ -1,6 +1,7 @@ package com.graduationproject.studentinformationsystem.university.lesson.teacher.model.dto.response; import com.graduationproject.studentinformationsystem.university.lesson.common.model.dto.response.LessonResponse; +import com.graduationproject.studentinformationsystem.university.teacher.model.dto.response.TeacherAcademicInfoResponse; import lombok.Getter; import lombok.experimental.SuperBuilder; @@ -8,9 +9,9 @@ @SuperBuilder public class TeacherLessonResponse { - private Long teacherId; private Long createdUserId; private String createdDate; private LessonResponse lessonResponse; + private TeacherAcademicInfoResponse teacherAcademicInfoResponse; } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/model/entity/TeacherLessonEntity.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/model/entity/TeacherLessonEntity.java index 73f023b8..649207f3 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/model/entity/TeacherLessonEntity.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/model/entity/TeacherLessonEntity.java @@ -1,6 +1,7 @@ package com.graduationproject.studentinformationsystem.university.lesson.teacher.model.entity; import com.graduationproject.studentinformationsystem.university.lesson.common.model.entity.LessonEntity; +import com.graduationproject.studentinformationsystem.university.teacher.model.entity.TeacherAcademicInfoEntity; import lombok.Builder; import lombok.Getter; import lombok.Setter; @@ -18,4 +19,7 @@ public class TeacherLessonEntity { @Setter private LessonEntity lessonEntity; + + @Setter + private TeacherAcademicInfoEntity teacherAcademicInfoEntity; } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/service/impl/TeacherLessonServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/service/impl/TeacherLessonServiceImpl.java index 31519ad5..cb586026 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/service/impl/TeacherLessonServiceImpl.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/service/impl/TeacherLessonServiceImpl.java @@ -19,6 +19,8 @@ import com.graduationproject.studentinformationsystem.university.lesson.teacher.model.exception.TeacherLessonException; import com.graduationproject.studentinformationsystem.university.lesson.teacher.repository.TeacherLessonRepository; import com.graduationproject.studentinformationsystem.university.lesson.teacher.service.TeacherLessonService; +import com.graduationproject.studentinformationsystem.university.teacher.model.entity.TeacherAcademicInfoEntity; +import com.graduationproject.studentinformationsystem.university.teacher.repository.TeacherAcademicInfoRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -32,6 +34,7 @@ public class TeacherLessonServiceImpl implements TeacherLessonService { private final FacultyRepository facultyRepository; private final DepartmentRepository departmentRepository; private final LessonRepository lessonRepository; + private final TeacherAcademicInfoRepository teacherAcademicInfoRepository; private final TeacherLessonRepository teacherLessonRepository; @@ -39,6 +42,7 @@ public class TeacherLessonServiceImpl implements TeacherLessonService { public List getAllTeachersLessons() { final List teacherLessonEntities = teacherLessonRepository.getAllTeachersLessons(); setLessonEntities(teacherLessonEntities); + setTeacherAcademicInfoEntities(teacherLessonEntities); return TeacherLessonInfoConverter.entitiesToResponses(teacherLessonEntities); } @@ -46,6 +50,7 @@ public List getAllTeachersLessons() { public List getTeacherLessonsById(final Long teacherId) { final List teacherLessonEntities = teacherLessonRepository.getTeacherLessonsByTeacherId(teacherId); setLessonEntities(teacherLessonEntities); + setTeacherAcademicInfoEntities(teacherLessonEntities); return TeacherLessonInfoConverter.entitiesToResponses(teacherLessonEntities); } @@ -69,10 +74,22 @@ public void deleteTeacherLesson(final TeacherLessonDeleteRequest deleteRequest) private TeacherLessonResponse getTeacherLessonResponse(final Long teacherId, final Long lessonId) { final TeacherLessonEntity teacherLessonEntity = teacherLessonRepository.getTeacherLessonByTeacherIdAndLessonId(teacherId, lessonId); + setTeacherAcademicInfoEntity(teacherLessonEntity); setLessonEntity(teacherLessonEntity); return TeacherLessonInfoConverter.entityToResponse(teacherLessonEntity); } + private void setTeacherAcademicInfoEntity(final TeacherLessonEntity teacherLessonEntity) { + final Long teacherId = teacherLessonEntity.getTeacherId(); + final TeacherAcademicInfoEntity teacherAcademicInfoEntity = teacherAcademicInfoRepository.getTeacherAcademicInfoById(teacherId); + setDepartmentEntity(teacherAcademicInfoEntity); + teacherLessonEntity.setTeacherAcademicInfoEntity(teacherAcademicInfoEntity); + } + + private void setTeacherAcademicInfoEntities(List teacherLessonEntities) { + teacherLessonEntities.forEach(this::setTeacherAcademicInfoEntity); + } + private void setLessonEntity(final TeacherLessonEntity teacherLessonEntity) { final Long lessonId = teacherLessonEntity.getLessonId(); final LessonEntity lessonEntity = lessonRepository.getLessonById(lessonId); @@ -84,6 +101,13 @@ private void setLessonEntities(final List teacherLessonEnti teacherLessonEntities.forEach(this::setLessonEntity); } + private void setDepartmentEntity(final TeacherAcademicInfoEntity teacherAcademicInfoEntity) { + final Long departmentId = teacherAcademicInfoEntity.getDepartmentId(); + final DepartmentEntity departmentEntity = departmentRepository.getDepartmentById(departmentId); + setFacultyEntity(departmentEntity); + teacherAcademicInfoEntity.setDepartmentEntity(departmentEntity); + } + private void setDepartmentEntity(final LessonEntity lessonEntity) { final Long departmentId = lessonEntity.getDepartmentId(); final DepartmentEntity departmentEntity = departmentRepository.getDepartmentById(departmentId); From 0e5413c29e2a89d9d1796bb78f5eda1a7f8b6ffd Mon Sep 17 00:00:00 2001 From: Agit Rubar Demir <61833677+agitrubard@users.noreply.github.com> Date: Fri, 18 Feb 2022 07:52:53 +0300 Subject: [PATCH 03/13] Service Refactores | SIS-108 (#56) * FacultyOutService Classes Have Been Created * FacultyServiceImpl and FacultyInfoConverter Classes Have Been Refactored * DepartmentOutService Classes Have Been Created * DepartmentInfoConverter and DepartmentEntity Classes Have Been Refactored * DepartmentServiceImpl Class Has Been Refactored * LessonOutService Classes Have Been Created * LessonServiceImpl and LessonInfoConverter Classes Have Been Refactored * OfficerAcademicInfoConverter and OfficerResponseConverter Classes Have Been Refactored * OfficerServiceImpl and OfficerAcademicInfoServiceImpl Classes Have Been Refactored * ScheduleFileEntity and ExamScheduleFileInfoConverter Classes Have Been Refactored * ExamScheduleFileServiceImpl Class Has Been Refactored * LessonScheduleFileInfoConverter Class Has Been Refactored * LessonScheduleFileServiceImpl Class Has Been Refactored * StudentResponseConverter and StudentAcademicInfoConverter Classes Have Been Refactored * StudentServiceImpl and StudentAcademicInfoServiceImpl Classes Have Been Refactored * TeacherAcademicInfoConverter, TeacherServiceImpl and TeacherAcademicInfoServiceImpl Classes Have Been Refactored * TeacherOutService Classes Have Been Created * TeacherLessonInfoConverter and TeacherLessonServiceImpl Classes Have Been Refactored --- .../converter/DepartmentInfoConverter.java | 33 +++--- .../model/entity/DepartmentEntity.java | 5 - .../service/DepartmentOutService.java | 11 ++ .../impl/DepartmentOutServiceImpl.java | 32 ++++++ .../service/impl/DepartmentServiceImpl.java | 41 +++---- .../dto/converter/FacultyInfoConverter.java | 23 ++-- .../faculty/service/FacultyOutService.java | 11 ++ .../service/impl/FacultyOutServiceImpl.java | 32 ++++++ .../service/impl/FacultyServiceImpl.java | 15 +-- .../dto/converter/LessonInfoConverter.java | 33 +++--- .../common/model/entity/LessonEntity.java | 5 - .../common/service/LessonOutService.java | 11 ++ .../service/impl/LessonOutServiceImpl.java | 32 ++++++ .../service/impl/LessonServiceImpl.java | 48 ++------- .../converter/TeacherLessonInfoConverter.java | 29 +++-- .../model/entity/TeacherLessonEntity.java | 9 -- .../impl/TeacherLessonServiceImpl.java | 102 +++++------------- .../OfficerAcademicInfoConverter.java | 40 ++++--- .../converter/OfficerResponseConverter.java | 4 +- .../entity/OfficerAcademicInfoEntity.java | 5 - .../impl/OfficerAcademicInfoServiceImpl.java | 31 ++---- .../service/impl/OfficerServiceImpl.java | 8 +- .../model/entity/ScheduleFileEntity.java | 5 - .../ExamScheduleFileInfoConverter.java | 33 +++--- .../impl/ExamScheduleFileServiceImpl.java | 48 ++------- .../LessonScheduleFileInfoConverter.java | 33 +++--- .../impl/LessonScheduleFileServiceImpl.java | 52 +++------ .../StudentAcademicInfoConverter.java | 42 +++++--- .../converter/StudentResponseConverter.java | 5 +- .../entity/StudentAcademicInfoEntity.java | 5 - .../impl/StudentAcademicInfoServiceImpl.java | 46 +++----- .../service/impl/StudentServiceImpl.java | 19 ++-- .../TeacherAcademicInfoConverter.java | 40 ++++--- .../entity/TeacherAcademicInfoEntity.java | 5 - .../teacher/service/TeacherOutService.java | 8 ++ .../impl/TeacherAcademicInfoServiceImpl.java | 41 ++----- .../service/impl/TeacherOutServiceImpl.java | 23 ++++ .../service/impl/TeacherServiceImpl.java | 8 +- 38 files changed, 475 insertions(+), 498 deletions(-) create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/department/service/DepartmentOutService.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/department/service/impl/DepartmentOutServiceImpl.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/faculty/service/FacultyOutService.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/faculty/service/impl/FacultyOutServiceImpl.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/common/service/LessonOutService.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/common/service/impl/LessonOutServiceImpl.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/TeacherOutService.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/impl/TeacherOutServiceImpl.java diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/department/model/dto/converter/DepartmentInfoConverter.java b/src/main/java/com/graduationproject/studentinformationsystem/university/department/model/dto/converter/DepartmentInfoConverter.java index 226e9e93..5a20dbd6 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/department/model/dto/converter/DepartmentInfoConverter.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/department/model/dto/converter/DepartmentInfoConverter.java @@ -6,19 +6,23 @@ import com.graduationproject.studentinformationsystem.university.department.model.dto.response.DepartmentResponse; import com.graduationproject.studentinformationsystem.university.department.model.entity.DepartmentEntity; import com.graduationproject.studentinformationsystem.university.department.model.enums.DepartmentStatus; -import com.graduationproject.studentinformationsystem.university.faculty.model.dto.converter.FacultyInfoConverter; +import com.graduationproject.studentinformationsystem.university.faculty.model.dto.response.FacultyResponse; +import com.graduationproject.studentinformationsystem.university.faculty.service.FacultyOutService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.Date; import java.util.List; +@Component +@RequiredArgsConstructor public class DepartmentInfoConverter { - private DepartmentInfoConverter() { - } + private final FacultyOutService facultyOutService; - public static DepartmentEntity generateSaveEntity(final Long departmentId, - final DepartmentSaveRequest saveRequest) { + public DepartmentEntity generateSaveEntity(final Long departmentId, + final DepartmentSaveRequest saveRequest) { final DepartmentInfoRequest departmentInfoRequest = saveRequest.getDepartmentInfoRequest(); final SisOperationInfoRequest operationInfoRequest = saveRequest.getOperationInfoRequest(); @@ -35,8 +39,8 @@ public static DepartmentEntity generateSaveEntity(final Long departmentId, .build(); } - public static DepartmentEntity generateUpdateEntity(final Long departmentId, - final DepartmentUpdateRequest updateRequest) { + public DepartmentEntity generateUpdateEntity(final Long departmentId, + final DepartmentUpdateRequest updateRequest) { final DepartmentInfoRequest departmentInfoRequest = updateRequest.getDepartmentInfoRequest(); final SisOperationInfoRequest operationInfoRequest = updateRequest.getOperationInfoRequest(); @@ -53,7 +57,7 @@ public static DepartmentEntity generateUpdateEntity(final Long departmentId, .build(); } - public static DepartmentEntity generateDeleteEntity(final DepartmentDeleteRequest deleteRequest) { + public DepartmentEntity generateDeleteEntity(final DepartmentDeleteRequest deleteRequest) { return DepartmentEntity.builder() .departmentId(deleteRequest.getDepartmentId()) .status(DepartmentStatus.DELETED) @@ -62,7 +66,7 @@ public static DepartmentEntity generateDeleteEntity(final DepartmentDeleteReques .build(); } - public static DepartmentEntity generatePassiveEntity(final DepartmentPassivateRequest passivateRequest) { + public DepartmentEntity generatePassiveEntity(final DepartmentPassivateRequest passivateRequest) { return DepartmentEntity.builder() .departmentId(passivateRequest.getDepartmentId()) .status(DepartmentStatus.PASSIVE) @@ -71,7 +75,7 @@ public static DepartmentEntity generatePassiveEntity(final DepartmentPassivateRe .build(); } - public static DepartmentEntity generateActiveEntity(final DepartmentActivateRequest activateRequest) { + public DepartmentEntity generateActiveEntity(final DepartmentActivateRequest activateRequest) { return DepartmentEntity.builder() .departmentId(activateRequest.getDepartmentId()) .status(DepartmentStatus.ACTIVE) @@ -80,10 +84,12 @@ public static DepartmentEntity generateActiveEntity(final DepartmentActivateRequ .build(); } - public static DepartmentResponse entityToResponse(final DepartmentEntity departmentEntity) { + public DepartmentResponse entityToResponse(final DepartmentEntity departmentEntity) { + + final FacultyResponse facultyResponse = facultyOutService.getFacultyResponse(departmentEntity.getFacultyId()); + return DepartmentResponse.builder() .departmentId(departmentEntity.getDepartmentId()) - .facultyResponse(FacultyInfoConverter.entityToResponse(departmentEntity.getFacultyEntity())) .name(departmentEntity.getName()) .status(departmentEntity.getStatus()) .totalClassLevel(departmentEntity.getTotalClassLevel()) @@ -92,10 +98,11 @@ public static DepartmentResponse entityToResponse(final DepartmentEntity departm .createdDate(SisUtil.getFormattedDateTime(departmentEntity.getCreatedDate())) .modifiedUserId(departmentEntity.getModifiedUserId()) .modifiedDate(SisUtil.getFormattedDateTime(departmentEntity.getModifiedDate())) + .facultyResponse(facultyResponse) .build(); } - public static List entitiesToResponses(final List departmentEntities) { + public List entitiesToResponses(final List departmentEntities) { List departmentResponses = new ArrayList<>(); departmentEntities.forEach(departmentEntity -> departmentResponses.add(entityToResponse(departmentEntity))); return departmentResponses; diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/department/model/entity/DepartmentEntity.java b/src/main/java/com/graduationproject/studentinformationsystem/university/department/model/entity/DepartmentEntity.java index e2ec65ed..1ebcbd37 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/department/model/entity/DepartmentEntity.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/department/model/entity/DepartmentEntity.java @@ -2,9 +2,7 @@ import com.graduationproject.studentinformationsystem.common.model.entity.SisBaseEntity; import com.graduationproject.studentinformationsystem.university.department.model.enums.DepartmentStatus; -import com.graduationproject.studentinformationsystem.university.faculty.model.entity.FacultyEntity; import lombok.Getter; -import lombok.Setter; import lombok.experimental.SuperBuilder; @Getter @@ -17,7 +15,4 @@ public class DepartmentEntity extends SisBaseEntity { private DepartmentStatus status; private Integer totalClassLevel; private Boolean isTherePreparatoryClass; - - @Setter - private FacultyEntity facultyEntity; } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/department/service/DepartmentOutService.java b/src/main/java/com/graduationproject/studentinformationsystem/university/department/service/DepartmentOutService.java new file mode 100644 index 00000000..47c463d3 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/department/service/DepartmentOutService.java @@ -0,0 +1,11 @@ +package com.graduationproject.studentinformationsystem.university.department.service; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.university.department.model.dto.response.DepartmentResponse; + +public interface DepartmentOutService { + + DepartmentResponse getDepartmentResponse(Long departmentId); + + void ifDepartmentIsNotExistThrowNotExistException(Long departmentId) throws SisNotExistException; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/department/service/impl/DepartmentOutServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/department/service/impl/DepartmentOutServiceImpl.java new file mode 100644 index 00000000..bbe4c881 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/department/service/impl/DepartmentOutServiceImpl.java @@ -0,0 +1,32 @@ +package com.graduationproject.studentinformationsystem.university.department.service.impl; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.university.department.model.dto.converter.DepartmentInfoConverter; +import com.graduationproject.studentinformationsystem.university.department.model.dto.response.DepartmentResponse; +import com.graduationproject.studentinformationsystem.university.department.model.entity.DepartmentEntity; +import com.graduationproject.studentinformationsystem.university.department.model.exception.DepartmentException; +import com.graduationproject.studentinformationsystem.university.department.repository.DepartmentRepository; +import com.graduationproject.studentinformationsystem.university.department.service.DepartmentOutService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class DepartmentOutServiceImpl implements DepartmentOutService { + + private final DepartmentRepository departmentRepository; + private final DepartmentInfoConverter departmentInfoConverter; + + @Override + public DepartmentResponse getDepartmentResponse(Long departmentId) { + final DepartmentEntity departmentEntity = departmentRepository.getDepartmentById(departmentId); + return departmentInfoConverter.entityToResponse(departmentEntity); + } + + @Override + public void ifDepartmentIsNotExistThrowNotExistException(Long departmentId) throws SisNotExistException { + if (!departmentRepository.isDepartmentExist(departmentId)) { + DepartmentException.throwNotExistException(departmentId); + } + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/department/service/impl/DepartmentServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/department/service/impl/DepartmentServiceImpl.java index e913e0d8..95d90a47 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/department/service/impl/DepartmentServiceImpl.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/department/service/impl/DepartmentServiceImpl.java @@ -11,9 +11,7 @@ import com.graduationproject.studentinformationsystem.university.department.repository.DepartmentRepository; import com.graduationproject.studentinformationsystem.university.department.service.DepartmentService; import com.graduationproject.studentinformationsystem.university.department.util.DepartmentUtil; -import com.graduationproject.studentinformationsystem.university.faculty.model.entity.FacultyEntity; -import com.graduationproject.studentinformationsystem.university.faculty.model.exception.FacultyException; -import com.graduationproject.studentinformationsystem.university.faculty.repository.FacultyRepository; +import com.graduationproject.studentinformationsystem.university.faculty.service.FacultyOutService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -23,15 +21,15 @@ @RequiredArgsConstructor public class DepartmentServiceImpl implements DepartmentService { - private final FacultyRepository facultyRepository; + private final FacultyOutService facultyOutService; private final DepartmentRepository departmentRepository; + private final DepartmentInfoConverter departmentInfoConverter; @Override public List getAllDepartmentsByStatus(final DepartmentStatus status) { final List departmentEntities = departmentRepository.getAllDepartmentsByStatus(status); - setFacultyEntities(departmentEntities); - return DepartmentInfoConverter.entitiesToResponses(departmentEntities); + return departmentInfoConverter.entitiesToResponses(departmentEntities); } @Override @@ -48,7 +46,7 @@ public DepartmentResponse saveDepartment(final DepartmentSaveRequest saveRequest checkBeforeSaving(facultyId); final Long departmentId = generateDepartmentId(facultyId); - final DepartmentEntity departmentEntity = DepartmentInfoConverter.generateSaveEntity(departmentId, saveRequest); + final DepartmentEntity departmentEntity = departmentInfoConverter.generateSaveEntity(departmentId, saveRequest); departmentRepository.saveDepartment(departmentEntity); @@ -62,7 +60,7 @@ public DepartmentResponse updateDepartment(final Long departmentId, final Depart final Long facultyId = updateRequest.getDepartmentInfoRequest().getFacultyId(); checkBeforeUpdating(departmentId, facultyId); - final DepartmentEntity departmentEntity = DepartmentInfoConverter.generateUpdateEntity(departmentId, updateRequest); + final DepartmentEntity departmentEntity = departmentInfoConverter.generateUpdateEntity(departmentId, updateRequest); departmentRepository.updateDepartment(departmentEntity); return getDepartmentResponse(departmentId); @@ -74,7 +72,7 @@ public DepartmentResponse deleteDepartment(final DepartmentDeleteRequest deleteR checkBeforeDeleting(deleteRequest.getDepartmentId()); - final DepartmentEntity departmentEntity = DepartmentInfoConverter.generateDeleteEntity(deleteRequest); + final DepartmentEntity departmentEntity = departmentInfoConverter.generateDeleteEntity(deleteRequest); departmentRepository.updateDepartmentStatus(departmentEntity); return getDepartmentResponse(deleteRequest.getDepartmentId()); @@ -86,7 +84,7 @@ public DepartmentResponse passivateDepartment(final DepartmentPassivateRequest p checkBeforePassivating(passivateRequest.getDepartmentId()); - final DepartmentEntity departmentEntity = DepartmentInfoConverter.generatePassiveEntity(passivateRequest); + final DepartmentEntity departmentEntity = departmentInfoConverter.generatePassiveEntity(passivateRequest); departmentRepository.updateDepartmentStatus(departmentEntity); return getDepartmentResponse(passivateRequest.getDepartmentId()); @@ -98,7 +96,7 @@ public DepartmentResponse activateDepartment(final DepartmentActivateRequest act checkBeforeActivating(activateRequest.getDepartmentId()); - final DepartmentEntity departmentEntity = DepartmentInfoConverter.generateActiveEntity(activateRequest); + final DepartmentEntity departmentEntity = departmentInfoConverter.generateActiveEntity(activateRequest); departmentRepository.updateDepartmentStatus(departmentEntity); return getDepartmentResponse(activateRequest.getDepartmentId()); @@ -112,18 +110,7 @@ private Long generateDepartmentId(final Long facultyId) { private DepartmentResponse getDepartmentResponse(final Long departmentId) { final DepartmentEntity departmentEntity = departmentRepository.getDepartmentById(departmentId); - setFacultyEntity(departmentEntity); - return DepartmentInfoConverter.entityToResponse(departmentEntity); - } - - private void setFacultyEntity(final DepartmentEntity departmentEntity) { - final Long facultyId = departmentEntity.getFacultyId(); - final FacultyEntity facultyEntity = facultyRepository.getFacultyById(facultyId); - departmentEntity.setFacultyEntity(facultyEntity); - } - - private void setFacultyEntities(final List departmentEntities) { - departmentEntities.forEach(this::setFacultyEntity); + return departmentInfoConverter.entityToResponse(departmentEntity); } @@ -132,12 +119,10 @@ private void setFacultyEntities(final List departmentEntities) */ private void checkBeforeSaving(final Long facultyId) throws SisNotExistException { - ifFacultyIsNotExistThrowNotExistException(facultyId); } private void checkBeforeUpdating(final Long departmentId, final Long facultyId) throws SisNotExistException { - ifDepartmentIsNotExistThrowNotExistException(departmentId); ifFacultyIsNotExistThrowNotExistException(facultyId); } @@ -164,10 +149,8 @@ private void checkBeforeActivating(final Long departmentId) throws SisNotExistEx * Throw Exceptions */ - private void ifFacultyIsNotExistThrowNotExistException(final Long facultyId) throws SisNotExistException { - if (!facultyRepository.isFacultyExist(facultyId)) { - FacultyException.throwNotExistException(facultyId); - } + private void ifFacultyIsNotExistThrowNotExistException(Long facultyId) throws SisNotExistException { + facultyOutService.ifFacultyIsNotExistThrowNotExistException(facultyId); } private void ifDepartmentIsNotExistThrowNotExistException(final Long departmentId) throws SisNotExistException { diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/faculty/model/dto/converter/FacultyInfoConverter.java b/src/main/java/com/graduationproject/studentinformationsystem/university/faculty/model/dto/converter/FacultyInfoConverter.java index 8741d3b2..2257af5d 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/faculty/model/dto/converter/FacultyInfoConverter.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/faculty/model/dto/converter/FacultyInfoConverter.java @@ -6,18 +6,17 @@ import com.graduationproject.studentinformationsystem.university.faculty.model.dto.response.FacultyResponse; import com.graduationproject.studentinformationsystem.university.faculty.model.entity.FacultyEntity; import com.graduationproject.studentinformationsystem.university.faculty.model.enums.FacultyStatus; +import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.Date; import java.util.List; +@Component public class FacultyInfoConverter { - private FacultyInfoConverter() { - } - - public static FacultyEntity generateSaveEntity(final Long facultyId, - final FacultySaveRequest saveRequest) { + public FacultyEntity generateSaveEntity(final Long facultyId, + final FacultySaveRequest saveRequest) { final FacultyInfoRequest facultyInfoRequest = saveRequest.getFacultyInfoRequest(); final SisOperationInfoRequest operationInfoRequest = saveRequest.getOperationInfoRequest(); @@ -31,8 +30,8 @@ public static FacultyEntity generateSaveEntity(final Long facultyId, .build(); } - public static FacultyEntity generateUpdateEntity(final Long facultyId, - final FacultyUpdateRequest updateRequest) { + public FacultyEntity generateUpdateEntity(final Long facultyId, + final FacultyUpdateRequest updateRequest) { final FacultyInfoRequest facultyInfoRequest = updateRequest.getFacultyInfoRequest(); final SisOperationInfoRequest operationInfoRequest = updateRequest.getOperationInfoRequest(); @@ -46,7 +45,7 @@ public static FacultyEntity generateUpdateEntity(final Long facultyId, .build(); } - public static FacultyEntity generateDeleteEntity(final FacultyDeleteRequest deleteRequest) { + public FacultyEntity generateDeleteEntity(final FacultyDeleteRequest deleteRequest) { return FacultyEntity.builder() .facultyId(deleteRequest.getFacultyId()) .status(FacultyStatus.DELETED) @@ -55,7 +54,7 @@ public static FacultyEntity generateDeleteEntity(final FacultyDeleteRequest dele .build(); } - public static FacultyEntity generatePassiveEntity(final FacultyPassivateRequest passivateRequest) { + public FacultyEntity generatePassiveEntity(final FacultyPassivateRequest passivateRequest) { return FacultyEntity.builder() .facultyId(passivateRequest.getFacultyId()) .status(FacultyStatus.PASSIVE) @@ -64,7 +63,7 @@ public static FacultyEntity generatePassiveEntity(final FacultyPassivateRequest .build(); } - public static FacultyEntity generateActiveEntity(final FacultyActivateRequest activateRequest) { + public FacultyEntity generateActiveEntity(final FacultyActivateRequest activateRequest) { return FacultyEntity.builder() .facultyId(activateRequest.getFacultyId()) .status(FacultyStatus.ACTIVE) @@ -73,7 +72,7 @@ public static FacultyEntity generateActiveEntity(final FacultyActivateRequest ac .build(); } - public static FacultyResponse entityToResponse(final FacultyEntity facultyEntity) { + public FacultyResponse entityToResponse(final FacultyEntity facultyEntity) { return FacultyResponse.builder() .facultyId(facultyEntity.getFacultyId()) .name(facultyEntity.getName()) @@ -85,7 +84,7 @@ public static FacultyResponse entityToResponse(final FacultyEntity facultyEntity .build(); } - public static List entitiesToResponses(final List facultyEntities) { + public List entitiesToResponses(final List facultyEntities) { List facultyResponses = new ArrayList<>(); facultyEntities.forEach(facultyEntity -> facultyResponses.add(entityToResponse(facultyEntity))); return facultyResponses; diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/faculty/service/FacultyOutService.java b/src/main/java/com/graduationproject/studentinformationsystem/university/faculty/service/FacultyOutService.java new file mode 100644 index 00000000..b81951a0 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/faculty/service/FacultyOutService.java @@ -0,0 +1,11 @@ +package com.graduationproject.studentinformationsystem.university.faculty.service; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.university.faculty.model.dto.response.FacultyResponse; + +public interface FacultyOutService { + + FacultyResponse getFacultyResponse(Long facultyId); + + void ifFacultyIsNotExistThrowNotExistException(Long facultyId) throws SisNotExistException; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/faculty/service/impl/FacultyOutServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/faculty/service/impl/FacultyOutServiceImpl.java new file mode 100644 index 00000000..5e1e30e1 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/faculty/service/impl/FacultyOutServiceImpl.java @@ -0,0 +1,32 @@ +package com.graduationproject.studentinformationsystem.university.faculty.service.impl; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.university.faculty.model.dto.converter.FacultyInfoConverter; +import com.graduationproject.studentinformationsystem.university.faculty.model.dto.response.FacultyResponse; +import com.graduationproject.studentinformationsystem.university.faculty.model.entity.FacultyEntity; +import com.graduationproject.studentinformationsystem.university.faculty.model.exception.FacultyException; +import com.graduationproject.studentinformationsystem.university.faculty.repository.FacultyRepository; +import com.graduationproject.studentinformationsystem.university.faculty.service.FacultyOutService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class FacultyOutServiceImpl implements FacultyOutService { + + private final FacultyRepository facultyRepository; + private final FacultyInfoConverter facultyInfoConverter; + + @Override + public FacultyResponse getFacultyResponse(Long facultyId) { + final FacultyEntity facultyEntity = facultyRepository.getFacultyById(facultyId); + return facultyInfoConverter.entityToResponse(facultyEntity); + } + + @Override + public void ifFacultyIsNotExistThrowNotExistException(Long facultyId) throws SisNotExistException { + if (!facultyRepository.isFacultyExist(facultyId)) { + FacultyException.throwNotExistException(facultyId); + } + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/faculty/service/impl/FacultyServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/faculty/service/impl/FacultyServiceImpl.java index ec310534..6b172019 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/faculty/service/impl/FacultyServiceImpl.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/faculty/service/impl/FacultyServiceImpl.java @@ -21,11 +21,12 @@ public class FacultyServiceImpl implements FacultyService { private final FacultyRepository facultyRepository; + private final FacultyInfoConverter facultyInfoConverter; @Override public List getAllFacultiesByStatus(final FacultyStatus status) { final List facultyResponses = facultyRepository.getAllFacultiesByStatus(status); - return FacultyInfoConverter.entitiesToResponses(facultyResponses); + return facultyInfoConverter.entitiesToResponses(facultyResponses); } @Override @@ -38,7 +39,7 @@ public FacultyResponse getFacultyById(final Long facultyId) throws SisNotExistEx public FacultyResponse saveFaculty(final FacultySaveRequest saveRequest) { final Long facultyId = generateFacultyId(); - final FacultyEntity facultyEntity = FacultyInfoConverter.generateSaveEntity(facultyId, saveRequest); + final FacultyEntity facultyEntity = facultyInfoConverter.generateSaveEntity(facultyId, saveRequest); facultyRepository.saveFaculty(facultyEntity); @@ -51,7 +52,7 @@ public FacultyResponse updateFaculty(final Long facultyId, final FacultyUpdateRe checkBeforeUpdating(facultyId); - final FacultyEntity facultyEntity = FacultyInfoConverter.generateUpdateEntity(facultyId, updateRequest); + final FacultyEntity facultyEntity = facultyInfoConverter.generateUpdateEntity(facultyId, updateRequest); facultyRepository.updateFaculty(facultyEntity); return getFacultyResponse(facultyId); @@ -63,7 +64,7 @@ public FacultyResponse deleteFaculty(final FacultyDeleteRequest deleteRequest) checkBeforeDeleting(deleteRequest.getFacultyId()); - final FacultyEntity facultyEntity = FacultyInfoConverter.generateDeleteEntity(deleteRequest); + final FacultyEntity facultyEntity = facultyInfoConverter.generateDeleteEntity(deleteRequest); facultyRepository.updateFacultyStatus(facultyEntity); return getFacultyResponse(deleteRequest.getFacultyId()); @@ -75,7 +76,7 @@ public FacultyResponse passivateFaculty(final FacultyPassivateRequest passivateR checkBeforePassivating(passivateRequest.getFacultyId()); - final FacultyEntity facultyEntity = FacultyInfoConverter.generatePassiveEntity(passivateRequest); + final FacultyEntity facultyEntity = facultyInfoConverter.generatePassiveEntity(passivateRequest); facultyRepository.updateFacultyStatus(facultyEntity); return getFacultyResponse(passivateRequest.getFacultyId()); @@ -87,7 +88,7 @@ public FacultyResponse activateFaculty(final FacultyActivateRequest activateRequ checkBeforeActivating(activateRequest.getFacultyId()); - final FacultyEntity facultyEntity = FacultyInfoConverter.generateActiveEntity(activateRequest); + final FacultyEntity facultyEntity = facultyInfoConverter.generateActiveEntity(activateRequest); facultyRepository.updateFacultyStatus(facultyEntity); return getFacultyResponse(activateRequest.getFacultyId()); @@ -101,7 +102,7 @@ private Long generateFacultyId() { private FacultyResponse getFacultyResponse(final Long facultyId) { final FacultyEntity facultyEntity = facultyRepository.getFacultyById(facultyId); - return FacultyInfoConverter.entityToResponse(facultyEntity); + return facultyInfoConverter.entityToResponse(facultyEntity); } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/common/model/dto/converter/LessonInfoConverter.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/common/model/dto/converter/LessonInfoConverter.java index fbc72ded..04e9c972 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/common/model/dto/converter/LessonInfoConverter.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/common/model/dto/converter/LessonInfoConverter.java @@ -2,23 +2,27 @@ import com.graduationproject.studentinformationsystem.common.model.dto.request.SisOperationInfoRequest; import com.graduationproject.studentinformationsystem.common.util.SisUtil; -import com.graduationproject.studentinformationsystem.university.department.model.dto.converter.DepartmentInfoConverter; +import com.graduationproject.studentinformationsystem.university.department.model.dto.response.DepartmentResponse; +import com.graduationproject.studentinformationsystem.university.department.service.DepartmentOutService; import com.graduationproject.studentinformationsystem.university.lesson.common.model.dto.request.*; import com.graduationproject.studentinformationsystem.university.lesson.common.model.dto.response.LessonResponse; import com.graduationproject.studentinformationsystem.university.lesson.common.model.entity.LessonEntity; import com.graduationproject.studentinformationsystem.university.lesson.common.model.enums.LessonStatus; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.Date; import java.util.List; +@Component +@RequiredArgsConstructor public class LessonInfoConverter { - private LessonInfoConverter() { - } + private final DepartmentOutService departmentOutService; - public static LessonEntity generateSaveEntity(final Long lessonId, - final LessonSaveRequest saveRequest) { + public LessonEntity generateSaveEntity(final Long lessonId, + final LessonSaveRequest saveRequest) { final LessonInfoRequest lessonInfoRequest = saveRequest.getLessonInfoRequest(); final SisOperationInfoRequest operationInfoRequest = saveRequest.getOperationInfoRequest(); @@ -36,8 +40,8 @@ public static LessonEntity generateSaveEntity(final Long lessonId, .build(); } - public static LessonEntity generateUpdateEntity(final Long lessonId, - final LessonUpdateRequest updateRequest) { + public LessonEntity generateUpdateEntity(final Long lessonId, + final LessonUpdateRequest updateRequest) { final LessonInfoRequest lessonInfoRequest = updateRequest.getLessonInfoRequest(); final SisOperationInfoRequest operationInfoRequest = updateRequest.getOperationInfoRequest(); @@ -55,7 +59,7 @@ public static LessonEntity generateUpdateEntity(final Long lessonId, .build(); } - public static LessonEntity generateDeleteEntity(final LessonDeleteRequest deleteRequest) { + public LessonEntity generateDeleteEntity(final LessonDeleteRequest deleteRequest) { return LessonEntity.builder() .lessonId(deleteRequest.getLessonId()) .status(LessonStatus.DELETED) @@ -64,7 +68,7 @@ public static LessonEntity generateDeleteEntity(final LessonDeleteRequest delete .build(); } - public static LessonEntity generatePassiveEntity(final LessonPassivateRequest passivateRequest) { + public LessonEntity generatePassiveEntity(final LessonPassivateRequest passivateRequest) { return LessonEntity.builder() .lessonId(passivateRequest.getLessonId()) .status(LessonStatus.PASSIVE) @@ -73,7 +77,7 @@ public static LessonEntity generatePassiveEntity(final LessonPassivateRequest pa .build(); } - public static LessonEntity generateActiveEntity(final LessonActivateRequest activateRequest) { + public LessonEntity generateActiveEntity(final LessonActivateRequest activateRequest) { return LessonEntity.builder() .lessonId(activateRequest.getLessonId()) .status(LessonStatus.ACTIVE) @@ -82,10 +86,12 @@ public static LessonEntity generateActiveEntity(final LessonActivateRequest acti .build(); } - public static LessonResponse entityToResponse(final LessonEntity lessonEntity) { + public LessonResponse entityToResponse(final LessonEntity lessonEntity) { + + final DepartmentResponse departmentResponse = departmentOutService.getDepartmentResponse(lessonEntity.getDepartmentId()); + return LessonResponse.builder() .lessonId(lessonEntity.getLessonId()) - .departmentResponse(DepartmentInfoConverter.entityToResponse(lessonEntity.getDepartmentEntity())) .name(lessonEntity.getName()) .status(lessonEntity.getStatus()) .semester(lessonEntity.getSemester()) @@ -95,10 +101,11 @@ public static LessonResponse entityToResponse(final LessonEntity lessonEntity) { .createdDate(SisUtil.getFormattedDateTime(lessonEntity.getCreatedDate())) .modifiedUserId(lessonEntity.getModifiedUserId()) .modifiedDate(SisUtil.getFormattedDateTime(lessonEntity.getModifiedDate())) + .departmentResponse(departmentResponse) .build(); } - public static List entitiesToResponses(final List lessonEntities) { + public List entitiesToResponses(final List lessonEntities) { List lessonResponses = new ArrayList<>(); lessonEntities.forEach(lessonEntity -> lessonResponses.add(entityToResponse(lessonEntity))); return lessonResponses; diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/common/model/entity/LessonEntity.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/common/model/entity/LessonEntity.java index a30fa1e3..84289356 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/common/model/entity/LessonEntity.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/common/model/entity/LessonEntity.java @@ -1,12 +1,10 @@ package com.graduationproject.studentinformationsystem.university.lesson.common.model.entity; import com.graduationproject.studentinformationsystem.common.model.entity.SisBaseEntity; -import com.graduationproject.studentinformationsystem.university.department.model.entity.DepartmentEntity; import com.graduationproject.studentinformationsystem.university.lesson.common.model.enums.LessonCompulsoryOrElective; import com.graduationproject.studentinformationsystem.university.lesson.common.model.enums.LessonSemester; import com.graduationproject.studentinformationsystem.university.lesson.common.model.enums.LessonStatus; import lombok.Getter; -import lombok.Setter; import lombok.experimental.SuperBuilder; @Getter @@ -20,7 +18,4 @@ public class LessonEntity extends SisBaseEntity { private LessonSemester semester; private Integer credit; private LessonCompulsoryOrElective compulsoryOrElective; - - @Setter - private DepartmentEntity departmentEntity; } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/common/service/LessonOutService.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/common/service/LessonOutService.java new file mode 100644 index 00000000..06e36f55 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/common/service/LessonOutService.java @@ -0,0 +1,11 @@ +package com.graduationproject.studentinformationsystem.university.lesson.common.service; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.university.lesson.common.model.dto.response.LessonResponse; + +public interface LessonOutService { + + LessonResponse getLessonResponse(Long lessonId); + + void ifLessonIsNotExistThrowNotExistException(Long lessonId) throws SisNotExistException; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/common/service/impl/LessonOutServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/common/service/impl/LessonOutServiceImpl.java new file mode 100644 index 00000000..dc19dc11 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/common/service/impl/LessonOutServiceImpl.java @@ -0,0 +1,32 @@ +package com.graduationproject.studentinformationsystem.university.lesson.common.service.impl; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.university.lesson.common.model.dto.converter.LessonInfoConverter; +import com.graduationproject.studentinformationsystem.university.lesson.common.model.dto.response.LessonResponse; +import com.graduationproject.studentinformationsystem.university.lesson.common.model.entity.LessonEntity; +import com.graduationproject.studentinformationsystem.university.lesson.common.model.exception.LessonException; +import com.graduationproject.studentinformationsystem.university.lesson.common.repository.LessonRepository; +import com.graduationproject.studentinformationsystem.university.lesson.common.service.LessonOutService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class LessonOutServiceImpl implements LessonOutService { + + private final LessonRepository lessonRepository; + private final LessonInfoConverter lessonInfoConverter; + + @Override + public LessonResponse getLessonResponse(Long lessonId) { + final LessonEntity lessonEntity = lessonRepository.getLessonById(lessonId); + return lessonInfoConverter.entityToResponse(lessonEntity); + } + + @Override + public void ifLessonIsNotExistThrowNotExistException(Long lessonId) throws SisNotExistException { + if (!lessonRepository.isLessonExist(lessonId)) { + LessonException.throwNotExistException(lessonId); + } + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/common/service/impl/LessonServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/common/service/impl/LessonServiceImpl.java index 984c4a38..8c8d1160 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/common/service/impl/LessonServiceImpl.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/common/service/impl/LessonServiceImpl.java @@ -2,10 +2,7 @@ import com.graduationproject.studentinformationsystem.common.util.exception.SisAlreadyException; import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; -import com.graduationproject.studentinformationsystem.university.department.model.entity.DepartmentEntity; -import com.graduationproject.studentinformationsystem.university.department.repository.DepartmentRepository; -import com.graduationproject.studentinformationsystem.university.faculty.model.entity.FacultyEntity; -import com.graduationproject.studentinformationsystem.university.faculty.repository.FacultyRepository; +import com.graduationproject.studentinformationsystem.university.department.service.DepartmentOutService; import com.graduationproject.studentinformationsystem.university.lesson.common.model.dto.converter.LessonInfoConverter; import com.graduationproject.studentinformationsystem.university.lesson.common.model.dto.request.*; import com.graduationproject.studentinformationsystem.university.lesson.common.model.dto.response.LessonResponse; @@ -24,16 +21,15 @@ @RequiredArgsConstructor public class LessonServiceImpl implements LessonService { - private final FacultyRepository facultyRepository; - private final DepartmentRepository departmentRepository; + private final DepartmentOutService departmentOutService; private final LessonRepository lessonRepository; + private final LessonInfoConverter lessonInfoConverter; @Override public List getAllLessonsByStatus(final LessonStatus status) { final List lessonEntities = lessonRepository.getAllLessonsByStatus(status); - setDepartmentEntities(lessonEntities); - return LessonInfoConverter.entitiesToResponses(lessonEntities); + return lessonInfoConverter.entitiesToResponses(lessonEntities); } @Override @@ -50,7 +46,7 @@ public LessonResponse saveLesson(final LessonSaveRequest saveRequest) throws Sis checkBeforeSaving(departmentId); final Long lessonId = generateLessonId(departmentId); - final LessonEntity lessonEntity = LessonInfoConverter.generateSaveEntity(lessonId, saveRequest); + final LessonEntity lessonEntity = lessonInfoConverter.generateSaveEntity(lessonId, saveRequest); lessonRepository.saveLesson(lessonEntity); @@ -63,7 +59,7 @@ public LessonResponse updateLesson(final Long lessonId, final LessonUpdateReques checkBeforeUpdating(lessonId); - final LessonEntity lessonEntity = LessonInfoConverter.generateUpdateEntity(lessonId, updateRequest); + final LessonEntity lessonEntity = lessonInfoConverter.generateUpdateEntity(lessonId, updateRequest); lessonRepository.updateLesson(lessonEntity); return getLessonResponse(lessonId); @@ -75,7 +71,7 @@ public LessonResponse deleteLesson(final LessonDeleteRequest deleteRequest) checkBeforeDeleting(deleteRequest.getLessonId()); - final LessonEntity lessonEntity = LessonInfoConverter.generateDeleteEntity(deleteRequest); + final LessonEntity lessonEntity = lessonInfoConverter.generateDeleteEntity(deleteRequest); lessonRepository.updateLessonStatus(lessonEntity); return getLessonResponse(deleteRequest.getLessonId()); @@ -87,7 +83,7 @@ public LessonResponse passivateLesson(final LessonPassivateRequest passivateRequ checkBeforePassivating(passivateRequest.getLessonId()); - final LessonEntity lessonEntity = LessonInfoConverter.generatePassiveEntity(passivateRequest); + final LessonEntity lessonEntity = lessonInfoConverter.generatePassiveEntity(passivateRequest); lessonRepository.updateLessonStatus(lessonEntity); return getLessonResponse(passivateRequest.getLessonId()); @@ -99,7 +95,7 @@ public LessonResponse activateLesson(final LessonActivateRequest activateRequest checkBeforeActivating(activateRequest.getLessonId()); - final LessonEntity lessonEntity = LessonInfoConverter.generateActiveEntity(activateRequest); + final LessonEntity lessonEntity = lessonInfoConverter.generateActiveEntity(activateRequest); lessonRepository.updateLessonStatus(lessonEntity); return getLessonResponse(activateRequest.getLessonId()); @@ -113,25 +109,7 @@ private Long generateLessonId(final Long departmentId) { private LessonResponse getLessonResponse(final Long lessonId) { final LessonEntity lessonEntity = lessonRepository.getLessonById(lessonId); - setDepartmentEntity(lessonEntity); - return LessonInfoConverter.entityToResponse(lessonEntity); - } - - private void setDepartmentEntity(final LessonEntity lessonEntity) { - final Long departmentId = lessonEntity.getDepartmentId(); - final DepartmentEntity departmentEntity = departmentRepository.getDepartmentById(departmentId); - setFacultyEntity(departmentEntity); - lessonEntity.setDepartmentEntity(departmentEntity); - } - - private void setDepartmentEntities(final List lessonEntities) { - lessonEntities.forEach(this::setDepartmentEntity); - } - - private void setFacultyEntity(final DepartmentEntity departmentEntity) { - final Long facultyId = departmentEntity.getFacultyId(); - final FacultyEntity facultyEntity = facultyRepository.getFacultyById(facultyId); - departmentEntity.setFacultyEntity(facultyEntity); + return lessonInfoConverter.entityToResponse(lessonEntity); } @@ -140,12 +118,10 @@ private void setFacultyEntity(final DepartmentEntity departmentEntity) { */ private void checkBeforeSaving(final Long departmentId) throws SisNotExistException { - ifDepartmentIsNotExistThrowNotExistException(departmentId); } private void checkBeforeUpdating(final Long lessonId) throws SisNotExistException { - ifLessonIsNotExistThrowNotExistException(lessonId); } @@ -172,9 +148,7 @@ private void checkBeforeActivating(final Long lessonId) throws SisNotExistExcept */ private void ifDepartmentIsNotExistThrowNotExistException(final Long departmentId) throws SisNotExistException { - if (!departmentRepository.isDepartmentExist(departmentId)) { - LessonException.throwNotExistException(departmentId); - } + departmentOutService.ifDepartmentIsNotExistThrowNotExistException(departmentId); } private void ifLessonIsNotExistThrowNotExistException(final Long lessonId) throws SisNotExistException { diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/model/dto/converter/TeacherLessonInfoConverter.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/model/dto/converter/TeacherLessonInfoConverter.java index 76d9cc65..4965ed55 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/model/dto/converter/TeacherLessonInfoConverter.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/model/dto/converter/TeacherLessonInfoConverter.java @@ -2,7 +2,8 @@ import com.graduationproject.studentinformationsystem.common.model.dto.request.SisOperationInfoRequest; import com.graduationproject.studentinformationsystem.common.util.SisUtil; -import com.graduationproject.studentinformationsystem.university.lesson.common.model.dto.converter.LessonInfoConverter; +import com.graduationproject.studentinformationsystem.university.lesson.common.model.dto.response.LessonResponse; +import com.graduationproject.studentinformationsystem.university.lesson.common.service.LessonOutService; import com.graduationproject.studentinformationsystem.university.lesson.teacher.model.dto.request.TeacherLessonDeleteRequest; import com.graduationproject.studentinformationsystem.university.lesson.teacher.model.dto.request.TeacherLessonInfoRequest; import com.graduationproject.studentinformationsystem.university.lesson.teacher.model.dto.request.TeacherLessonSaveRequest; @@ -10,18 +11,23 @@ import com.graduationproject.studentinformationsystem.university.lesson.teacher.model.entity.TeacherLessonDeleteEntity; import com.graduationproject.studentinformationsystem.university.lesson.teacher.model.entity.TeacherLessonEntity; import com.graduationproject.studentinformationsystem.university.lesson.teacher.model.entity.TeacherLessonSaveEntity; -import com.graduationproject.studentinformationsystem.university.teacher.model.dto.converter.TeacherAcademicInfoConverter; +import com.graduationproject.studentinformationsystem.university.teacher.model.dto.response.TeacherAcademicInfoResponse; +import com.graduationproject.studentinformationsystem.university.teacher.service.TeacherOutService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.Date; import java.util.List; +@Component +@RequiredArgsConstructor public class TeacherLessonInfoConverter { - private TeacherLessonInfoConverter() { - } + private final TeacherOutService teacherOutService; + private final LessonOutService lessonOutService; - public static TeacherLessonSaveEntity generateSaveEntity(final TeacherLessonSaveRequest saveRequest) { + public TeacherLessonSaveEntity generateSaveEntity(final TeacherLessonSaveRequest saveRequest) { final TeacherLessonInfoRequest teacherLessonInfoRequest = saveRequest.getTeacherLessonInfoRequest(); final SisOperationInfoRequest operationInfoRequest = saveRequest.getOperationInfoRequest(); @@ -33,7 +39,7 @@ public static TeacherLessonSaveEntity generateSaveEntity(final TeacherLessonSave .createdDate(new Date()).build(); } - public static TeacherLessonDeleteEntity generateDeleteEntity(final TeacherLessonDeleteRequest deleteRequest) { + public TeacherLessonDeleteEntity generateDeleteEntity(final TeacherLessonDeleteRequest deleteRequest) { final TeacherLessonInfoRequest teacherLessonInfoRequest = deleteRequest.getTeacherLessonInfoRequest(); @@ -42,16 +48,19 @@ public static TeacherLessonDeleteEntity generateDeleteEntity(final TeacherLesson .lessonId(teacherLessonInfoRequest.getLessonId()).build(); } - public static TeacherLessonResponse entityToResponse(final TeacherLessonEntity teacherLessonEntity) { + public TeacherLessonResponse entityToResponse(final TeacherLessonEntity teacherLessonEntity) { + + final TeacherAcademicInfoResponse teacherAcademicInfoResponse = teacherOutService.getTeacherAcademicInfoResponse(teacherLessonEntity.getTeacherId()); + final LessonResponse lessonResponse = lessonOutService.getLessonResponse(teacherLessonEntity.getLessonId()); return TeacherLessonResponse.builder() .createdUserId(teacherLessonEntity.getCreatedUserId()) .createdDate(SisUtil.getFormattedDateTime(teacherLessonEntity.getCreatedDate())) - .teacherAcademicInfoResponse(TeacherAcademicInfoConverter.entityToResponse(teacherLessonEntity.getTeacherAcademicInfoEntity())) - .lessonResponse(LessonInfoConverter.entityToResponse(teacherLessonEntity.getLessonEntity())).build(); + .lessonResponse(lessonResponse) + .teacherAcademicInfoResponse(teacherAcademicInfoResponse).build(); } - public static List entitiesToResponses(final List lessonEntities) { + public List entitiesToResponses(final List lessonEntities) { final List lessonResponses = new ArrayList<>(); lessonEntities.forEach(lessonEntity -> lessonResponses.add(entityToResponse(lessonEntity))); return lessonResponses; diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/model/entity/TeacherLessonEntity.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/model/entity/TeacherLessonEntity.java index 649207f3..a725ebc3 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/model/entity/TeacherLessonEntity.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/model/entity/TeacherLessonEntity.java @@ -1,10 +1,7 @@ package com.graduationproject.studentinformationsystem.university.lesson.teacher.model.entity; -import com.graduationproject.studentinformationsystem.university.lesson.common.model.entity.LessonEntity; -import com.graduationproject.studentinformationsystem.university.teacher.model.entity.TeacherAcademicInfoEntity; import lombok.Builder; import lombok.Getter; -import lombok.Setter; import java.util.Date; @@ -16,10 +13,4 @@ public class TeacherLessonEntity { private Long lessonId; private Long createdUserId; private Date createdDate; - - @Setter - private LessonEntity lessonEntity; - - @Setter - private TeacherAcademicInfoEntity teacherAcademicInfoEntity; } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/service/impl/TeacherLessonServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/service/impl/TeacherLessonServiceImpl.java index cb586026..231956e6 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/service/impl/TeacherLessonServiceImpl.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/service/impl/TeacherLessonServiceImpl.java @@ -2,15 +2,8 @@ import com.graduationproject.studentinformationsystem.common.util.exception.SisAlreadyException; import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; -import com.graduationproject.studentinformationsystem.university.department.model.entity.DepartmentEntity; -import com.graduationproject.studentinformationsystem.university.department.repository.DepartmentRepository; -import com.graduationproject.studentinformationsystem.university.faculty.model.entity.FacultyEntity; -import com.graduationproject.studentinformationsystem.university.faculty.repository.FacultyRepository; -import com.graduationproject.studentinformationsystem.university.lesson.common.model.entity.LessonEntity; -import com.graduationproject.studentinformationsystem.university.lesson.common.repository.LessonRepository; import com.graduationproject.studentinformationsystem.university.lesson.teacher.model.dto.converter.TeacherLessonInfoConverter; import com.graduationproject.studentinformationsystem.university.lesson.teacher.model.dto.request.TeacherLessonDeleteRequest; -import com.graduationproject.studentinformationsystem.university.lesson.teacher.model.dto.request.TeacherLessonInfoRequest; import com.graduationproject.studentinformationsystem.university.lesson.teacher.model.dto.request.TeacherLessonSaveRequest; import com.graduationproject.studentinformationsystem.university.lesson.teacher.model.dto.response.TeacherLessonResponse; import com.graduationproject.studentinformationsystem.university.lesson.teacher.model.entity.TeacherLessonDeleteEntity; @@ -19,8 +12,6 @@ import com.graduationproject.studentinformationsystem.university.lesson.teacher.model.exception.TeacherLessonException; import com.graduationproject.studentinformationsystem.university.lesson.teacher.repository.TeacherLessonRepository; import com.graduationproject.studentinformationsystem.university.lesson.teacher.service.TeacherLessonService; -import com.graduationproject.studentinformationsystem.university.teacher.model.entity.TeacherAcademicInfoEntity; -import com.graduationproject.studentinformationsystem.university.teacher.repository.TeacherAcademicInfoRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -31,94 +22,54 @@ @RequiredArgsConstructor public class TeacherLessonServiceImpl implements TeacherLessonService { - private final FacultyRepository facultyRepository; - private final DepartmentRepository departmentRepository; - private final LessonRepository lessonRepository; - private final TeacherAcademicInfoRepository teacherAcademicInfoRepository; - private final TeacherLessonRepository teacherLessonRepository; + private final TeacherLessonInfoConverter teacherLessonInfoConverter; @Override public List getAllTeachersLessons() { final List teacherLessonEntities = teacherLessonRepository.getAllTeachersLessons(); - setLessonEntities(teacherLessonEntities); - setTeacherAcademicInfoEntities(teacherLessonEntities); - return TeacherLessonInfoConverter.entitiesToResponses(teacherLessonEntities); + return teacherLessonInfoConverter.entitiesToResponses(teacherLessonEntities); } @Override public List getTeacherLessonsById(final Long teacherId) { - final List teacherLessonEntities = teacherLessonRepository.getTeacherLessonsByTeacherId(teacherId); - setLessonEntities(teacherLessonEntities); - setTeacherAcademicInfoEntities(teacherLessonEntities); - return TeacherLessonInfoConverter.entitiesToResponses(teacherLessonEntities); - } - @Override - public TeacherLessonResponse saveTeacherLesson(final TeacherLessonSaveRequest saveRequest) throws SisAlreadyException { - checkBeforeSaving(saveRequest); + final List teacherLessonEntities = teacherLessonRepository + .getTeacherLessonsByTeacherId(teacherId); - final TeacherLessonSaveEntity saveEntity = TeacherLessonInfoConverter.generateSaveEntity(saveRequest); - - teacherLessonRepository.saveTeacherLesson(saveEntity); - return getTeacherLessonResponse(saveEntity.getTeacherId(), saveEntity.getLessonId()); + return teacherLessonInfoConverter.entitiesToResponses(teacherLessonEntities); } @Override - public void deleteTeacherLesson(final TeacherLessonDeleteRequest deleteRequest) throws SisNotExistException { - checkBeforeDeleting(deleteRequest); + public TeacherLessonResponse saveTeacherLesson(final TeacherLessonSaveRequest teacherLessonSaveRequest) + throws SisAlreadyException { - final TeacherLessonDeleteEntity deleteEntity = TeacherLessonInfoConverter.generateDeleteEntity(deleteRequest); - teacherLessonRepository.deleteTeacherLesson(deleteEntity); - } + checkBeforeSaving(teacherLessonSaveRequest); - private TeacherLessonResponse getTeacherLessonResponse(final Long teacherId, final Long lessonId) { - final TeacherLessonEntity teacherLessonEntity = teacherLessonRepository.getTeacherLessonByTeacherIdAndLessonId(teacherId, lessonId); - setTeacherAcademicInfoEntity(teacherLessonEntity); - setLessonEntity(teacherLessonEntity); - return TeacherLessonInfoConverter.entityToResponse(teacherLessonEntity); - } + final TeacherLessonSaveEntity teacherLessonSaveEntity = teacherLessonInfoConverter + .generateSaveEntity(teacherLessonSaveRequest); - private void setTeacherAcademicInfoEntity(final TeacherLessonEntity teacherLessonEntity) { - final Long teacherId = teacherLessonEntity.getTeacherId(); - final TeacherAcademicInfoEntity teacherAcademicInfoEntity = teacherAcademicInfoRepository.getTeacherAcademicInfoById(teacherId); - setDepartmentEntity(teacherAcademicInfoEntity); - teacherLessonEntity.setTeacherAcademicInfoEntity(teacherAcademicInfoEntity); + teacherLessonRepository.saveTeacherLesson(teacherLessonSaveEntity); + return getTeacherLessonResponse(teacherLessonSaveEntity.getTeacherId(), teacherLessonSaveEntity.getLessonId()); } - private void setTeacherAcademicInfoEntities(List teacherLessonEntities) { - teacherLessonEntities.forEach(this::setTeacherAcademicInfoEntity); - } + @Override + public void deleteTeacherLesson(final TeacherLessonDeleteRequest teacherLessonDeleteRequest) + throws SisNotExistException { - private void setLessonEntity(final TeacherLessonEntity teacherLessonEntity) { - final Long lessonId = teacherLessonEntity.getLessonId(); - final LessonEntity lessonEntity = lessonRepository.getLessonById(lessonId); - setDepartmentEntity(lessonEntity); - teacherLessonEntity.setLessonEntity(lessonEntity); - } + checkBeforeDeleting(teacherLessonDeleteRequest); - private void setLessonEntities(final List teacherLessonEntities) { - teacherLessonEntities.forEach(this::setLessonEntity); - } + final TeacherLessonDeleteEntity teacherLessonDeleteEntity = teacherLessonInfoConverter + .generateDeleteEntity(teacherLessonDeleteRequest); - private void setDepartmentEntity(final TeacherAcademicInfoEntity teacherAcademicInfoEntity) { - final Long departmentId = teacherAcademicInfoEntity.getDepartmentId(); - final DepartmentEntity departmentEntity = departmentRepository.getDepartmentById(departmentId); - setFacultyEntity(departmentEntity); - teacherAcademicInfoEntity.setDepartmentEntity(departmentEntity); + teacherLessonRepository.deleteTeacherLesson(teacherLessonDeleteEntity); } - private void setDepartmentEntity(final LessonEntity lessonEntity) { - final Long departmentId = lessonEntity.getDepartmentId(); - final DepartmentEntity departmentEntity = departmentRepository.getDepartmentById(departmentId); - setFacultyEntity(departmentEntity); - lessonEntity.setDepartmentEntity(departmentEntity); - } + private TeacherLessonResponse getTeacherLessonResponse(final Long teacherId, final Long lessonId) { + final TeacherLessonEntity teacherLessonEntity = teacherLessonRepository + .getTeacherLessonByTeacherIdAndLessonId(teacherId, lessonId); - private void setFacultyEntity(final DepartmentEntity departmentEntity) { - final Long facultyId = departmentEntity.getFacultyId(); - final FacultyEntity facultyEntity = facultyRepository.getFacultyById(facultyId); - departmentEntity.setFacultyEntity(facultyEntity); + return teacherLessonInfoConverter.entityToResponse(teacherLessonEntity); } @@ -129,12 +80,15 @@ private void setFacultyEntity(final DepartmentEntity departmentEntity) { private void checkBeforeSaving(final TeacherLessonSaveRequest saveRequest) throws SisAlreadyException { final Long teacherId = saveRequest.getTeacherLessonInfoRequest().getTeacherId(); final Long lessonId = saveRequest.getTeacherLessonInfoRequest().getLessonId(); + ifTeacherLessonIsExistThrowAlreadyException(teacherId, lessonId); } private void checkBeforeDeleting(final TeacherLessonDeleteRequest deleteRequest) throws SisNotExistException { - final TeacherLessonInfoRequest teacherLessonInfoRequest = deleteRequest.getTeacherLessonInfoRequest(); - ifTeacherLessonIsNotExistThrowNotExistException(teacherLessonInfoRequest.getTeacherId(), teacherLessonInfoRequest.getLessonId()); + final Long teacherId = deleteRequest.getTeacherLessonInfoRequest().getTeacherId(); + final Long lessonId = deleteRequest.getTeacherLessonInfoRequest().getLessonId(); + + ifTeacherLessonIsNotExistThrowNotExistException(teacherId, lessonId); } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/officer/model/dto/converter/OfficerAcademicInfoConverter.java b/src/main/java/com/graduationproject/studentinformationsystem/university/officer/model/dto/converter/OfficerAcademicInfoConverter.java index 4f2dbc05..87ec0e63 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/officer/model/dto/converter/OfficerAcademicInfoConverter.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/officer/model/dto/converter/OfficerAcademicInfoConverter.java @@ -2,25 +2,29 @@ import com.graduationproject.studentinformationsystem.common.model.dto.request.SisOperationInfoRequest; import com.graduationproject.studentinformationsystem.common.util.SisUtil; -import com.graduationproject.studentinformationsystem.university.faculty.model.dto.converter.FacultyInfoConverter; +import com.graduationproject.studentinformationsystem.university.faculty.model.dto.response.FacultyResponse; +import com.graduationproject.studentinformationsystem.university.faculty.service.FacultyOutService; import com.graduationproject.studentinformationsystem.university.officer.model.dto.request.*; import com.graduationproject.studentinformationsystem.university.officer.model.dto.response.OfficerAcademicInfoResponse; import com.graduationproject.studentinformationsystem.university.officer.model.entity.OfficerAcademicInfoEntity; import com.graduationproject.studentinformationsystem.university.officer.model.enums.OfficerStatus; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.Date; import java.util.List; +@Component +@RequiredArgsConstructor public class OfficerAcademicInfoConverter { - private OfficerAcademicInfoConverter() { - } + private final FacultyOutService facultyOutService; - public static OfficerAcademicInfoEntity generateSaveEntity(final Long officerId, - final String officerEmail, - final OfficerAcademicInfoRequest academicInfoRequest, - final SisOperationInfoRequest operationInfoRequest) { + public OfficerAcademicInfoEntity generateSaveEntity(final Long officerId, + final String officerEmail, + final OfficerAcademicInfoRequest academicInfoRequest, + final SisOperationInfoRequest operationInfoRequest) { return OfficerAcademicInfoEntity.builder() .officerId(officerId) @@ -34,8 +38,8 @@ public static OfficerAcademicInfoEntity generateSaveEntity(final Long officerId, .build(); } - public static OfficerAcademicInfoEntity generateUpdateEntity(final Long officerId, - final OfficerAcademicInfoUpdateRequest academicInfoUpdateRequest) { + public OfficerAcademicInfoEntity generateUpdateEntity(final Long officerId, + final OfficerAcademicInfoUpdateRequest academicInfoUpdateRequest) { final OfficerAcademicInfoRequest academicInfoRequest = academicInfoUpdateRequest.getAcademicInfoRequest(); final SisOperationInfoRequest operationInfoRequest = academicInfoUpdateRequest.getOperationInfoRequest(); @@ -49,7 +53,7 @@ public static OfficerAcademicInfoEntity generateUpdateEntity(final Long officerI .build(); } - public static OfficerAcademicInfoEntity generateDeleteEntity(final OfficerDeleteRequest deleteRequest) { + public OfficerAcademicInfoEntity generateDeleteEntity(final OfficerDeleteRequest deleteRequest) { return OfficerAcademicInfoEntity.builder() .officerId(deleteRequest.getOfficerId()) .status(OfficerStatus.DELETED) @@ -58,7 +62,7 @@ public static OfficerAcademicInfoEntity generateDeleteEntity(final OfficerDelete .build(); } - public static OfficerAcademicInfoEntity generatePassiveEntity(final OfficerPassivateRequest passivateRequest) { + public OfficerAcademicInfoEntity generatePassiveEntity(final OfficerPassivateRequest passivateRequest) { return OfficerAcademicInfoEntity.builder() .officerId(passivateRequest.getOfficerId()) .status(OfficerStatus.PASSIVE) @@ -67,7 +71,7 @@ public static OfficerAcademicInfoEntity generatePassiveEntity(final OfficerPassi .build(); } - public static OfficerAcademicInfoEntity generateActiveEntity(final OfficerActivateRequest activateRequest) { + public OfficerAcademicInfoEntity generateActiveEntity(final OfficerActivateRequest activateRequest) { return OfficerAcademicInfoEntity.builder() .officerId(activateRequest.getOfficerId()) .status(OfficerStatus.ACTIVE) @@ -76,10 +80,12 @@ public static OfficerAcademicInfoEntity generateActiveEntity(final OfficerActiva .build(); } - public static OfficerAcademicInfoResponse entityToResponse(final OfficerAcademicInfoEntity academicInfoEntity) { + public OfficerAcademicInfoResponse entityToResponse(final OfficerAcademicInfoEntity academicInfoEntity) { + + final FacultyResponse facultyResponse = facultyOutService.getFacultyResponse(academicInfoEntity.getFacultyId()); + return OfficerAcademicInfoResponse.builder() .officerId(academicInfoEntity.getOfficerId()) - .facultyResponse(FacultyInfoConverter.entityToResponse(academicInfoEntity.getFacultyEntity())) .phoneNumber(SisUtil.getFormattedPhoneNumber(academicInfoEntity.getPhoneNumber())) .email(academicInfoEntity.getEmail()) .status(academicInfoEntity.getStatus()) @@ -87,10 +93,12 @@ public static OfficerAcademicInfoResponse entityToResponse(final OfficerAcademic .createdUserId(academicInfoEntity.getCreatedUserId()) .createdDate(SisUtil.getFormattedDateTime(academicInfoEntity.getCreatedDate())) .modifiedUserId(academicInfoEntity.getModifiedUserId()) - .modifiedDate(SisUtil.getFormattedDateTime(academicInfoEntity.getModifiedDate())).build(); + .modifiedDate(SisUtil.getFormattedDateTime(academicInfoEntity.getModifiedDate())) + .facultyResponse(facultyResponse) + .build(); } - public static List entitiesToResponses(final List academicInfoEntities) { + public List entitiesToResponses(final List academicInfoEntities) { List academicInfoResponses = new ArrayList<>(); academicInfoEntities.forEach(academicInfoEntity -> academicInfoResponses.add(entityToResponse(academicInfoEntity))); return academicInfoResponses; diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/officer/model/dto/converter/OfficerResponseConverter.java b/src/main/java/com/graduationproject/studentinformationsystem/university/officer/model/dto/converter/OfficerResponseConverter.java index b2d0dbbf..a487026d 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/officer/model/dto/converter/OfficerResponseConverter.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/officer/model/dto/converter/OfficerResponseConverter.java @@ -17,13 +17,13 @@ public static OfficerInfoResponse infoResponsesToResponse(OfficerAcademicInfoRes return OfficerInfoResponse.builder() .officerId(academicInfoResponse.getOfficerId()) - .facultyResponse(academicInfoResponse.getFacultyResponse()) .name(personalInfoResponse.getName()) .surname(personalInfoResponse.getSurname()) .email(academicInfoResponse.getEmail()) .phoneNumber(academicInfoResponse.getPhoneNumber()) .status(academicInfoResponse.getStatus()) - .registrationDate(academicInfoResponse.getRegistrationDate()).build(); + .registrationDate(academicInfoResponse.getRegistrationDate()) + .facultyResponse(academicInfoResponse.getFacultyResponse()).build(); } public static List infoResponsesListToResponseList(List academicInfoResponses, diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/officer/model/entity/OfficerAcademicInfoEntity.java b/src/main/java/com/graduationproject/studentinformationsystem/university/officer/model/entity/OfficerAcademicInfoEntity.java index 6ef463d4..ce65de40 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/officer/model/entity/OfficerAcademicInfoEntity.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/officer/model/entity/OfficerAcademicInfoEntity.java @@ -1,10 +1,8 @@ package com.graduationproject.studentinformationsystem.university.officer.model.entity; import com.graduationproject.studentinformationsystem.common.model.entity.SisBaseEntity; -import com.graduationproject.studentinformationsystem.university.faculty.model.entity.FacultyEntity; import com.graduationproject.studentinformationsystem.university.officer.model.enums.OfficerStatus; import lombok.Getter; -import lombok.Setter; import lombok.experimental.SuperBuilder; import java.util.Date; @@ -19,7 +17,4 @@ public class OfficerAcademicInfoEntity extends SisBaseEntity { private String email; private OfficerStatus status; private Date registrationDate; - - @Setter - private FacultyEntity facultyEntity; } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/officer/service/impl/OfficerAcademicInfoServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/officer/service/impl/OfficerAcademicInfoServiceImpl.java index baf25d51..d44da30e 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/officer/service/impl/OfficerAcademicInfoServiceImpl.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/officer/service/impl/OfficerAcademicInfoServiceImpl.java @@ -1,8 +1,6 @@ package com.graduationproject.studentinformationsystem.university.officer.service.impl; import com.graduationproject.studentinformationsystem.common.model.dto.request.SisOperationInfoRequest; -import com.graduationproject.studentinformationsystem.university.faculty.model.entity.FacultyEntity; -import com.graduationproject.studentinformationsystem.university.faculty.repository.FacultyRepository; import com.graduationproject.studentinformationsystem.university.officer.model.dto.converter.OfficerAcademicInfoConverter; import com.graduationproject.studentinformationsystem.university.officer.model.dto.request.*; import com.graduationproject.studentinformationsystem.university.officer.model.dto.response.OfficerAcademicInfoResponse; @@ -19,15 +17,13 @@ @RequiredArgsConstructor public class OfficerAcademicInfoServiceImpl implements OfficerAcademicInfoService { - private final FacultyRepository facultyRepository; - private final OfficerAcademicInfoRepository academicInfoRepository; + private final OfficerAcademicInfoConverter academicInfoConverter; @Override public List getAllOfficerAcademicInfosByStatus(final OfficerStatus status) { final List academicInfoEntities = academicInfoRepository.getAllOfficerAcademicInfosByStatus(status); - setFacultyEntities(academicInfoEntities); - return OfficerAcademicInfoConverter.entitiesToResponses(academicInfoEntities); + return academicInfoConverter.entitiesToResponses(academicInfoEntities); } @Override @@ -41,7 +37,7 @@ public void saveOfficerAcademicInfo(final Long officerId, final OfficerAcademicInfoRequest academicInfoRequest, final SisOperationInfoRequest operationInfoRequest) { - final OfficerAcademicInfoEntity academicInfoEntity = OfficerAcademicInfoConverter + final OfficerAcademicInfoEntity academicInfoEntity = academicInfoConverter .generateSaveEntity(officerId, officerEmail, academicInfoRequest, operationInfoRequest); academicInfoRepository.saveOfficerAcademicInfo(academicInfoEntity); @@ -51,7 +47,7 @@ public void saveOfficerAcademicInfo(final Long officerId, public OfficerAcademicInfoResponse updateOfficerAcademicInfo(final Long officerId, final OfficerAcademicInfoUpdateRequest academicInfoUpdateRequest) { - final OfficerAcademicInfoEntity academicInfoEntity = OfficerAcademicInfoConverter + final OfficerAcademicInfoEntity academicInfoEntity = academicInfoConverter .generateUpdateEntity(officerId, academicInfoUpdateRequest); academicInfoRepository.updateOfficerAcademicInfo(academicInfoEntity); @@ -61,19 +57,19 @@ public OfficerAcademicInfoResponse updateOfficerAcademicInfo(final Long officerI @Override public void deleteOfficerAcademicInfo(final OfficerDeleteRequest deleteRequest) { - final OfficerAcademicInfoEntity academicInfoEntity = OfficerAcademicInfoConverter.generateDeleteEntity(deleteRequest); + final OfficerAcademicInfoEntity academicInfoEntity = academicInfoConverter.generateDeleteEntity(deleteRequest); academicInfoRepository.updateOfficerAcademicInfoStatus(academicInfoEntity); } @Override public void passivateOfficerAcademicInfo(final OfficerPassivateRequest passivateRequest) { - final OfficerAcademicInfoEntity academicInfoEntity = OfficerAcademicInfoConverter.generatePassiveEntity(passivateRequest); + final OfficerAcademicInfoEntity academicInfoEntity = academicInfoConverter.generatePassiveEntity(passivateRequest); academicInfoRepository.updateOfficerAcademicInfoStatus(academicInfoEntity); } @Override public void activateOfficerAcademicInfo(final OfficerActivateRequest activateRequest) { - final OfficerAcademicInfoEntity academicInfoEntity = OfficerAcademicInfoConverter.generateActiveEntity(activateRequest); + final OfficerAcademicInfoEntity academicInfoEntity = academicInfoConverter.generateActiveEntity(activateRequest); academicInfoRepository.updateOfficerAcademicInfoStatus(academicInfoEntity); } @@ -105,17 +101,6 @@ public boolean isOfficerActive(final Long officerId) { private OfficerAcademicInfoResponse getOfficerAcademicInfoResponse(final Long officerId) { final OfficerAcademicInfoEntity academicInfoEntity = academicInfoRepository.getOfficerAcademicInfoById(officerId); - setFacultyEntity(academicInfoEntity); - return OfficerAcademicInfoConverter.entityToResponse(academicInfoEntity); - } - - private void setFacultyEntity(final OfficerAcademicInfoEntity academicInfoEntity) { - final Long facultyId = academicInfoEntity.getFacultyId(); - final FacultyEntity facultyEntity = facultyRepository.getFacultyById(facultyId); - academicInfoEntity.setFacultyEntity(facultyEntity); - } - - private void setFacultyEntities(final List academicInfoEntities) { - academicInfoEntities.forEach(this::setFacultyEntity); + return academicInfoConverter.entityToResponse(academicInfoEntity); } } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/officer/service/impl/OfficerServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/officer/service/impl/OfficerServiceImpl.java index 94f73652..cea66175 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/officer/service/impl/OfficerServiceImpl.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/officer/service/impl/OfficerServiceImpl.java @@ -139,14 +139,14 @@ private OfficerInfoResponse getOfficerResponse(final Long officerId) { */ private void checkBeforeSaving(final OfficerSaveRequest saveRequest) { - ifFacultyIdIsNotExistThrowNotExistException(saveRequest.getAcademicInfoRequest().getFacultyId()); + ifFacultyIsNotExistThrowNotExistException(saveRequest.getAcademicInfoRequest().getFacultyId()); } private void checkBeforeUpdatingAcademicInfo(final Long officerId, final OfficerAcademicInfoUpdateRequest academicInfoUpdateRequest) throws SisNotExistException { ifOfficerIsNotExistThrowNotExistException(officerId); - ifFacultyIdIsNotExistThrowNotExistException(academicInfoUpdateRequest.getAcademicInfoRequest().getFacultyId()); + ifFacultyIsNotExistThrowNotExistException(academicInfoUpdateRequest.getAcademicInfoRequest().getFacultyId()); } private void checkBeforeUpdatingPersonalInfo(final Long officerId) throws SisNotExistException { @@ -181,8 +181,8 @@ private void ifOfficerIsNotExistThrowNotExistException(final Long officerId) thr } } - private void ifFacultyIdIsNotExistThrowNotExistException(final Long facultyId) { - // TODO: ifFacultyIdIsNotExistThrowNotExistException + private void ifFacultyIsNotExistThrowNotExistException(final Long facultyId) { + // TODO: ifFacultyIsNotExistThrowNotExistException // if (!facultyService.isFacultyExist(facultyId)) { // SisException.throwNotExistException(); // } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/schedule/common/model/entity/ScheduleFileEntity.java b/src/main/java/com/graduationproject/studentinformationsystem/university/schedule/common/model/entity/ScheduleFileEntity.java index 9c31ded7..ec686697 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/schedule/common/model/entity/ScheduleFileEntity.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/schedule/common/model/entity/ScheduleFileEntity.java @@ -1,9 +1,7 @@ package com.graduationproject.studentinformationsystem.university.schedule.common.model.entity; -import com.graduationproject.studentinformationsystem.university.department.model.entity.DepartmentEntity; import lombok.Builder; import lombok.Getter; -import lombok.Setter; import org.springframework.web.multipart.MultipartFile; import java.util.Date; @@ -23,7 +21,4 @@ public class ScheduleFileEntity { private MultipartFile file; private Long createdUserId; private Date createdDate; - - @Setter - private DepartmentEntity departmentEntity; } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/schedule/exam/model/dto/converter/ExamScheduleFileInfoConverter.java b/src/main/java/com/graduationproject/studentinformationsystem/university/schedule/exam/model/dto/converter/ExamScheduleFileInfoConverter.java index 4d45b1c9..aca60ab9 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/schedule/exam/model/dto/converter/ExamScheduleFileInfoConverter.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/schedule/exam/model/dto/converter/ExamScheduleFileInfoConverter.java @@ -1,10 +1,13 @@ package com.graduationproject.studentinformationsystem.university.schedule.exam.model.dto.converter; import com.graduationproject.studentinformationsystem.common.util.SisUtil; -import com.graduationproject.studentinformationsystem.university.department.model.dto.converter.DepartmentInfoConverter; +import com.graduationproject.studentinformationsystem.university.department.model.dto.response.DepartmentResponse; +import com.graduationproject.studentinformationsystem.university.department.service.DepartmentOutService; import com.graduationproject.studentinformationsystem.university.schedule.common.model.dto.response.ScheduleFileDetailResponse; import com.graduationproject.studentinformationsystem.university.schedule.common.model.dto.response.ScheduleFileResponse; import com.graduationproject.studentinformationsystem.university.schedule.common.model.entity.ScheduleFileEntity; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; import org.springframework.web.multipart.MultipartFile; import java.io.IOException; @@ -12,17 +15,18 @@ import java.util.Date; import java.util.List; +@Component +@RequiredArgsConstructor public class ExamScheduleFileInfoConverter { - private ExamScheduleFileInfoConverter() { - } + private final DepartmentOutService departmentOutService; - public static ScheduleFileEntity generateSaveEntity(final String fileId, - final MultipartFile document, - final String apiUrl, - final Long facultyId, - final Long departmentId, - final Long operationUserId) throws IOException { + public ScheduleFileEntity generateSaveEntity(final String fileId, + final MultipartFile document, + final String apiUrl, + final Long facultyId, + final Long departmentId, + final Long operationUserId) throws IOException { return ScheduleFileEntity.builder() .fileId(fileId) @@ -39,7 +43,7 @@ public static ScheduleFileEntity generateSaveEntity(final String fileId, .build(); } - public static ScheduleFileResponse entityToResponse(final ScheduleFileEntity scheduleFileEntity) throws IOException { + public ScheduleFileResponse entityToResponse(final ScheduleFileEntity scheduleFileEntity) throws IOException { return ScheduleFileResponse.builder() .fileName(scheduleFileEntity.getFileName()) .fileByte(scheduleFileEntity.getFileByte()) @@ -48,20 +52,23 @@ public static ScheduleFileResponse entityToResponse(final ScheduleFileEntity sch .build(); } - public static ScheduleFileDetailResponse entityToDetailResponse(final ScheduleFileEntity scheduleFileEntity) { + public ScheduleFileDetailResponse entityToDetailResponse(final ScheduleFileEntity scheduleFileEntity) { + + final DepartmentResponse departmentResponse = departmentOutService.getDepartmentResponse(scheduleFileEntity.getDepartmentId()); + return ScheduleFileDetailResponse.builder() .fileId(scheduleFileEntity.getFileId()) - .departmentResponse(DepartmentInfoConverter.entityToResponse(scheduleFileEntity.getDepartmentEntity())) .fileName(scheduleFileEntity.getFileName()) .fileType(scheduleFileEntity.getFileType()) .fileDownloadUrl(scheduleFileEntity.getApiUrl() + "/exam-schedule-file/download/" + scheduleFileEntity.getFileId()) .fileViewUrl(scheduleFileEntity.getApiUrl() + "/exam-schedule-file/view/" + scheduleFileEntity.getFileId()) .createdUserId(scheduleFileEntity.getCreatedUserId()) .createdDate(SisUtil.getFormattedDateTime(scheduleFileEntity.getCreatedDate())) + .departmentResponse(departmentResponse) .build(); } - public static List entitiesToResponses(final List scheduleFileEntities) { + public List entitiesToResponses(final List scheduleFileEntities) { List scheduleFileDetailResponses = new ArrayList<>(); scheduleFileEntities.forEach(scheduleFileEntity -> scheduleFileDetailResponses.add(entityToDetailResponse(scheduleFileEntity))); return scheduleFileDetailResponses; diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/schedule/exam/service/impl/ExamScheduleFileServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/schedule/exam/service/impl/ExamScheduleFileServiceImpl.java index 6be21c09..709d0267 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/schedule/exam/service/impl/ExamScheduleFileServiceImpl.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/schedule/exam/service/impl/ExamScheduleFileServiceImpl.java @@ -5,12 +5,8 @@ import com.graduationproject.studentinformationsystem.common.util.exception.SisAlreadyException; import com.graduationproject.studentinformationsystem.common.util.exception.SisFileTypeException; import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; -import com.graduationproject.studentinformationsystem.university.department.model.entity.DepartmentEntity; -import com.graduationproject.studentinformationsystem.university.department.model.exception.DepartmentException; -import com.graduationproject.studentinformationsystem.university.department.repository.DepartmentRepository; -import com.graduationproject.studentinformationsystem.university.faculty.model.entity.FacultyEntity; -import com.graduationproject.studentinformationsystem.university.faculty.model.exception.FacultyException; -import com.graduationproject.studentinformationsystem.university.faculty.repository.FacultyRepository; +import com.graduationproject.studentinformationsystem.university.department.service.DepartmentOutService; +import com.graduationproject.studentinformationsystem.university.faculty.service.FacultyOutService; import com.graduationproject.studentinformationsystem.university.schedule.common.model.dto.response.ScheduleFileDetailResponse; import com.graduationproject.studentinformationsystem.university.schedule.common.model.dto.response.ScheduleFileResponse; import com.graduationproject.studentinformationsystem.university.schedule.common.model.entity.ScheduleFileEntity; @@ -29,10 +25,11 @@ @RequiredArgsConstructor public class ExamScheduleFileServiceImpl implements ExamScheduleFileService { - private final FacultyRepository facultyRepository; - private final DepartmentRepository departmentRepository; + private final FacultyOutService facultyOutService; + private final DepartmentOutService departmentOutService; private final ExamScheduleFileRepository scheduleFileRepository; + private final ExamScheduleFileInfoConverter scheduleFileInfoConverter; @Override public List getExamScheduleFilesByFacultyId(final Long facultyId) @@ -69,7 +66,7 @@ public ScheduleFileDetailResponse saveExamScheduleFile(final String apiUrl, checkBeforeSaving(facultyId, departmentId, document.getContentType()); final String fileId = SisUtil.generateRandomUUID(); - final ScheduleFileEntity scheduleFileEntity = ExamScheduleFileInfoConverter + final ScheduleFileEntity scheduleFileEntity = scheduleFileInfoConverter .generateSaveEntity(fileId, document, apiUrl, facultyId, departmentId, operationUserId); scheduleFileRepository.saveExamScheduleFile(scheduleFileEntity); @@ -85,36 +82,17 @@ public void deleteExamScheduleFileByDepartmentId(final Long departmentId) throws private ScheduleFileResponse getExamScheduleFileResponse(final String fileId) throws IOException { final ScheduleFileEntity scheduleFileEntity = scheduleFileRepository.getExamScheduleFileById(fileId); - return ExamScheduleFileInfoConverter.entityToResponse(scheduleFileEntity); + return scheduleFileInfoConverter.entityToResponse(scheduleFileEntity); } private List getExamScheduleFilesDetailResponses(final Long facultyId) { final List scheduleFileEntities = scheduleFileRepository.getExamScheduleFilesByFacultyId(facultyId); - setDepartmentEntities(scheduleFileEntities); - return ExamScheduleFileInfoConverter.entitiesToResponses(scheduleFileEntities); + return scheduleFileInfoConverter.entitiesToResponses(scheduleFileEntities); } private ScheduleFileDetailResponse getExamScheduleFileDetailResponse(final Long departmentId) { final ScheduleFileEntity scheduleFileEntity = scheduleFileRepository.getExamScheduleFileByDepartmentId(departmentId); - setDepartmentEntity(scheduleFileEntity); - return ExamScheduleFileInfoConverter.entityToDetailResponse(scheduleFileEntity); - } - - private void setDepartmentEntities(final List scheduleFileEntities) { - scheduleFileEntities.forEach(this::setDepartmentEntity); - } - - private void setDepartmentEntity(final ScheduleFileEntity scheduleFileEntity) { - final Long departmentId = scheduleFileEntity.getDepartmentId(); - final DepartmentEntity departmentEntity = departmentRepository.getDepartmentById(departmentId); - setFacultyEntity(departmentEntity); - scheduleFileEntity.setDepartmentEntity(departmentEntity); - } - - private void setFacultyEntity(final DepartmentEntity departmentEntity) { - final Long facultyId = departmentEntity.getFacultyId(); - final FacultyEntity facultyEntity = facultyRepository.getFacultyById(facultyId); - departmentEntity.setFacultyEntity(facultyEntity); + return scheduleFileInfoConverter.entityToDetailResponse(scheduleFileEntity); } @@ -151,15 +129,11 @@ private void checkBeforeGetFacultyId(final Long facultyId) throws SisNotExistExc */ private void ifDepartmentIsNotExistThrowNotExistException(final Long departmentId) throws SisNotExistException { - if (!departmentRepository.isDepartmentExist(departmentId)) { - DepartmentException.throwNotExistException(departmentId); - } + departmentOutService.ifDepartmentIsNotExistThrowNotExistException(departmentId); } private void ifFacultyIsNotExistThrowNotExistException(final Long facultyId) throws SisNotExistException { - if (!facultyRepository.isFacultyExist(facultyId)) { - FacultyException.throwNotExistException(facultyId); - } + facultyOutService.ifFacultyIsNotExistThrowNotExistException(facultyId); } private void ifFileIsExistThrowFileAlreadyExistException(final Long departmentId) throws SisAlreadyException { diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/schedule/lesson/model/dto/converter/LessonScheduleFileInfoConverter.java b/src/main/java/com/graduationproject/studentinformationsystem/university/schedule/lesson/model/dto/converter/LessonScheduleFileInfoConverter.java index 303475f2..71719d4d 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/schedule/lesson/model/dto/converter/LessonScheduleFileInfoConverter.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/schedule/lesson/model/dto/converter/LessonScheduleFileInfoConverter.java @@ -1,10 +1,13 @@ package com.graduationproject.studentinformationsystem.university.schedule.lesson.model.dto.converter; import com.graduationproject.studentinformationsystem.common.util.SisUtil; -import com.graduationproject.studentinformationsystem.university.department.model.dto.converter.DepartmentInfoConverter; +import com.graduationproject.studentinformationsystem.university.department.model.dto.response.DepartmentResponse; +import com.graduationproject.studentinformationsystem.university.department.service.DepartmentOutService; import com.graduationproject.studentinformationsystem.university.schedule.common.model.dto.response.ScheduleFileDetailResponse; import com.graduationproject.studentinformationsystem.university.schedule.common.model.dto.response.ScheduleFileResponse; import com.graduationproject.studentinformationsystem.university.schedule.common.model.entity.ScheduleFileEntity; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; import org.springframework.web.multipart.MultipartFile; import java.io.IOException; @@ -12,17 +15,18 @@ import java.util.Date; import java.util.List; +@Component +@RequiredArgsConstructor public class LessonScheduleFileInfoConverter { - private LessonScheduleFileInfoConverter() { - } + private final DepartmentOutService departmentOutService; - public static ScheduleFileEntity generateSaveEntity(final String fileId, - final MultipartFile document, - final String apiUrl, - final Long facultyId, - final Long departmentId, - final Long operationUserId) throws IOException { + public ScheduleFileEntity generateSaveEntity(final String fileId, + final MultipartFile document, + final String apiUrl, + final Long facultyId, + final Long departmentId, + final Long operationUserId) throws IOException { return ScheduleFileEntity.builder() .fileId(fileId) @@ -39,7 +43,7 @@ public static ScheduleFileEntity generateSaveEntity(final String fileId, .build(); } - public static ScheduleFileResponse entityToResponse(final ScheduleFileEntity scheduleFileEntity) throws IOException { + public ScheduleFileResponse entityToResponse(final ScheduleFileEntity scheduleFileEntity) throws IOException { return ScheduleFileResponse.builder() .fileName(scheduleFileEntity.getFileName()) .fileByte(scheduleFileEntity.getFileByte()) @@ -48,20 +52,23 @@ public static ScheduleFileResponse entityToResponse(final ScheduleFileEntity sch .build(); } - public static ScheduleFileDetailResponse entityToDetailResponse(final ScheduleFileEntity scheduleFileEntity) { + public ScheduleFileDetailResponse entityToDetailResponse(final ScheduleFileEntity scheduleFileEntity) { + + final DepartmentResponse departmentResponse = departmentOutService.getDepartmentResponse(scheduleFileEntity.getDepartmentId()); + return ScheduleFileDetailResponse.builder() .fileId(scheduleFileEntity.getFileId()) - .departmentResponse(DepartmentInfoConverter.entityToResponse(scheduleFileEntity.getDepartmentEntity())) .fileName(scheduleFileEntity.getFileName()) .fileType(scheduleFileEntity.getFileType()) .fileDownloadUrl(scheduleFileEntity.getApiUrl() + "/lesson-schedule-file/download/" + scheduleFileEntity.getFileId()) .fileViewUrl(scheduleFileEntity.getApiUrl() + "/lesson-schedule-file/view/" + scheduleFileEntity.getFileId()) .createdUserId(scheduleFileEntity.getCreatedUserId()) .createdDate(SisUtil.getFormattedDateTime(scheduleFileEntity.getCreatedDate())) + .departmentResponse(departmentResponse) .build(); } - public static List entitiesToResponses(final List scheduleFileEntities) { + public List entitiesToResponses(final List scheduleFileEntities) { List scheduleFileDetailResponses = new ArrayList<>(); scheduleFileEntities.forEach(scheduleFileEntity -> scheduleFileDetailResponses.add(entityToDetailResponse(scheduleFileEntity))); return scheduleFileDetailResponses; diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/schedule/lesson/service/impl/LessonScheduleFileServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/schedule/lesson/service/impl/LessonScheduleFileServiceImpl.java index 60f85309..20260f07 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/schedule/lesson/service/impl/LessonScheduleFileServiceImpl.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/schedule/lesson/service/impl/LessonScheduleFileServiceImpl.java @@ -5,12 +5,8 @@ import com.graduationproject.studentinformationsystem.common.util.exception.SisAlreadyException; import com.graduationproject.studentinformationsystem.common.util.exception.SisFileTypeException; import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; -import com.graduationproject.studentinformationsystem.university.department.model.entity.DepartmentEntity; -import com.graduationproject.studentinformationsystem.university.department.model.exception.DepartmentException; -import com.graduationproject.studentinformationsystem.university.department.repository.DepartmentRepository; -import com.graduationproject.studentinformationsystem.university.faculty.model.entity.FacultyEntity; -import com.graduationproject.studentinformationsystem.university.faculty.model.exception.FacultyException; -import com.graduationproject.studentinformationsystem.university.faculty.repository.FacultyRepository; +import com.graduationproject.studentinformationsystem.university.department.service.DepartmentOutService; +import com.graduationproject.studentinformationsystem.university.faculty.service.FacultyOutService; import com.graduationproject.studentinformationsystem.university.schedule.common.model.dto.response.ScheduleFileDetailResponse; import com.graduationproject.studentinformationsystem.university.schedule.common.model.dto.response.ScheduleFileResponse; import com.graduationproject.studentinformationsystem.university.schedule.common.model.entity.ScheduleFileEntity; @@ -29,10 +25,11 @@ @RequiredArgsConstructor public class LessonScheduleFileServiceImpl implements LessonScheduleFileService { - private final FacultyRepository facultyRepository; - private final DepartmentRepository departmentRepository; + private final FacultyOutService facultyOutService; + private final DepartmentOutService departmentOutService; private final LessonScheduleFileRepository scheduleFileRepository; + private final LessonScheduleFileInfoConverter scheduleFileInfoConverter; @Override public List getLessonScheduleFilesByFacultyId(final Long facultyId) @@ -69,7 +66,7 @@ public ScheduleFileDetailResponse saveLessonScheduleFile(final String apiUrl, checkBeforeSaving(facultyId, departmentId, document.getContentType()); final String fileId = SisUtil.generateRandomUUID(); - final ScheduleFileEntity scheduleFileEntity = LessonScheduleFileInfoConverter + final ScheduleFileEntity scheduleFileEntity = scheduleFileInfoConverter .generateSaveEntity(fileId, document, apiUrl, facultyId, departmentId, operationUserId); scheduleFileRepository.saveLessonScheduleFile(scheduleFileEntity); @@ -85,36 +82,17 @@ public void deleteLessonScheduleFileByDepartmentId(final Long departmentId) thro private ScheduleFileResponse getLessonScheduleFileResponse(final String fileId) throws IOException { final ScheduleFileEntity scheduleFileEntity = scheduleFileRepository.getLessonScheduleFileById(fileId); - return LessonScheduleFileInfoConverter.entityToResponse(scheduleFileEntity); + return scheduleFileInfoConverter.entityToResponse(scheduleFileEntity); } private List getLessonScheduleFilesDetailResponses(final Long facultyId) { final List scheduleFileEntities = scheduleFileRepository.getLessonScheduleFilesByFacultyId(facultyId); - setDepartmentEntities(scheduleFileEntities); - return LessonScheduleFileInfoConverter.entitiesToResponses(scheduleFileEntities); + return scheduleFileInfoConverter.entitiesToResponses(scheduleFileEntities); } private ScheduleFileDetailResponse getLessonScheduleFileDetailResponse(final Long departmentId) { final ScheduleFileEntity scheduleFileEntity = scheduleFileRepository.getLessonScheduleFileByDepartmentId(departmentId); - setDepartmentEntity(scheduleFileEntity); - return LessonScheduleFileInfoConverter.entityToDetailResponse(scheduleFileEntity); - } - - private void setDepartmentEntities(final List scheduleFileEntities) { - scheduleFileEntities.forEach(this::setDepartmentEntity); - } - - private void setDepartmentEntity(final ScheduleFileEntity scheduleFileEntity) { - final Long departmentId = scheduleFileEntity.getDepartmentId(); - final DepartmentEntity departmentEntity = departmentRepository.getDepartmentById(departmentId); - setFacultyEntity(departmentEntity); - scheduleFileEntity.setDepartmentEntity(departmentEntity); - } - - private void setFacultyEntity(final DepartmentEntity departmentEntity) { - final Long facultyId = departmentEntity.getFacultyId(); - final FacultyEntity facultyEntity = facultyRepository.getFacultyById(facultyId); - departmentEntity.setFacultyEntity(facultyEntity); + return scheduleFileInfoConverter.entityToDetailResponse(scheduleFileEntity); } @@ -150,16 +128,12 @@ private void checkBeforeGetFacultyId(final Long facultyId) throws SisNotExistExc * Throw Exceptions */ - private void ifDepartmentIsNotExistThrowNotExistException(final Long departmentId) throws SisNotExistException { - if (!departmentRepository.isDepartmentExist(departmentId)) { - DepartmentException.throwNotExistException(departmentId); - } + private void ifFacultyIsNotExistThrowNotExistException(final Long facultyId) throws SisNotExistException { + facultyOutService.ifFacultyIsNotExistThrowNotExistException(facultyId); } - private void ifFacultyIsNotExistThrowNotExistException(final Long facultyId) throws SisNotExistException { - if (!facultyRepository.isFacultyExist(facultyId)) { - FacultyException.throwNotExistException(facultyId); - } + private void ifDepartmentIsNotExistThrowNotExistException(final Long departmentId) throws SisNotExistException { + departmentOutService.ifDepartmentIsNotExistThrowNotExistException(departmentId); } private void ifFileIsExistThrowFileAlreadyExistException(final Long departmentId) throws SisAlreadyException { diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/student/model/dto/converter/StudentAcademicInfoConverter.java b/src/main/java/com/graduationproject/studentinformationsystem/university/student/model/dto/converter/StudentAcademicInfoConverter.java index aafc2840..b8647792 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/student/model/dto/converter/StudentAcademicInfoConverter.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/student/model/dto/converter/StudentAcademicInfoConverter.java @@ -2,25 +2,29 @@ import com.graduationproject.studentinformationsystem.common.model.dto.request.SisOperationInfoRequest; import com.graduationproject.studentinformationsystem.common.util.SisUtil; -import com.graduationproject.studentinformationsystem.university.department.model.dto.converter.DepartmentInfoConverter; +import com.graduationproject.studentinformationsystem.university.department.model.dto.response.DepartmentResponse; +import com.graduationproject.studentinformationsystem.university.department.service.DepartmentOutService; import com.graduationproject.studentinformationsystem.university.student.model.dto.request.*; import com.graduationproject.studentinformationsystem.university.student.model.dto.response.StudentAcademicInfoResponse; import com.graduationproject.studentinformationsystem.university.student.model.entity.StudentAcademicInfoEntity; import com.graduationproject.studentinformationsystem.university.student.model.enums.StudentStatus; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.Date; import java.util.List; +@Component +@RequiredArgsConstructor public class StudentAcademicInfoConverter { - private StudentAcademicInfoConverter() { - } + private final DepartmentOutService departmentOutService; - public static StudentAcademicInfoEntity generateSaveEntity(final Long studentId, - final String studentEmail, - final StudentAcademicInfoRequest academicInfoRequest, - final SisOperationInfoRequest operationInfoRequest) { + public StudentAcademicInfoEntity generateSaveEntity(final Long studentId, + final String studentEmail, + final StudentAcademicInfoRequest academicInfoRequest, + final SisOperationInfoRequest operationInfoRequest) { return StudentAcademicInfoEntity.builder() .studentId(studentId) @@ -35,8 +39,8 @@ public static StudentAcademicInfoEntity generateSaveEntity(final Long studentId, .build(); } - public static StudentAcademicInfoEntity generateUpdateEntity(final Long studentId, - final StudentAcademicInfoUpdateRequest academicInfoUpdateRequest) { + public StudentAcademicInfoEntity generateUpdateEntity(final Long studentId, + final StudentAcademicInfoUpdateRequest academicInfoUpdateRequest) { final StudentAcademicInfoRequest academicInfoRequest = academicInfoUpdateRequest.getAcademicInfoRequest(); final SisOperationInfoRequest operationInfoRequest = academicInfoUpdateRequest.getOperationInfoRequest(); @@ -51,7 +55,7 @@ public static StudentAcademicInfoEntity generateUpdateEntity(final Long studentI .build(); } - public static StudentAcademicInfoEntity generateDeleteEntity(final StudentDeleteRequest deleteRequest) { + public StudentAcademicInfoEntity generateDeleteEntity(final StudentDeleteRequest deleteRequest) { return StudentAcademicInfoEntity.builder() .studentId(deleteRequest.getStudentId()) .status(StudentStatus.DELETED) @@ -60,7 +64,7 @@ public static StudentAcademicInfoEntity generateDeleteEntity(final StudentDelete .build(); } - public static StudentAcademicInfoEntity generatePassiveEntity(final StudentPassivateRequest passivateRequest) { + public StudentAcademicInfoEntity generatePassiveEntity(final StudentPassivateRequest passivateRequest) { return StudentAcademicInfoEntity.builder() .studentId(passivateRequest.getStudentId()) .status(StudentStatus.PASSIVE) @@ -69,7 +73,7 @@ public static StudentAcademicInfoEntity generatePassiveEntity(final StudentPassi .build(); } - public static StudentAcademicInfoEntity generateActiveEntity(final StudentActivateRequest activateRequest) { + public StudentAcademicInfoEntity generateActiveEntity(final StudentActivateRequest activateRequest) { return StudentAcademicInfoEntity.builder() .studentId(activateRequest.getStudentId()) .status(StudentStatus.ACTIVE) @@ -78,7 +82,7 @@ public static StudentAcademicInfoEntity generateActiveEntity(final StudentActiva .build(); } - public static StudentAcademicInfoEntity generateGraduateEntity(final StudentGraduateRequest graduateRequest) { + public StudentAcademicInfoEntity generateGraduateEntity(final StudentGraduateRequest graduateRequest) { return StudentAcademicInfoEntity.builder() .studentId(graduateRequest.getStudentId()) .status(StudentStatus.GRADUATED) @@ -87,10 +91,12 @@ public static StudentAcademicInfoEntity generateGraduateEntity(final StudentGrad .build(); } - public static StudentAcademicInfoResponse entityToResponse(final StudentAcademicInfoEntity academicInfoEntity) { + public StudentAcademicInfoResponse entityToResponse(final StudentAcademicInfoEntity academicInfoEntity) { + + final DepartmentResponse departmentResponse = departmentOutService.getDepartmentResponse(academicInfoEntity.getDepartmentId()); + return StudentAcademicInfoResponse.builder() .studentId(academicInfoEntity.getStudentId()) - .departmentResponse(DepartmentInfoConverter.entityToResponse(academicInfoEntity.getDepartmentEntity())) .degree(academicInfoEntity.getDegree()) .classLevel(academicInfoEntity.getClassLevel()) .status(academicInfoEntity.getStatus()) @@ -99,10 +105,12 @@ public static StudentAcademicInfoResponse entityToResponse(final StudentAcademic .createdDate(SisUtil.getFormattedDateTime(academicInfoEntity.getCreatedDate())) .createdUserId(academicInfoEntity.getCreatedUserId()) .modifiedDate(SisUtil.getFormattedDateTime(academicInfoEntity.getModifiedDate())) - .modifiedUserId(academicInfoEntity.getModifiedUserId()).build(); + .modifiedUserId(academicInfoEntity.getModifiedUserId()) + .departmentResponse(departmentResponse) + .build(); } - public static List entitiesToResponses(final List academicInfoEntities) { + public List entitiesToResponses(final List academicInfoEntities) { List academicInfoResponses = new ArrayList<>(); academicInfoEntities.forEach(academicInfoEntity -> academicInfoResponses.add(entityToResponse(academicInfoEntity))); return academicInfoResponses; diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/student/model/dto/converter/StudentResponseConverter.java b/src/main/java/com/graduationproject/studentinformationsystem/university/student/model/dto/converter/StudentResponseConverter.java index 578ba287..86fae9f4 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/student/model/dto/converter/StudentResponseConverter.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/student/model/dto/converter/StudentResponseConverter.java @@ -17,14 +17,15 @@ public static StudentInfoResponse infoResponsesToResponse(final StudentAcademicI return StudentInfoResponse.builder() .studentId(academicInfoResponse.getStudentId()) - .departmentResponse(academicInfoResponse.getDepartmentResponse()) .degree(academicInfoResponse.getDegree()) .classLevel(academicInfoResponse.getClassLevel()) .name(personalInfoResponse.getName()) .surname(personalInfoResponse.getSurname()) .email(academicInfoResponse.getEmail()) .status(academicInfoResponse.getStatus()) - .registrationDate(academicInfoResponse.getRegistrationDate()).build(); + .registrationDate(academicInfoResponse.getRegistrationDate()) + .departmentResponse(academicInfoResponse.getDepartmentResponse()) + .build(); } public static List infoResponsesListToResponseList(final List academicInfoResponses, diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/student/model/entity/StudentAcademicInfoEntity.java b/src/main/java/com/graduationproject/studentinformationsystem/university/student/model/entity/StudentAcademicInfoEntity.java index 84fda030..7d70e51c 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/student/model/entity/StudentAcademicInfoEntity.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/student/model/entity/StudentAcademicInfoEntity.java @@ -1,12 +1,10 @@ package com.graduationproject.studentinformationsystem.university.student.model.entity; import com.graduationproject.studentinformationsystem.common.model.entity.SisBaseEntity; -import com.graduationproject.studentinformationsystem.university.department.model.entity.DepartmentEntity; import com.graduationproject.studentinformationsystem.university.student.model.enums.StudentClassLevel; import com.graduationproject.studentinformationsystem.university.student.model.enums.StudentDegree; import com.graduationproject.studentinformationsystem.university.student.model.enums.StudentStatus; import lombok.Getter; -import lombok.Setter; import lombok.experimental.SuperBuilder; import java.util.Date; @@ -22,7 +20,4 @@ public class StudentAcademicInfoEntity extends SisBaseEntity { private String email; private StudentStatus status; private Date registrationDate; - - @Setter - private DepartmentEntity departmentEntity; } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/student/service/impl/StudentAcademicInfoServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/student/service/impl/StudentAcademicInfoServiceImpl.java index 19652065..26231d4e 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/student/service/impl/StudentAcademicInfoServiceImpl.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/student/service/impl/StudentAcademicInfoServiceImpl.java @@ -1,10 +1,6 @@ package com.graduationproject.studentinformationsystem.university.student.service.impl; import com.graduationproject.studentinformationsystem.common.model.dto.request.SisOperationInfoRequest; -import com.graduationproject.studentinformationsystem.university.department.model.entity.DepartmentEntity; -import com.graduationproject.studentinformationsystem.university.department.repository.DepartmentRepository; -import com.graduationproject.studentinformationsystem.university.faculty.model.entity.FacultyEntity; -import com.graduationproject.studentinformationsystem.university.faculty.repository.FacultyRepository; import com.graduationproject.studentinformationsystem.university.student.model.dto.converter.StudentAcademicInfoConverter; import com.graduationproject.studentinformationsystem.university.student.model.dto.request.*; import com.graduationproject.studentinformationsystem.university.student.model.dto.response.StudentAcademicInfoResponse; @@ -21,16 +17,13 @@ @RequiredArgsConstructor public class StudentAcademicInfoServiceImpl implements StudentAcademicInfoService { - private final FacultyRepository facultyRepository; - private final DepartmentRepository departmentRepository; - private final StudentAcademicInfoRepository academicInfoRepository; + private final StudentAcademicInfoConverter academicInfoConverter; @Override public List getAllStudentAcademicInfosByStatus(StudentStatus status) { final List academicInfoEntities = academicInfoRepository.getAllStudentAcademicInfosByStatus(status); - setDepartmentEntities(academicInfoEntities); - return StudentAcademicInfoConverter.entitiesToResponses(academicInfoEntities); + return academicInfoConverter.entitiesToResponses(academicInfoEntities); } @Override @@ -44,8 +37,9 @@ public void saveStudentAcademicInfo(Long studentId, StudentAcademicInfoRequest academicInfoRequest, SisOperationInfoRequest operationInfoRequest) { - StudentAcademicInfoEntity academicInfoEntity = StudentAcademicInfoConverter + StudentAcademicInfoEntity academicInfoEntity = academicInfoConverter .generateSaveEntity(studentId, studentEmail, academicInfoRequest, operationInfoRequest); + academicInfoRepository.saveStudentAcademicInfo(academicInfoEntity); } @@ -53,8 +47,9 @@ public void saveStudentAcademicInfo(Long studentId, public StudentAcademicInfoResponse updateStudentAcademicInfo(Long studentId, StudentAcademicInfoUpdateRequest academicInfoUpdateRequest) { - StudentAcademicInfoEntity academicInfoEntity = StudentAcademicInfoConverter + StudentAcademicInfoEntity academicInfoEntity = academicInfoConverter .generateUpdateEntity(studentId, academicInfoUpdateRequest); + academicInfoRepository.updateStudentAcademicInfo(academicInfoEntity); return getStudentAcademicInfoResponse(studentId); @@ -62,25 +57,25 @@ public StudentAcademicInfoResponse updateStudentAcademicInfo(Long studentId, @Override public void deleteStudentAcademicInfo(StudentDeleteRequest deleteRequest) { - StudentAcademicInfoEntity academicInfoEntity = StudentAcademicInfoConverter.generateDeleteEntity(deleteRequest); + StudentAcademicInfoEntity academicInfoEntity = academicInfoConverter.generateDeleteEntity(deleteRequest); academicInfoRepository.updateStudentAcademicInfoStatus(academicInfoEntity); } @Override public void passivateStudentAcademicInfo(StudentPassivateRequest passivateRequest) { - StudentAcademicInfoEntity academicInfoEntity = StudentAcademicInfoConverter.generatePassiveEntity(passivateRequest); + StudentAcademicInfoEntity academicInfoEntity = academicInfoConverter.generatePassiveEntity(passivateRequest); academicInfoRepository.updateStudentAcademicInfoStatus(academicInfoEntity); } @Override public void activateStudentAcademicInfo(StudentActivateRequest activateRequest) { - StudentAcademicInfoEntity academicInfoEntity = StudentAcademicInfoConverter.generateActiveEntity(activateRequest); + StudentAcademicInfoEntity academicInfoEntity = academicInfoConverter.generateActiveEntity(activateRequest); academicInfoRepository.updateStudentAcademicInfoStatus(academicInfoEntity); } @Override public void graduateStudentAcademicInfo(StudentGraduateRequest graduateRequest) { - StudentAcademicInfoEntity academicInfoEntity = StudentAcademicInfoConverter.generateGraduateEntity(graduateRequest); + StudentAcademicInfoEntity academicInfoEntity = academicInfoConverter.generateGraduateEntity(graduateRequest); academicInfoRepository.updateStudentAcademicInfoStatus(academicInfoEntity); } @@ -114,26 +109,9 @@ public boolean isStudentGraduated(Long studentId) { return academicInfoRepository.isStudentGraduated(studentId); } + private StudentAcademicInfoResponse getStudentAcademicInfoResponse(Long studentId) { final StudentAcademicInfoEntity academicInfoEntity = academicInfoRepository.getStudentAcademicInfoById(studentId); - setDepartmentEntity(academicInfoEntity); - return StudentAcademicInfoConverter.entityToResponse(academicInfoEntity); - } - - private void setDepartmentEntity(final StudentAcademicInfoEntity academicInfoEntity) { - final Long departmentId = academicInfoEntity.getDepartmentId(); - final DepartmentEntity departmentEntity = departmentRepository.getDepartmentById(departmentId); - setFacultyEntity(departmentEntity); - academicInfoEntity.setDepartmentEntity(departmentEntity); - } - - private void setDepartmentEntities(final List academicInfoEntities) { - academicInfoEntities.forEach(this::setDepartmentEntity); - } - - private void setFacultyEntity(final DepartmentEntity departmentEntity) { - final Long facultyId = departmentEntity.getFacultyId(); - final FacultyEntity facultyEntity = facultyRepository.getFacultyById(facultyId); - departmentEntity.setFacultyEntity(facultyEntity); + return academicInfoConverter.entityToResponse(academicInfoEntity); } } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/student/service/impl/StudentServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/student/service/impl/StudentServiceImpl.java index b650261d..225bfa9e 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/student/service/impl/StudentServiceImpl.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/student/service/impl/StudentServiceImpl.java @@ -3,8 +3,7 @@ import com.graduationproject.studentinformationsystem.common.model.dto.request.SisOperationInfoRequest; import com.graduationproject.studentinformationsystem.common.util.exception.SisAlreadyException; import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; -import com.graduationproject.studentinformationsystem.university.department.model.exception.DepartmentException; -import com.graduationproject.studentinformationsystem.university.department.repository.DepartmentRepository; +import com.graduationproject.studentinformationsystem.university.department.service.DepartmentOutService; import com.graduationproject.studentinformationsystem.university.mail.service.StudentMailService; import com.graduationproject.studentinformationsystem.university.student.model.dto.converter.StudentInfoResponseConverter; import com.graduationproject.studentinformationsystem.university.student.model.dto.converter.StudentResponseConverter; @@ -28,7 +27,7 @@ @RequiredArgsConstructor public class StudentServiceImpl implements StudentService { - private final DepartmentRepository departmentRepository; + private final DepartmentOutService departmentOutService; private final StudentAcademicInfoService academicInfoService; private final StudentPersonalInfoService personalInfoService; @@ -153,14 +152,14 @@ private StudentInfoResponse getStudentResponse(final Long studentId) { */ private void checkBeforeSaving(final StudentSaveRequest studentInfoRequest) throws SisNotExistException { - ifDepartmentIdIsNotExistThrowNotExistException(studentInfoRequest.getAcademicInfoRequest().getDepartmentId()); + ifDepartmentIsNotExistThrowNotExistException(studentInfoRequest.getAcademicInfoRequest().getDepartmentId()); } private void checkBeforeUpdatingAcademicInfo(final Long studentId, final StudentAcademicInfoUpdateRequest academicInfoUpdateRequest) throws SisNotExistException { ifStudentIsNotExistThrowNotExistException(studentId); - ifDepartmentIdIsNotExistThrowNotExistException(academicInfoUpdateRequest.getAcademicInfoRequest().getDepartmentId()); + ifDepartmentIsNotExistThrowNotExistException(academicInfoUpdateRequest.getAcademicInfoRequest().getDepartmentId()); } private void checkBeforeUpdatingPersonalInfo(final Long studentId) throws SisNotExistException { @@ -199,18 +198,16 @@ private void checkBeforeGraduating(final Long studentId) throws SisNotExistExcep * Throw Exceptions */ + private void ifDepartmentIsNotExistThrowNotExistException(final Long departmentId) throws SisNotExistException { + departmentOutService.ifDepartmentIsNotExistThrowNotExistException(departmentId); + } + private void ifStudentIsNotExistThrowNotExistException(final Long studentId) throws SisNotExistException { if (!academicInfoService.isStudentExist(studentId)) { StudentException.throwNotExistException(studentId); } } - private void ifDepartmentIdIsNotExistThrowNotExistException(final Long departmentId) throws SisNotExistException { - if (!departmentRepository.isDepartmentExist(departmentId)) { - DepartmentException.throwNotExistException(departmentId); - } - } - private void ifStudentIsAlreadyDeletedThrowAlreadyException(final Long studentId) throws SisAlreadyException { if (academicInfoService.isStudentDeleted(studentId)) { StudentException.throwAlreadyDeletedException(studentId); diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/model/dto/converter/TeacherAcademicInfoConverter.java b/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/model/dto/converter/TeacherAcademicInfoConverter.java index cfb964b0..b21791db 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/model/dto/converter/TeacherAcademicInfoConverter.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/model/dto/converter/TeacherAcademicInfoConverter.java @@ -2,25 +2,29 @@ import com.graduationproject.studentinformationsystem.common.model.dto.request.SisOperationInfoRequest; import com.graduationproject.studentinformationsystem.common.util.SisUtil; -import com.graduationproject.studentinformationsystem.university.department.model.dto.converter.DepartmentInfoConverter; +import com.graduationproject.studentinformationsystem.university.department.model.dto.response.DepartmentResponse; +import com.graduationproject.studentinformationsystem.university.department.service.DepartmentOutService; import com.graduationproject.studentinformationsystem.university.teacher.model.dto.request.*; import com.graduationproject.studentinformationsystem.university.teacher.model.dto.response.TeacherAcademicInfoResponse; import com.graduationproject.studentinformationsystem.university.teacher.model.entity.TeacherAcademicInfoEntity; import com.graduationproject.studentinformationsystem.university.teacher.model.enums.TeacherStatus; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; import java.util.ArrayList; import java.util.Date; import java.util.List; +@Component +@RequiredArgsConstructor public class TeacherAcademicInfoConverter { - private TeacherAcademicInfoConverter() { - } + private final DepartmentOutService departmentOutService; - public static TeacherAcademicInfoEntity generateSaveEntity(final Long teacherId, - final String teacherEmail, - final TeacherAcademicInfoRequest academicInfoRequest, - final SisOperationInfoRequest operationInfoRequest) { + public TeacherAcademicInfoEntity generateSaveEntity(final Long teacherId, + final String teacherEmail, + final TeacherAcademicInfoRequest academicInfoRequest, + final SisOperationInfoRequest operationInfoRequest) { return TeacherAcademicInfoEntity.builder() .teacherId(teacherId) @@ -37,8 +41,8 @@ public static TeacherAcademicInfoEntity generateSaveEntity(final Long teacherId, .build(); } - public static TeacherAcademicInfoEntity generateUpdateEntity(final Long teacherId, - final TeacherAcademicInfoUpdateRequest academicInfoUpdateRequest) { + public TeacherAcademicInfoEntity generateUpdateEntity(final Long teacherId, + final TeacherAcademicInfoUpdateRequest academicInfoUpdateRequest) { final TeacherAcademicInfoRequest academicInfoRequest = academicInfoUpdateRequest.getAcademicInfoRequest(); final SisOperationInfoRequest operationInfoRequest = academicInfoUpdateRequest.getOperationInfoRequest(); @@ -55,7 +59,7 @@ public static TeacherAcademicInfoEntity generateUpdateEntity(final Long teacherI .build(); } - public static TeacherAcademicInfoEntity generateDeleteEntity(final TeacherDeleteRequest deleteRequest) { + public TeacherAcademicInfoEntity generateDeleteEntity(final TeacherDeleteRequest deleteRequest) { return TeacherAcademicInfoEntity.builder() .teacherId(deleteRequest.getTeacherId()) .status(TeacherStatus.DELETED) @@ -64,7 +68,7 @@ public static TeacherAcademicInfoEntity generateDeleteEntity(final TeacherDelete .build(); } - public static TeacherAcademicInfoEntity generatePassiveEntity(final TeacherPassivateRequest passivateRequest) { + public TeacherAcademicInfoEntity generatePassiveEntity(final TeacherPassivateRequest passivateRequest) { return TeacherAcademicInfoEntity.builder() .teacherId(passivateRequest.getTeacherId()) .status(TeacherStatus.PASSIVE) @@ -73,7 +77,7 @@ public static TeacherAcademicInfoEntity generatePassiveEntity(final TeacherPassi .build(); } - public static TeacherAcademicInfoEntity generateActiveEntity(final TeacherActivateRequest activateRequest) { + public TeacherAcademicInfoEntity generateActiveEntity(final TeacherActivateRequest activateRequest) { return TeacherAcademicInfoEntity.builder() .teacherId(activateRequest.getTeacherId()) .status(TeacherStatus.ACTIVE) @@ -82,10 +86,12 @@ public static TeacherAcademicInfoEntity generateActiveEntity(final TeacherActiva .build(); } - public static TeacherAcademicInfoResponse entityToResponse(final TeacherAcademicInfoEntity academicInfoEntity) { + public TeacherAcademicInfoResponse entityToResponse(final TeacherAcademicInfoEntity academicInfoEntity) { + + final DepartmentResponse departmentResponse = departmentOutService.getDepartmentResponse(academicInfoEntity.getDepartmentId()); + return TeacherAcademicInfoResponse.builder() .teacherId(academicInfoEntity.getTeacherId()) - .departmentResponse(DepartmentInfoConverter.entityToResponse(academicInfoEntity.getDepartmentEntity())) .degree(academicInfoEntity.getDegree()) .role(academicInfoEntity.getRole()) .fieldOfStudy(academicInfoEntity.getFieldOfStudy()) @@ -96,10 +102,12 @@ public static TeacherAcademicInfoResponse entityToResponse(final TeacherAcademic .createdUserId(academicInfoEntity.getCreatedUserId()) .createdDate(SisUtil.getFormattedDateTime(academicInfoEntity.getCreatedDate())) .modifiedUserId(academicInfoEntity.getModifiedUserId()) - .modifiedDate(SisUtil.getFormattedDateTime(academicInfoEntity.getModifiedDate())).build(); + .modifiedDate(SisUtil.getFormattedDateTime(academicInfoEntity.getModifiedDate())) + .departmentResponse(departmentResponse) + .build(); } - public static List entitiesToResponses(final List academicInfoEntities) { + public List entitiesToResponses(final List academicInfoEntities) { List academicInfoResponses = new ArrayList<>(); academicInfoEntities.forEach(academicInfoEntity -> academicInfoResponses.add(entityToResponse(academicInfoEntity))); return academicInfoResponses; diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/model/entity/TeacherAcademicInfoEntity.java b/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/model/entity/TeacherAcademicInfoEntity.java index cee1073a..2fffbbf2 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/model/entity/TeacherAcademicInfoEntity.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/model/entity/TeacherAcademicInfoEntity.java @@ -1,12 +1,10 @@ package com.graduationproject.studentinformationsystem.university.teacher.model.entity; import com.graduationproject.studentinformationsystem.common.model.entity.SisBaseEntity; -import com.graduationproject.studentinformationsystem.university.department.model.entity.DepartmentEntity; import com.graduationproject.studentinformationsystem.university.teacher.model.enums.TeacherDegree; import com.graduationproject.studentinformationsystem.university.teacher.model.enums.TeacherRole; import com.graduationproject.studentinformationsystem.university.teacher.model.enums.TeacherStatus; import lombok.Getter; -import lombok.Setter; import lombok.experimental.SuperBuilder; import java.util.Date; @@ -24,7 +22,4 @@ public class TeacherAcademicInfoEntity extends SisBaseEntity { private String email; private TeacherStatus status; private Date registrationDate; - - @Setter - private DepartmentEntity departmentEntity; } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/TeacherOutService.java b/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/TeacherOutService.java new file mode 100644 index 00000000..75a124a9 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/TeacherOutService.java @@ -0,0 +1,8 @@ +package com.graduationproject.studentinformationsystem.university.teacher.service; + +import com.graduationproject.studentinformationsystem.university.teacher.model.dto.response.TeacherAcademicInfoResponse; + +public interface TeacherOutService { + + TeacherAcademicInfoResponse getTeacherAcademicInfoResponse(Long teacherId); +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/impl/TeacherAcademicInfoServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/impl/TeacherAcademicInfoServiceImpl.java index e751c2b8..315ffc5d 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/impl/TeacherAcademicInfoServiceImpl.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/impl/TeacherAcademicInfoServiceImpl.java @@ -1,10 +1,6 @@ package com.graduationproject.studentinformationsystem.university.teacher.service.impl; import com.graduationproject.studentinformationsystem.common.model.dto.request.SisOperationInfoRequest; -import com.graduationproject.studentinformationsystem.university.department.model.entity.DepartmentEntity; -import com.graduationproject.studentinformationsystem.university.department.repository.DepartmentRepository; -import com.graduationproject.studentinformationsystem.university.faculty.model.entity.FacultyEntity; -import com.graduationproject.studentinformationsystem.university.faculty.repository.FacultyRepository; import com.graduationproject.studentinformationsystem.university.teacher.model.dto.converter.TeacherAcademicInfoConverter; import com.graduationproject.studentinformationsystem.university.teacher.model.dto.request.*; import com.graduationproject.studentinformationsystem.university.teacher.model.dto.response.TeacherAcademicInfoResponse; @@ -21,16 +17,13 @@ @RequiredArgsConstructor public class TeacherAcademicInfoServiceImpl implements TeacherAcademicInfoService { - private final FacultyRepository facultyRepository; - private final DepartmentRepository departmentRepository; - private final TeacherAcademicInfoRepository academicInfoRepository; + private final TeacherAcademicInfoConverter academicInfoConverter; @Override public List getAllTeacherAcademicInfosByStatus(final TeacherStatus status) { final List academicInfoEntities = academicInfoRepository.getAllTeacherAcademicInfosByStatus(status); - setDepartmentEntities(academicInfoEntities); - return TeacherAcademicInfoConverter.entitiesToResponses(academicInfoEntities); + return academicInfoConverter.entitiesToResponses(academicInfoEntities); } @Override @@ -44,7 +37,7 @@ public void saveTeacherAcademicInfo(final Long teacherId, final TeacherAcademicInfoRequest academicInfoRequest, final SisOperationInfoRequest operationInfoRequest) { - final TeacherAcademicInfoEntity academicInfoEntity = TeacherAcademicInfoConverter + final TeacherAcademicInfoEntity academicInfoEntity = academicInfoConverter .generateSaveEntity(teacherId, teacherEmail, academicInfoRequest, operationInfoRequest); academicInfoRepository.saveTeacherAcademicInfo(academicInfoEntity); @@ -54,7 +47,7 @@ public void saveTeacherAcademicInfo(final Long teacherId, public TeacherAcademicInfoResponse updateTeacherAcademicInfo(final Long teacherId, final TeacherAcademicInfoUpdateRequest academicInfoUpdateRequest) { - final TeacherAcademicInfoEntity academicInfoEntity = TeacherAcademicInfoConverter + final TeacherAcademicInfoEntity academicInfoEntity = academicInfoConverter .generateUpdateEntity(teacherId, academicInfoUpdateRequest); academicInfoRepository.updateTeacherAcademicInfo(academicInfoEntity); @@ -64,19 +57,19 @@ public TeacherAcademicInfoResponse updateTeacherAcademicInfo(final Long teacherI @Override public void deleteTeacherAcademicInfo(final TeacherDeleteRequest deleteRequest) { - final TeacherAcademicInfoEntity academicInfoEntity = TeacherAcademicInfoConverter.generateDeleteEntity(deleteRequest); + final TeacherAcademicInfoEntity academicInfoEntity = academicInfoConverter.generateDeleteEntity(deleteRequest); academicInfoRepository.updateTeacherAcademicInfoStatus(academicInfoEntity); } @Override public void passivateTeacherAcademicInfo(final TeacherPassivateRequest passivateRequest) { - final TeacherAcademicInfoEntity academicInfoEntity = TeacherAcademicInfoConverter.generatePassiveEntity(passivateRequest); + final TeacherAcademicInfoEntity academicInfoEntity = academicInfoConverter.generatePassiveEntity(passivateRequest); academicInfoRepository.updateTeacherAcademicInfoStatus(academicInfoEntity); } @Override public void activateTeacherAcademicInfo(final TeacherActivateRequest activateRequest) { - final TeacherAcademicInfoEntity academicInfoEntity = TeacherAcademicInfoConverter.generateActiveEntity(activateRequest); + final TeacherAcademicInfoEntity academicInfoEntity = academicInfoConverter.generateActiveEntity(activateRequest); academicInfoRepository.updateTeacherAcademicInfoStatus(academicInfoEntity); } @@ -108,24 +101,6 @@ public boolean isTeacherActive(final Long teacherId) { private TeacherAcademicInfoResponse getTeacherAcademicInfoResponse(final Long teacherId) { final TeacherAcademicInfoEntity academicInfoEntity = academicInfoRepository.getTeacherAcademicInfoById(teacherId); - setDepartmentEntity(academicInfoEntity); - return TeacherAcademicInfoConverter.entityToResponse(academicInfoEntity); - } - - private void setDepartmentEntity(final TeacherAcademicInfoEntity academicInfoEntity) { - final Long departmentId = academicInfoEntity.getDepartmentId(); - final DepartmentEntity departmentEntity = departmentRepository.getDepartmentById(departmentId); - setFacultyEntity(departmentEntity); - academicInfoEntity.setDepartmentEntity(departmentEntity); - } - - private void setDepartmentEntities(final List academicInfoEntities) { - academicInfoEntities.forEach(this::setDepartmentEntity); - } - - private void setFacultyEntity(final DepartmentEntity departmentEntity) { - final Long facultyId = departmentEntity.getFacultyId(); - final FacultyEntity facultyEntity = facultyRepository.getFacultyById(facultyId); - departmentEntity.setFacultyEntity(facultyEntity); + return academicInfoConverter.entityToResponse(academicInfoEntity); } } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/impl/TeacherOutServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/impl/TeacherOutServiceImpl.java new file mode 100644 index 00000000..9fb2bb54 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/impl/TeacherOutServiceImpl.java @@ -0,0 +1,23 @@ +package com.graduationproject.studentinformationsystem.university.teacher.service.impl; + +import com.graduationproject.studentinformationsystem.university.teacher.model.dto.converter.TeacherAcademicInfoConverter; +import com.graduationproject.studentinformationsystem.university.teacher.model.dto.response.TeacherAcademicInfoResponse; +import com.graduationproject.studentinformationsystem.university.teacher.model.entity.TeacherAcademicInfoEntity; +import com.graduationproject.studentinformationsystem.university.teacher.repository.TeacherAcademicInfoRepository; +import com.graduationproject.studentinformationsystem.university.teacher.service.TeacherOutService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class TeacherOutServiceImpl implements TeacherOutService { + + private final TeacherAcademicInfoRepository academicInfoRepository; + private final TeacherAcademicInfoConverter academicInfoConverter; + + @Override + public TeacherAcademicInfoResponse getTeacherAcademicInfoResponse(Long teacherId) { + final TeacherAcademicInfoEntity entity = academicInfoRepository.getTeacherAcademicInfoById(teacherId); + return academicInfoConverter.entityToResponse(entity); + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/impl/TeacherServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/impl/TeacherServiceImpl.java index bcd36ed2..a29f309f 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/impl/TeacherServiceImpl.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/impl/TeacherServiceImpl.java @@ -139,14 +139,14 @@ private TeacherInfoResponse getTeacherResponse(final Long teacherId) { */ private void checkBeforeSaving(final TeacherSaveRequest saveRequest) { - ifDepartmentIdIsNotExistThrowNotExistException(saveRequest.getAcademicInfoRequest().getDepartmentId()); + ifDepartmentIsNotExistThrowNotExistException(saveRequest.getAcademicInfoRequest().getDepartmentId()); } private void checkBeforeUpdatingAcademicInfo(final Long teacherId, final TeacherAcademicInfoUpdateRequest academicInfoUpdateRequest) throws SisNotExistException { ifTeacherIsNotExistThrowNotExistException(teacherId); - ifDepartmentIdIsNotExistThrowNotExistException(academicInfoUpdateRequest.getAcademicInfoRequest().getDepartmentId()); + ifDepartmentIsNotExistThrowNotExistException(academicInfoUpdateRequest.getAcademicInfoRequest().getDepartmentId()); } private void checkBeforeUpdatingPersonalInfo(final Long teacherId) throws SisNotExistException { @@ -181,8 +181,8 @@ private void ifTeacherIsNotExistThrowNotExistException(final Long teacherId) thr } } - private void ifDepartmentIdIsNotExistThrowNotExistException(final Long departmentId) { - // TODO: ifDepartmentIdIsNotExistThrowNotExistException + private void ifDepartmentIsNotExistThrowNotExistException(final Long departmentId) { + // TODO: ifDepartmentIsNotExistThrowNotExistException // if (!departmentService.isDepartmentExist(teacherId)) { // SisException.throwNotExistException(); // } From 68fcd58e49d366d1cda5e8f767211d81e3ad0ac0 Mon Sep 17 00:00:00 2001 From: Agit Rubar Demir <61833677+agitrubard@users.noreply.github.com> Date: Fri, 18 Feb 2022 11:26:05 +0300 Subject: [PATCH 04/13] Department API Res Fix | SIS-110 (#57) * SisUtil/integerToBoolean Method Has Been Updated with BooleanUtils Class * booleanToInteger Method Has Been Added to SisUtil Class & DepartmentResponse/isTherePreparatoryClass Field Type Has Been Updated to Integer --- .../common/util/SisUtil.java | 12 +++++++----- .../model/dto/converter/DepartmentInfoConverter.java | 2 +- .../model/dto/response/DepartmentResponse.java | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/graduationproject/studentinformationsystem/common/util/SisUtil.java b/src/main/java/com/graduationproject/studentinformationsystem/common/util/SisUtil.java index 5b23b9c7..881fc3a7 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/common/util/SisUtil.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/common/util/SisUtil.java @@ -1,5 +1,7 @@ package com.graduationproject.studentinformationsystem.common.util; +import org.apache.commons.lang3.BooleanUtils; + import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -96,10 +98,10 @@ public static boolean isNotExistIdInIdList(final Long id, final List ids) } public static boolean integerToBoolean(final Integer integer) { - return switch (integer) { - case 1 -> true; - case 0 -> false; - default -> throw new IndexOutOfBoundsException(); - }; + return BooleanUtils.toBooleanObject(integer); + } + + public static Integer booleanToInteger(final Boolean bool) { + return BooleanUtils.toIntegerObject(bool); } } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/department/model/dto/converter/DepartmentInfoConverter.java b/src/main/java/com/graduationproject/studentinformationsystem/university/department/model/dto/converter/DepartmentInfoConverter.java index 5a20dbd6..587bbea6 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/department/model/dto/converter/DepartmentInfoConverter.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/department/model/dto/converter/DepartmentInfoConverter.java @@ -93,7 +93,7 @@ public DepartmentResponse entityToResponse(final DepartmentEntity departmentEnti .name(departmentEntity.getName()) .status(departmentEntity.getStatus()) .totalClassLevel(departmentEntity.getTotalClassLevel()) - .isTherePreparatoryClass(departmentEntity.getIsTherePreparatoryClass()) + .isTherePreparatoryClass(SisUtil.booleanToInteger(departmentEntity.getIsTherePreparatoryClass())) .createdUserId(departmentEntity.getCreatedUserId()) .createdDate(SisUtil.getFormattedDateTime(departmentEntity.getCreatedDate())) .modifiedUserId(departmentEntity.getModifiedUserId()) diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/department/model/dto/response/DepartmentResponse.java b/src/main/java/com/graduationproject/studentinformationsystem/university/department/model/dto/response/DepartmentResponse.java index 1db52d38..d209478d 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/department/model/dto/response/DepartmentResponse.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/department/model/dto/response/DepartmentResponse.java @@ -14,7 +14,7 @@ public class DepartmentResponse extends SisBaseResponse { private String name; private DepartmentStatus status; private Integer totalClassLevel; - private Boolean isTherePreparatoryClass; + private Integer isTherePreparatoryClass; private FacultyResponse facultyResponse; } From 8c87201a839590057ad2b86c6f7bca239e4db112 Mon Sep 17 00:00:00 2001 From: Agit Rubar Demir <61833677+agitrubard@users.noreply.github.com> Date: Fri, 18 Feb 2022 12:18:37 +0300 Subject: [PATCH 05/13] Teacher Lesson Res Update | SIS-107 (#58) * TeacherOutService Classes Have Been Updated * TeacherLessonResponse and TeacherLessonInfoConverter Classes Have Been Refactored --- .../converter/TeacherLessonInfoConverter.java | 6 +++--- .../dto/response/TeacherLessonResponse.java | 4 ++-- .../teacher/service/TeacherOutService.java | 4 ++-- .../service/impl/TeacherOutServiceImpl.java | 19 +++++++++++-------- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/model/dto/converter/TeacherLessonInfoConverter.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/model/dto/converter/TeacherLessonInfoConverter.java index 4965ed55..9911378c 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/model/dto/converter/TeacherLessonInfoConverter.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/model/dto/converter/TeacherLessonInfoConverter.java @@ -11,7 +11,7 @@ import com.graduationproject.studentinformationsystem.university.lesson.teacher.model.entity.TeacherLessonDeleteEntity; import com.graduationproject.studentinformationsystem.university.lesson.teacher.model.entity.TeacherLessonEntity; import com.graduationproject.studentinformationsystem.university.lesson.teacher.model.entity.TeacherLessonSaveEntity; -import com.graduationproject.studentinformationsystem.university.teacher.model.dto.response.TeacherAcademicInfoResponse; +import com.graduationproject.studentinformationsystem.university.teacher.model.dto.response.TeacherInfoResponse; import com.graduationproject.studentinformationsystem.university.teacher.service.TeacherOutService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; @@ -50,14 +50,14 @@ public TeacherLessonDeleteEntity generateDeleteEntity(final TeacherLessonDeleteR public TeacherLessonResponse entityToResponse(final TeacherLessonEntity teacherLessonEntity) { - final TeacherAcademicInfoResponse teacherAcademicInfoResponse = teacherOutService.getTeacherAcademicInfoResponse(teacherLessonEntity.getTeacherId()); + final TeacherInfoResponse teacherInfoResponse = teacherOutService.getTeacherInfoResponse(teacherLessonEntity.getTeacherId()); final LessonResponse lessonResponse = lessonOutService.getLessonResponse(teacherLessonEntity.getLessonId()); return TeacherLessonResponse.builder() .createdUserId(teacherLessonEntity.getCreatedUserId()) .createdDate(SisUtil.getFormattedDateTime(teacherLessonEntity.getCreatedDate())) .lessonResponse(lessonResponse) - .teacherAcademicInfoResponse(teacherAcademicInfoResponse).build(); + .teacherInfoResponse(teacherInfoResponse).build(); } public List entitiesToResponses(final List lessonEntities) { diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/model/dto/response/TeacherLessonResponse.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/model/dto/response/TeacherLessonResponse.java index 7ef1f65d..685ed8ef 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/model/dto/response/TeacherLessonResponse.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/model/dto/response/TeacherLessonResponse.java @@ -1,7 +1,7 @@ package com.graduationproject.studentinformationsystem.university.lesson.teacher.model.dto.response; import com.graduationproject.studentinformationsystem.university.lesson.common.model.dto.response.LessonResponse; -import com.graduationproject.studentinformationsystem.university.teacher.model.dto.response.TeacherAcademicInfoResponse; +import com.graduationproject.studentinformationsystem.university.teacher.model.dto.response.TeacherInfoResponse; import lombok.Getter; import lombok.experimental.SuperBuilder; @@ -13,5 +13,5 @@ public class TeacherLessonResponse { private String createdDate; private LessonResponse lessonResponse; - private TeacherAcademicInfoResponse teacherAcademicInfoResponse; + private TeacherInfoResponse teacherInfoResponse; } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/TeacherOutService.java b/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/TeacherOutService.java index 75a124a9..39b9fa86 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/TeacherOutService.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/TeacherOutService.java @@ -1,8 +1,8 @@ package com.graduationproject.studentinformationsystem.university.teacher.service; -import com.graduationproject.studentinformationsystem.university.teacher.model.dto.response.TeacherAcademicInfoResponse; +import com.graduationproject.studentinformationsystem.university.teacher.model.dto.response.TeacherInfoResponse; public interface TeacherOutService { - TeacherAcademicInfoResponse getTeacherAcademicInfoResponse(Long teacherId); + TeacherInfoResponse getTeacherInfoResponse(Long teacherId); } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/impl/TeacherOutServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/impl/TeacherOutServiceImpl.java index 9fb2bb54..eda7bb41 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/impl/TeacherOutServiceImpl.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/impl/TeacherOutServiceImpl.java @@ -1,10 +1,12 @@ package com.graduationproject.studentinformationsystem.university.teacher.service.impl; -import com.graduationproject.studentinformationsystem.university.teacher.model.dto.converter.TeacherAcademicInfoConverter; +import com.graduationproject.studentinformationsystem.university.teacher.model.dto.converter.TeacherResponseConverter; import com.graduationproject.studentinformationsystem.university.teacher.model.dto.response.TeacherAcademicInfoResponse; -import com.graduationproject.studentinformationsystem.university.teacher.model.entity.TeacherAcademicInfoEntity; -import com.graduationproject.studentinformationsystem.university.teacher.repository.TeacherAcademicInfoRepository; +import com.graduationproject.studentinformationsystem.university.teacher.model.dto.response.TeacherInfoResponse; +import com.graduationproject.studentinformationsystem.university.teacher.model.dto.response.TeacherPersonalInfoResponse; +import com.graduationproject.studentinformationsystem.university.teacher.service.TeacherAcademicInfoService; import com.graduationproject.studentinformationsystem.university.teacher.service.TeacherOutService; +import com.graduationproject.studentinformationsystem.university.teacher.service.TeacherPersonalInfoService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -12,12 +14,13 @@ @RequiredArgsConstructor public class TeacherOutServiceImpl implements TeacherOutService { - private final TeacherAcademicInfoRepository academicInfoRepository; - private final TeacherAcademicInfoConverter academicInfoConverter; + private final TeacherAcademicInfoService academicInfoService; + private final TeacherPersonalInfoService personalInfoService; @Override - public TeacherAcademicInfoResponse getTeacherAcademicInfoResponse(Long teacherId) { - final TeacherAcademicInfoEntity entity = academicInfoRepository.getTeacherAcademicInfoById(teacherId); - return academicInfoConverter.entityToResponse(entity); + public TeacherInfoResponse getTeacherInfoResponse(Long teacherId) { + final TeacherAcademicInfoResponse academicInfoResponse = academicInfoService.getTeacherAcademicInfoById(teacherId); + final TeacherPersonalInfoResponse personalInfoResponse = personalInfoService.getTeacherPersonalInfoById(teacherId); + return TeacherResponseConverter.infoResponsesToResponse(academicInfoResponse, personalInfoResponse); } } From 13baa037dfb71f5ca400083b62e5bee9f06bf2b3 Mon Sep 17 00:00:00 2001 From: Agit Rubar Demir <61833677+agitrubard@users.noreply.github.com> Date: Wed, 23 Feb 2022 12:38:26 +0300 Subject: [PATCH 06/13] Project Version Has Been Updated to v1.2.0 (#60) --- pom.xml | 2 +- src/main/resources/application.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index e06f8e14..9cdbb71f 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ com.graduation-project student-information-system-be - v1.1.0 + v1.2.0 war Student Information System Student Information System for Higher Education diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 4f75b70d..54aee3a9 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,6 +1,6 @@ sis: title: Student Information System API - version: v1.1.0 + version: v1.2.0 server: port: 8585 From 417d15176f60e77eecee380cd5c57d291155603b Mon Sep 17 00:00:00 2001 From: Agit Rubar Demir <61833677+agitrubard@users.noreply.github.com> Date: Fri, 25 Feb 2022 13:25:36 +0300 Subject: [PATCH 07/13] Student Lesson API and Registration API | SIS-112 (#61) * longListToString and longArrayToLongList Methods Have Been Added to SisUtil Class * StudentLessonMapping Class Have Been Created * Student Lesson Entity Classes Have Been Created * StudentLessonException Class Have Been Created * Student Lesson Response Classes Have Been Created * Student Lesson Request Classes Have Been Created * Student Lesson Converter Class Has Been Created * StudentOutService Classes Have Been Created * Student Lesson Repository Classes Have Been Created * Student Lesson Service Classes Have Been Created * Student Lesson Controller Classes Have Been Created * StudentLessonRegistrationMapping Class Has Been Created * StudentLessonRegistrationException Class Has Been Created * StudentLessonRegistrationStatus Enum Class Has Been Created * StudentLessonRegistrationEntity Class Has Been Created * Student Lesson Registration Request Classes Have Been Created * Student Lesson Registration Response Classes Have Been Created * StudentLessonRegistrationInfoConverter Class Has Been Created * Student Lesson Registration Repository Classes Have Been Created * Student Lesson Registration Service Classes Have Been Created * Student Lesson Registration Controller Classes Have Been Created * STUDENT_LESSON_API_TAG and STUDENT_LESSON_REGISTRATION_API_TAG Have Been Added to SisSwaggerConfiguration Class * STUDENT_LESSON and STUDENT_LESSON_REGISTRATION Endpoints Have Been Added to SisControllerEndpoint Class --- pom.xml | 47 +++-- .../config/SisSwaggerConfiguration.java | 4 + .../common/util/SisUtil.java | 13 ++ .../endpoint/SisControllerEndpoint.java | 4 + .../controller/StudentLessonController.java | 48 +++++ .../StudentLessonControllerEndpoint.java | 11 ++ .../converter/StudentLessonInfoConverter.java | 76 +++++++ .../request/StudentLessonDeleteRequest.java | 19 ++ .../dto/request/StudentLessonInfoRequest.java | 24 +++ .../dto/request/StudentLessonSaveRequest.java | 24 +++ .../dto/response/StudentLessonResponse.java | 17 ++ .../dto/response/StudentLessonsResponse.java | 19 ++ .../entity/StudentLessonDeleteEntity.java | 12 ++ .../model/entity/StudentLessonEntity.java | 16 ++ .../model/entity/StudentLessonSaveEntity.java | 16 ++ .../exception/StudentLessonException.java | 19 ++ .../model/mapping/StudentLessonMapping.java | 24 +++ .../repository/StudentLessonRepository.java | 19 ++ .../impl/StudentLessonRepositoryImpl.java | 124 ++++++++++++ .../impl/scripts/StudentLessonSqlScripts.java | 67 +++++++ .../service/StudentLessonOutService.java | 11 ++ .../common/service/StudentLessonService.java | 12 ++ .../impl/StudentLessonOutServiceImpl.java | 77 ++++++++ .../impl/StudentLessonServiceImpl.java | 54 +++++ .../StudentLessonRegistrationController.java | 87 ++++++++ ...tLessonRegistrationControllerEndpoint.java | 14 ++ ...tudentLessonRegistrationInfoConverter.java | 115 +++++++++++ ...udentLessonRegistrationApproveRequest.java | 23 +++ .../StudentLessonRegistrationInfoRequest.java | 23 +++ ...tudentLessonRegistrationRejectRequest.java | 23 +++ .../StudentLessonRegistrationSaveRequest.java | 24 +++ ...udentLessonRegistrationDetailResponse.java | 21 ++ .../StudentLessonRegistrationResponse.java | 17 ++ .../StudentLessonRegistrationEntity.java | 16 ++ .../StudentLessonRegistrationStatus.java | 16 ++ .../StudentLessonRegistrationException.java | 27 +++ .../StudentLessonRegistrationMapping.java | 28 +++ .../StudentLessonRegistrationRepository.java | 27 +++ ...udentLessonRegistrationRepositoryImpl.java | 184 +++++++++++++++++ .../StudentLessonRegistrationSqlScripts.java | 105 ++++++++++ .../StudentLessonRegistrationService.java | 29 +++ .../StudentLessonRegistrationServiceImpl.java | 187 ++++++++++++++++++ .../student/service/StudentOutService.java | 11 ++ .../service/impl/StudentOutServiceImpl.java | 35 ++++ 44 files changed, 1749 insertions(+), 20 deletions(-) create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/controller/StudentLessonController.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/controller/endpoint/StudentLessonControllerEndpoint.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/dto/converter/StudentLessonInfoConverter.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/dto/request/StudentLessonDeleteRequest.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/dto/request/StudentLessonInfoRequest.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/dto/request/StudentLessonSaveRequest.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/dto/response/StudentLessonResponse.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/dto/response/StudentLessonsResponse.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/entity/StudentLessonDeleteEntity.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/entity/StudentLessonEntity.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/entity/StudentLessonSaveEntity.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/exception/StudentLessonException.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/mapping/StudentLessonMapping.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/repository/StudentLessonRepository.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/repository/impl/StudentLessonRepositoryImpl.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/repository/impl/scripts/StudentLessonSqlScripts.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/service/StudentLessonOutService.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/service/StudentLessonService.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/service/impl/StudentLessonOutServiceImpl.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/service/impl/StudentLessonServiceImpl.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/controller/StudentLessonRegistrationController.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/controller/endpoint/StudentLessonRegistrationControllerEndpoint.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/dto/converter/StudentLessonRegistrationInfoConverter.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/dto/request/StudentLessonRegistrationApproveRequest.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/dto/request/StudentLessonRegistrationInfoRequest.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/dto/request/StudentLessonRegistrationRejectRequest.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/dto/request/StudentLessonRegistrationSaveRequest.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/dto/response/StudentLessonRegistrationDetailResponse.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/dto/response/StudentLessonRegistrationResponse.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/entity/StudentLessonRegistrationEntity.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/enums/StudentLessonRegistrationStatus.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/exception/StudentLessonRegistrationException.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/mapping/StudentLessonRegistrationMapping.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/repository/StudentLessonRegistrationRepository.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/repository/impl/StudentLessonRegistrationRepositoryImpl.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/repository/impl/scripts/StudentLessonRegistrationSqlScripts.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/service/StudentLessonRegistrationService.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/service/impl/StudentLessonRegistrationServiceImpl.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/student/service/StudentOutService.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/student/service/impl/StudentOutServiceImpl.java diff --git a/pom.xml b/pom.xml index 9cdbb71f..c0b87304 100644 --- a/pom.xml +++ b/pom.xml @@ -49,6 +49,7 @@ 1.7 1.6.2 5.6.0 + 2.9.0 @@ -129,26 +130,32 @@ - commons-validator - commons-validator - ${commons.validator.version} - - - - com.sun.mail - javax.mail - ${javax.mail.version} - - - - - org.slf4j - slf4j-api - 1.7.32 - - - ch.qos.logback - logback-core + commons-validator + commons-validator + ${commons.validator.version} + + + + com.sun.mail + javax.mail + ${javax.mail.version} + + + + com.google.code.gson + gson + ${gson.version} + + + + + org.slf4j + slf4j-api + 1.7.32 + + + ch.qos.logback + logback-core 1.2.7 diff --git a/src/main/java/com/graduationproject/studentinformationsystem/common/config/SisSwaggerConfiguration.java b/src/main/java/com/graduationproject/studentinformationsystem/common/config/SisSwaggerConfiguration.java index d50c344e..f02f3265 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/common/config/SisSwaggerConfiguration.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/common/config/SisSwaggerConfiguration.java @@ -25,6 +25,8 @@ public class SisSwaggerConfiguration { public static final String EXAM_SCHEDULE_FILE_API_TAG = "Exam Schedule File Controller"; public static final String LESSON_SCHEDULE_FILE_API_TAG = "Lesson Schedule File Controller"; public static final String STUDENT_API_TAG = "Student Controller"; + public static final String STUDENT_LESSON_API_TAG = "Student Lesson Controller"; + public static final String STUDENT_LESSON_REGISTRATION_API_TAG = "Student Lesson Registration Controller"; public static final String TEACHER_API_TAG = "Teacher Controller"; public static final String TEACHER_LESSON_API_TAG = "Teacher Lesson Controller"; public static final String OFFICER_API_TAG = "Officer Controller"; @@ -44,6 +46,8 @@ public Docket api() { new Tag(EXAM_SCHEDULE_FILE_API_TAG, "UNIV_EXAM_SCHEDULE_FILE"), new Tag(LESSON_SCHEDULE_FILE_API_TAG, "UNIV_LESSON_SCHEDULE_FILE"), new Tag(STUDENT_API_TAG, "STUDENT_ACADEMIC_INFO & STUDENT_PERSONAL_INFO"), + new Tag(STUDENT_LESSON_API_TAG, "STUDENT_LESSON"), + new Tag(STUDENT_LESSON_REGISTRATION_API_TAG, "STUDENT_LESSON_REGISTRATION"), new Tag(TEACHER_API_TAG, "TEACHER_ACADEMIC_INFO & TEACHER_PERSONAL_INFO"), new Tag(TEACHER_LESSON_API_TAG, "TEACHER_LESSON"), new Tag(OFFICER_API_TAG, "OFFICER_ACADEMIC_INFO & OFFICER_PERSONAL_INFO"), diff --git a/src/main/java/com/graduationproject/studentinformationsystem/common/util/SisUtil.java b/src/main/java/com/graduationproject/studentinformationsystem/common/util/SisUtil.java index 881fc3a7..4fa13598 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/common/util/SisUtil.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/common/util/SisUtil.java @@ -1,7 +1,10 @@ package com.graduationproject.studentinformationsystem.common.util; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; import org.apache.commons.lang3.BooleanUtils; +import java.lang.reflect.Type; import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -104,4 +107,14 @@ public static boolean integerToBoolean(final Integer integer) { public static Integer booleanToInteger(final Boolean bool) { return BooleanUtils.toIntegerObject(bool); } + + public static String longListToString(final List values) { + return new Gson().toJson(values); + } + + public static List longArrayToLongList(final String values) { + Type type = new TypeToken>() { + }.getType(); + return new Gson().fromJson(values, type); + } } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/common/util/controller/endpoint/SisControllerEndpoint.java b/src/main/java/com/graduationproject/studentinformationsystem/common/util/controller/endpoint/SisControllerEndpoint.java index 5acd4e4d..e0d738ad 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/common/util/controller/endpoint/SisControllerEndpoint.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/common/util/controller/endpoint/SisControllerEndpoint.java @@ -9,12 +9,16 @@ public static class Path { private Path() { } + private static final String REGISTRATION = "/registration"; + public static final String FACULTY = "/faculty"; public static final String DEPARTMENT = "/department"; public static final String LESSON = "/lesson"; public static final String EXAM_SCHEDULE_FILE = "/exam-schedule-file"; public static final String LESSON_SCHEDULE_FILE = "/lesson-schedule-file"; public static final String STUDENT = "/student"; + public static final String STUDENT_LESSON = STUDENT + LESSON; + public static final String STUDENT_LESSON_REGISTRATION = STUDENT_LESSON + REGISTRATION; public static final String TEACHER = "/teacher"; public static final String TEACHER_LESSON = TEACHER + LESSON; public static final String OFFICER = "/officer"; diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/controller/StudentLessonController.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/controller/StudentLessonController.java new file mode 100644 index 00000000..1deefe31 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/controller/StudentLessonController.java @@ -0,0 +1,48 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.common.controller; + +import com.graduationproject.studentinformationsystem.common.util.controller.response.SisApiResponse; +import com.graduationproject.studentinformationsystem.common.util.controller.response.SisBaseApiResponse; +import com.graduationproject.studentinformationsystem.common.util.exception.SisAlreadyException; +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.common.util.validation.id.StudentID; +import com.graduationproject.studentinformationsystem.university.lesson.student.common.controller.endpoint.StudentLessonControllerEndpoint; +import com.graduationproject.studentinformationsystem.university.lesson.student.common.model.dto.response.StudentLessonsResponse; +import com.graduationproject.studentinformationsystem.university.lesson.student.common.service.StudentLessonService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import static com.graduationproject.studentinformationsystem.common.config.SisSwaggerConfiguration.STUDENT_LESSON_API_TAG; +import static com.graduationproject.studentinformationsystem.common.util.controller.endpoint.SisControllerEndpoint.Path.STUDENT_LESSON; +import static com.graduationproject.studentinformationsystem.common.util.controller.response.SisResponseUtil.successResponse; + +@RestController +@RequestMapping(STUDENT_LESSON) +@Api(tags = STUDENT_LESSON_API_TAG) +@RequiredArgsConstructor +public class StudentLessonController { + + private final StudentLessonService lessonService; + + @GetMapping(StudentLessonControllerEndpoint.GET_BY_STUDENT_ID) + @ApiOperation(value = "Get Student All Lessons By Student ID") + public ResponseEntity> getStudentLessonsById( + @PathVariable @StudentID final Long studentId) + throws SisNotExistException { + + final StudentLessonsResponse lessonsResponse = lessonService.getStudentLessonsById(studentId); + return successResponse(lessonsResponse); + } + + @DeleteMapping(StudentLessonControllerEndpoint.DELETE_BY_STUDENT_ID) + @ApiOperation(value = "Delete Student All Lessons By Student ID") + public ResponseEntity deleteStudentLessons( + @PathVariable @StudentID final Long studentId) + throws SisAlreadyException, SisNotExistException { + + lessonService.deleteStudentLessons(studentId); + return successResponse(); + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/controller/endpoint/StudentLessonControllerEndpoint.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/controller/endpoint/StudentLessonControllerEndpoint.java new file mode 100644 index 00000000..a0619857 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/controller/endpoint/StudentLessonControllerEndpoint.java @@ -0,0 +1,11 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.common.controller.endpoint; + +public class StudentLessonControllerEndpoint { + + private StudentLessonControllerEndpoint() { + } + + private static final String STUDENT_ID = "/{studentId}"; + public static final String GET_BY_STUDENT_ID = "/get" + STUDENT_ID; + public static final String DELETE_BY_STUDENT_ID = "/delete" + STUDENT_ID; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/dto/converter/StudentLessonInfoConverter.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/dto/converter/StudentLessonInfoConverter.java new file mode 100644 index 00000000..56c2e17f --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/dto/converter/StudentLessonInfoConverter.java @@ -0,0 +1,76 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.common.model.dto.converter; + +import com.graduationproject.studentinformationsystem.common.util.SisUtil; +import com.graduationproject.studentinformationsystem.university.lesson.common.model.dto.response.LessonResponse; +import com.graduationproject.studentinformationsystem.university.lesson.common.service.LessonOutService; +import com.graduationproject.studentinformationsystem.university.lesson.student.common.model.dto.response.StudentLessonResponse; +import com.graduationproject.studentinformationsystem.university.lesson.student.common.model.dto.response.StudentLessonsResponse; +import com.graduationproject.studentinformationsystem.university.lesson.student.common.model.entity.StudentLessonEntity; +import com.graduationproject.studentinformationsystem.university.lesson.student.common.model.entity.StudentLessonSaveEntity; +import com.graduationproject.studentinformationsystem.university.student.model.dto.response.StudentInfoResponse; +import com.graduationproject.studentinformationsystem.university.student.service.StudentOutService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +@Component +@RequiredArgsConstructor +public class StudentLessonInfoConverter { + + private final StudentOutService studentOutService; + private final LessonOutService lessonOutService; + + public StudentLessonSaveEntity generateSaveEntity(final Long studentId, + final Long lessonId, + final Long operationUserId) { + + return StudentLessonSaveEntity.builder() + .studentId(studentId) + .lessonId(lessonId) + .createdUserId(operationUserId) + .createdDate(new Date()).build(); + } + + public StudentLessonResponse entityToResponse(final StudentLessonEntity studentLessonEntity) { + + final StudentInfoResponse studentInfoResponse = getStudentInfoResponse(studentLessonEntity.getStudentId()); + final LessonResponse lessonResponse = getLessonResponse(studentLessonEntity.getLessonId()); + + return StudentLessonResponse.builder() + .createdUserId(studentLessonEntity.getCreatedUserId()) + .createdDate(SisUtil.getFormattedDateTime(studentLessonEntity.getCreatedDate())) + .studentInfoResponse(studentInfoResponse) + .lessonResponse(lessonResponse).build(); + } + + public StudentLessonsResponse entitiesToResponse(final List studentLessonEntities) { + if (studentLessonEntities.isEmpty()) { + return null; + } + + final StudentInfoResponse studentInfoResponse = getStudentInfoResponse(studentLessonEntities.get(0).getStudentId()); + final List lessonResponses = new ArrayList<>(); + + studentLessonEntities.forEach(studentLessonEntity -> { + final LessonResponse lessonResponse = getLessonResponse(studentLessonEntity.getLessonId()); + lessonResponses.add(lessonResponse); + }); + + return StudentLessonsResponse.builder() + .createdUserId(studentLessonEntities.get(0).getCreatedUserId()) + .createdDate(SisUtil.getFormattedDateTime(studentLessonEntities.get(0).getCreatedDate())) + .lessonsResponses(lessonResponses) + .studentInfoResponse(studentInfoResponse).build(); + } + + private StudentInfoResponse getStudentInfoResponse(Long studentId) { + return studentOutService.getStudentInfoResponse(studentId); + } + + private LessonResponse getLessonResponse(Long lessonId) { + return lessonOutService.getLessonResponse(lessonId); + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/dto/request/StudentLessonDeleteRequest.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/dto/request/StudentLessonDeleteRequest.java new file mode 100644 index 00000000..73dc8501 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/dto/request/StudentLessonDeleteRequest.java @@ -0,0 +1,19 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.common.model.dto.request; + +import lombok.Getter; + +import javax.validation.Valid; +import javax.validation.constraints.NotNull; +import java.io.Serial; +import java.io.Serializable; + +@Getter +public class StudentLessonDeleteRequest implements Serializable { + + @Serial + private static final long serialVersionUID = 8186474487495643349L; + + @Valid + @NotNull + private StudentLessonInfoRequest studentLessonInfoRequest; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/dto/request/StudentLessonInfoRequest.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/dto/request/StudentLessonInfoRequest.java new file mode 100644 index 00000000..35ece652 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/dto/request/StudentLessonInfoRequest.java @@ -0,0 +1,24 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.common.model.dto.request; + +import com.graduationproject.studentinformationsystem.common.util.validation.id.LessonID; +import com.graduationproject.studentinformationsystem.common.util.validation.id.StudentID; +import lombok.Getter; + +import javax.validation.constraints.NotNull; +import java.io.Serial; +import java.io.Serializable; + +@Getter +public class StudentLessonInfoRequest implements Serializable { + + @Serial + private static final long serialVersionUID = -3737062791585675014L; + + @NotNull + @StudentID + private Long studentId; + + @NotNull + @LessonID + private Long lessonId; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/dto/request/StudentLessonSaveRequest.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/dto/request/StudentLessonSaveRequest.java new file mode 100644 index 00000000..a0c7e83c --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/dto/request/StudentLessonSaveRequest.java @@ -0,0 +1,24 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.common.model.dto.request; + +import com.graduationproject.studentinformationsystem.common.model.dto.request.SisOperationInfoRequest; +import lombok.Getter; + +import javax.validation.Valid; +import javax.validation.constraints.NotNull; +import java.io.Serial; +import java.io.Serializable; + +@Getter +public class StudentLessonSaveRequest implements Serializable { + + @Serial + private static final long serialVersionUID = -7325837862878819492L; + + @Valid + @NotNull + private StudentLessonInfoRequest studentLessonInfoRequest; + + @Valid + @NotNull + private SisOperationInfoRequest operationInfoRequest; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/dto/response/StudentLessonResponse.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/dto/response/StudentLessonResponse.java new file mode 100644 index 00000000..69b4febf --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/dto/response/StudentLessonResponse.java @@ -0,0 +1,17 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.common.model.dto.response; + +import com.graduationproject.studentinformationsystem.university.lesson.common.model.dto.response.LessonResponse; +import com.graduationproject.studentinformationsystem.university.student.model.dto.response.StudentInfoResponse; +import lombok.Getter; +import lombok.experimental.SuperBuilder; + +@Getter +@SuperBuilder +public class StudentLessonResponse { + + private Long createdUserId; + private String createdDate; + + private StudentInfoResponse studentInfoResponse; + private LessonResponse lessonResponse; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/dto/response/StudentLessonsResponse.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/dto/response/StudentLessonsResponse.java new file mode 100644 index 00000000..ade1bc8c --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/dto/response/StudentLessonsResponse.java @@ -0,0 +1,19 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.common.model.dto.response; + +import com.graduationproject.studentinformationsystem.university.lesson.common.model.dto.response.LessonResponse; +import com.graduationproject.studentinformationsystem.university.student.model.dto.response.StudentInfoResponse; +import lombok.Getter; +import lombok.experimental.SuperBuilder; + +import java.util.List; + +@Getter +@SuperBuilder +public class StudentLessonsResponse { + + private Long createdUserId; + private String createdDate; + + private StudentInfoResponse studentInfoResponse; + private List lessonsResponses; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/entity/StudentLessonDeleteEntity.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/entity/StudentLessonDeleteEntity.java new file mode 100644 index 00000000..60bfab8f --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/entity/StudentLessonDeleteEntity.java @@ -0,0 +1,12 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.common.model.entity; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class StudentLessonDeleteEntity { + + private Long studentId; + private Long lessonId; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/entity/StudentLessonEntity.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/entity/StudentLessonEntity.java new file mode 100644 index 00000000..bd3b5687 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/entity/StudentLessonEntity.java @@ -0,0 +1,16 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.common.model.entity; + +import lombok.Builder; +import lombok.Getter; + +import java.util.Date; + +@Getter +@Builder +public class StudentLessonEntity { + + private Long studentId; + private Long lessonId; + private Long createdUserId; + private Date createdDate; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/entity/StudentLessonSaveEntity.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/entity/StudentLessonSaveEntity.java new file mode 100644 index 00000000..c7edcc3b --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/entity/StudentLessonSaveEntity.java @@ -0,0 +1,16 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.common.model.entity; + +import lombok.Builder; +import lombok.Getter; + +import java.util.Date; + +@Getter +@Builder +public class StudentLessonSaveEntity { + + private Long studentId; + private Long lessonId; + private Long createdUserId; + private Date createdDate; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/exception/StudentLessonException.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/exception/StudentLessonException.java new file mode 100644 index 00000000..26b602cf --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/exception/StudentLessonException.java @@ -0,0 +1,19 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.common.model.exception; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisAlreadyException; +import com.graduationproject.studentinformationsystem.common.util.exception.SisException; +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; + +public class StudentLessonException extends SisException { + + private StudentLessonException() { + } + + public static void throwAlreadyExistException(final Long studentId, final Long lessonId) throws SisAlreadyException { + SisException.throwAlreadyException("STUDENT LESSON IS ALREADY EXIST! studentId:" + studentId + " lessonId:" + lessonId); + } + + public static void throwNotExistException(final Long studentId) throws SisNotExistException { + SisException.throwNotExistException("STUDENT LESSONS IS NOT EXIST! studentId:" + studentId); + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/mapping/StudentLessonMapping.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/mapping/StudentLessonMapping.java new file mode 100644 index 00000000..a746a6af --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/model/mapping/StudentLessonMapping.java @@ -0,0 +1,24 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.common.model.mapping; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +@Getter +@RequiredArgsConstructor +public enum StudentLessonMapping { + + STUDENT_ID("STUDENT_ID", "studentId"), + LESSON_ID("LESSON_ID", "lessonId"), + CREATED_DATE("CREATED_DATE", "createdDate"), + CREATED_USER_ID("CREATED_USER_ID", "createdUserId"); + + private final String columnName; + private final String modelName; + + public static final Map COLUMN_MAPPINGS = Stream.of(values()) + .collect(Collectors.toMap(StudentLessonMapping::getColumnName, StudentLessonMapping::getModelName)); +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/repository/StudentLessonRepository.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/repository/StudentLessonRepository.java new file mode 100644 index 00000000..f54a164e --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/repository/StudentLessonRepository.java @@ -0,0 +1,19 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.common.repository; + +import com.graduationproject.studentinformationsystem.university.lesson.student.common.model.entity.StudentLessonEntity; +import com.graduationproject.studentinformationsystem.university.lesson.student.common.model.entity.StudentLessonSaveEntity; + +import java.util.List; + +public interface StudentLessonRepository { + + List getStudentLessonsByStudentId(Long studentId); + + void saveStudentLesson(StudentLessonSaveEntity saveLessonEntity); + + void deleteStudentLessons(Long studentId); + + boolean isStudentLessonsExist(Long studentId); + + boolean isStudentLessonExist(Long studentId, Long lessonId); +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/repository/impl/StudentLessonRepositoryImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/repository/impl/StudentLessonRepositoryImpl.java new file mode 100644 index 00000000..a5168012 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/repository/impl/StudentLessonRepositoryImpl.java @@ -0,0 +1,124 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.common.repository.impl; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisDatabaseException; +import com.graduationproject.studentinformationsystem.common.util.log.SisErrorLogMessageUtil; +import com.graduationproject.studentinformationsystem.common.util.log.SisInfoLogMessageUtil; +import com.graduationproject.studentinformationsystem.common.util.log.SisWarnLogMessageUtil; +import com.graduationproject.studentinformationsystem.university.lesson.student.common.model.entity.StudentLessonEntity; +import com.graduationproject.studentinformationsystem.university.lesson.student.common.model.entity.StudentLessonSaveEntity; +import com.graduationproject.studentinformationsystem.university.lesson.student.common.repository.StudentLessonRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; +import org.sql2o.Connection; +import org.sql2o.Query; +import org.sql2o.Sql2o; + +import java.util.List; + +import static com.graduationproject.studentinformationsystem.university.lesson.student.common.model.mapping.StudentLessonMapping.*; +import static com.graduationproject.studentinformationsystem.university.lesson.student.common.repository.impl.scripts.StudentLessonSqlScripts.*; + +@Repository +@RequiredArgsConstructor +public class StudentLessonRepositoryImpl implements StudentLessonRepository { + + private static final String STUDENT_LESSON = "Student Lesson"; + private final SisInfoLogMessageUtil info = SisInfoLogMessageUtil.builder().apiName(STUDENT_LESSON).build(); + private final SisWarnLogMessageUtil warn = SisWarnLogMessageUtil.builder().apiName(STUDENT_LESSON).build(); + private final SisErrorLogMessageUtil error = SisErrorLogMessageUtil.builder().apiName(STUDENT_LESSON).build(); + + private final Sql2o sql2o; + + @Override + public List getStudentLessonsByStudentId(final Long studentId) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(GET_STUDENT_ALL_LESSONS)) { + + final List studentLessonEntities = query + .addParameter(STUDENT_ID.getModelName(), studentId) + .setColumnMappings(COLUMN_MAPPINGS) + .executeAndFetch(StudentLessonEntity.class); + + info.foundAll(); + return studentLessonEntities; + } catch (Exception exception) { + error.errorWhenGettingAll(); + throw new SisDatabaseException(exception); + } + } + + @Override + public void saveStudentLesson(final StudentLessonSaveEntity saveEntity) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(SAVE_STUDENT_LESSON)) { + + query.addParameter(STUDENT_ID.getModelName(), saveEntity.getStudentId()) + .addParameter(LESSON_ID.getModelName(), saveEntity.getLessonId()) + .addParameter(CREATED_DATE.getModelName(), saveEntity.getCreatedDate()) + .addParameter(CREATED_USER_ID.getModelName(), saveEntity.getCreatedUserId()) + .setColumnMappings(COLUMN_MAPPINGS) + .executeUpdate(); + + info.savedById(saveEntity.getLessonId()); + } catch (Exception exception) { + error.errorWhenSaving(); + throw new SisDatabaseException(exception); + } + } + + @Override + public void deleteStudentLessons(final Long studentId) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(DELETE_STUDENT_LESSONS)) { + + query.addParameter(STUDENT_ID.getModelName(), studentId) + .setColumnMappings(COLUMN_MAPPINGS) + .executeUpdate(); + + info.deleted(); + } catch (Exception exception) { + error.errorWhenSaving(); + throw new SisDatabaseException(exception); + } + } + + @Override + public boolean isStudentLessonsExist(Long studentId) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(IS_STUDENT_LESSONS_EXIST)) { + + final boolean isLessonsExist = query + .addParameter(STUDENT_ID.getModelName(), studentId) + .executeAndFetchFirst(Boolean.class); + + if (isLessonsExist) { + info.foundById(studentId); + return true; + } else { + warn.notFoundById(studentId); + return false; + } + } catch (Exception exception) { + error.errorWhenGettingById(studentId); + throw new SisDatabaseException(exception); + } + } + + @Override + public boolean isStudentLessonExist(final Long studentId, final Long lessonId) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(IS_STUDENT_LESSON_EXIST)) { + + final boolean isLessonExist = query + .addParameter(STUDENT_ID.getModelName(), studentId) + .addParameter(LESSON_ID.getModelName(), lessonId) + .executeAndFetchFirst(Boolean.class); + + if (isLessonExist) { + info.foundById(lessonId); + return true; + } else { + warn.notFoundById(lessonId); + return false; + } + } catch (Exception exception) { + error.errorWhenGettingById(lessonId); + throw new SisDatabaseException(exception); + } + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/repository/impl/scripts/StudentLessonSqlScripts.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/repository/impl/scripts/StudentLessonSqlScripts.java new file mode 100644 index 00000000..890236b1 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/repository/impl/scripts/StudentLessonSqlScripts.java @@ -0,0 +1,67 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.common.repository.impl.scripts; + +import com.graduationproject.studentinformationsystem.common.util.sql.SisSqlUtil; + +import static com.graduationproject.studentinformationsystem.university.lesson.student.common.model.mapping.StudentLessonMapping.LESSON_ID; +import static com.graduationproject.studentinformationsystem.university.lesson.student.common.model.mapping.StudentLessonMapping.STUDENT_ID; + +public class StudentLessonSqlScripts { + + private static final StringBuilder sqlBuilder = new StringBuilder(); + + private StudentLessonSqlScripts() { + } + + /** + * SELECT STUDENT_ID, LESSON_ID, CREATED_USER_ID, CREATED_DATE FROM STUDENT_LESSON WHERE STUDENT_ID=:studentId; + */ + public static final String GET_STUDENT_ALL_LESSONS = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("SELECT STUDENT_ID, LESSON_ID, CREATED_USER_ID, CREATED_DATE " + + "FROM STUDENT_LESSON WHERE STUDENT_ID=:studentId ").toString(); + + /** + * SELECT STUDENT_ID, LESSON_ID, CREATED_USER_ID, CREATED_DATE FROM STUDENT_LESSON + * WHERE STUDENT_ID=:studentId AND LESSON_ID=:lessonId; + */ + public static final String GET_STUDENT_LESSON = + sqlBuilder.delete(0, sqlBuilder.length()) + .append(GET_STUDENT_ALL_LESSONS) + .append("AND LESSON_ID=:lessonId").toString(); + + /** + * INSERT INTO STUDENT_LESSON (STUDENT_ID, LESSON_ID, CREATED_DATE, CREATED_USER_ID) + * VALUES (:studentId, :lessonId, :createdDate, :createdUserId); + */ + public static final String SAVE_STUDENT_LESSON = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("INSERT INTO STUDENT_LESSON (STUDENT_ID, LESSON_ID, CREATED_DATE, CREATED_USER_ID) " + + "VALUES (:studentId, :lessonId, :createdDate, :createdUserId)").toString(); + + /** + * DELETE FROM STUDENT_LESSON WHERE STUDENT_ID=:studentId AND LESSON_ID=:lessonId; + */ + public static final String DELETE_STUDENT_LESSONS = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("DELETE FROM STUDENT_LESSON WHERE STUDENT_ID=:studentId").toString(); + + /** + * SELECT CASE WHEN MAX(STUDENT_ID) IS NULL THEN 'false' ELSE 'true' END IS_EXIST + * FROM STUDENT_LESSON WHERE STUDENT_ID=:studentId; + */ + public static final String IS_STUDENT_LESSONS_EXIST = SisSqlUtil + .isExistByColumnName("STUDENT_LESSON", + STUDENT_ID.getColumnName(), + STUDENT_ID.getModelName()); + + /** + * SELECT CASE WHEN MAX(STUDENT_ID) IS NULL THEN 'false' ELSE 'true' END IS_EXIST + * FROM STUDENT_LESSON WHERE STUDENT_ID=:studentId AND LESSON_ID=:lessonId; + */ + public static final String IS_STUDENT_LESSON_EXIST = SisSqlUtil + .isExistByColumnTwoColumns("STUDENT_LESSON", + STUDENT_ID.getColumnName(), + STUDENT_ID.getModelName(), + LESSON_ID.getColumnName(), + LESSON_ID.getModelName()); +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/service/StudentLessonOutService.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/service/StudentLessonOutService.java new file mode 100644 index 00000000..f335d7c4 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/service/StudentLessonOutService.java @@ -0,0 +1,11 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.common.service; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisAlreadyException; +import com.graduationproject.studentinformationsystem.university.lesson.student.common.model.dto.response.StudentLessonsResponse; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.dto.response.StudentLessonRegistrationDetailResponse; + +public interface StudentLessonOutService { + + StudentLessonsResponse saveStudentLessons(StudentLessonRegistrationDetailResponse registrationDetailResponse) + throws SisAlreadyException; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/service/StudentLessonService.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/service/StudentLessonService.java new file mode 100644 index 00000000..06b9c0f6 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/service/StudentLessonService.java @@ -0,0 +1,12 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.common.service; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisAlreadyException; +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.university.lesson.student.common.model.dto.response.StudentLessonsResponse; + +public interface StudentLessonService { + + StudentLessonsResponse getStudentLessonsById(Long studentId) throws SisNotExistException; + + void deleteStudentLessons(Long studentId) throws SisAlreadyException, SisNotExistException; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/service/impl/StudentLessonOutServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/service/impl/StudentLessonOutServiceImpl.java new file mode 100644 index 00000000..efc3ca6c --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/service/impl/StudentLessonOutServiceImpl.java @@ -0,0 +1,77 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.common.service.impl; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisAlreadyException; +import com.graduationproject.studentinformationsystem.university.lesson.common.model.dto.response.LessonResponse; +import com.graduationproject.studentinformationsystem.university.lesson.student.common.model.dto.converter.StudentLessonInfoConverter; +import com.graduationproject.studentinformationsystem.university.lesson.student.common.model.dto.response.StudentLessonsResponse; +import com.graduationproject.studentinformationsystem.university.lesson.student.common.model.entity.StudentLessonEntity; +import com.graduationproject.studentinformationsystem.university.lesson.student.common.model.entity.StudentLessonSaveEntity; +import com.graduationproject.studentinformationsystem.university.lesson.student.common.model.exception.StudentLessonException; +import com.graduationproject.studentinformationsystem.university.lesson.student.common.repository.StudentLessonRepository; +import com.graduationproject.studentinformationsystem.university.lesson.student.common.service.StudentLessonOutService; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.dto.response.StudentLessonRegistrationDetailResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +@RequiredArgsConstructor +public class StudentLessonOutServiceImpl implements StudentLessonOutService { + + private final StudentLessonRepository studentLessonRepository; + private final StudentLessonInfoConverter studentLessonInfoConverter; + + @Override + public StudentLessonsResponse saveStudentLessons(final StudentLessonRegistrationDetailResponse registrationDetailResponse) + throws SisAlreadyException { + + final Long studentId = registrationDetailResponse.getStudentInfoResponse().getStudentId(); + final List lessonResponses = registrationDetailResponse.getLessonResponses(); + final Long operationUserId = registrationDetailResponse.getModifiedUserId(); + + for (LessonResponse lessonResponse : lessonResponses) { + + final Long lessonId = lessonResponse.getLessonId(); + + checkBeforeSaving(studentId, lessonId); + + final StudentLessonSaveEntity studentLessonSaveEntity = studentLessonInfoConverter + .generateSaveEntity(studentId, lessonId, operationUserId); + + studentLessonRepository.saveStudentLesson(studentLessonSaveEntity); + } + + return getStudentLessonsResponse(studentId); + } + + private StudentLessonsResponse getStudentLessonsResponse(final Long studentId) { + + final List studentLessonEntities = studentLessonRepository + .getStudentLessonsByStudentId(studentId); + + return studentLessonInfoConverter.entitiesToResponse(studentLessonEntities); + } + + + /** + * Checks Before Processing + */ + + private void checkBeforeSaving(final Long studentId, final Long lessonId) throws SisAlreadyException { + ifStudentLessonIsExistThrowAlreadyException(studentId, lessonId); + } + + + /** + * Throw Exceptions + */ + + private void ifStudentLessonIsExistThrowAlreadyException(final Long studentId, final Long lessonId) + throws SisAlreadyException { + + if (studentLessonRepository.isStudentLessonExist(studentId, lessonId)) { + StudentLessonException.throwAlreadyExistException(studentId, lessonId); + } + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/service/impl/StudentLessonServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/service/impl/StudentLessonServiceImpl.java new file mode 100644 index 00000000..a8aff202 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/common/service/impl/StudentLessonServiceImpl.java @@ -0,0 +1,54 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.common.service.impl; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.university.lesson.student.common.model.dto.converter.StudentLessonInfoConverter; +import com.graduationproject.studentinformationsystem.university.lesson.student.common.model.dto.response.StudentLessonsResponse; +import com.graduationproject.studentinformationsystem.university.lesson.student.common.model.entity.StudentLessonEntity; +import com.graduationproject.studentinformationsystem.university.lesson.student.common.model.exception.StudentLessonException; +import com.graduationproject.studentinformationsystem.university.lesson.student.common.repository.StudentLessonRepository; +import com.graduationproject.studentinformationsystem.university.lesson.student.common.service.StudentLessonService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; + + +@Service +@RequiredArgsConstructor +public class StudentLessonServiceImpl implements StudentLessonService { + + private final StudentLessonRepository studentLessonRepository; + private final StudentLessonInfoConverter studentLessonInfoConverter; + + @Override + public StudentLessonsResponse getStudentLessonsById(final Long studentId) throws SisNotExistException { + + ifStudentLessonsIsNotExistThrowNotExistException(studentId); + + final List studentLessonEntities = studentLessonRepository + .getStudentLessonsByStudentId(studentId); + + return studentLessonInfoConverter.entitiesToResponse(studentLessonEntities); + } + + @Override + public void deleteStudentLessons(final Long studentId) throws SisNotExistException { + + ifStudentLessonsIsNotExistThrowNotExistException(studentId); + + studentLessonRepository.deleteStudentLessons(studentId); + } + + + /** + * Throw Exceptions + */ + + private void ifStudentLessonsIsNotExistThrowNotExistException(final Long studentId) + throws SisNotExistException { + + if (!studentLessonRepository.isStudentLessonsExist(studentId)) { + StudentLessonException.throwNotExistException(studentId); + } + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/controller/StudentLessonRegistrationController.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/controller/StudentLessonRegistrationController.java new file mode 100644 index 00000000..ebb2e954 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/controller/StudentLessonRegistrationController.java @@ -0,0 +1,87 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.registration.controller; + +import com.graduationproject.studentinformationsystem.common.util.controller.response.SisBaseApiResponse; +import com.graduationproject.studentinformationsystem.common.util.exception.SisAlreadyException; +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.controller.endpoint.StudentLessonRegistrationControllerEndpoint; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.dto.request.StudentLessonRegistrationApproveRequest; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.dto.request.StudentLessonRegistrationRejectRequest; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.dto.request.StudentLessonRegistrationSaveRequest; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.dto.response.StudentLessonRegistrationDetailResponse; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.dto.response.StudentLessonRegistrationResponse; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.enums.StudentLessonRegistrationStatus; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.service.StudentLessonRegistrationService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.util.List; + +import static com.graduationproject.studentinformationsystem.common.config.SisSwaggerConfiguration.STUDENT_LESSON_REGISTRATION_API_TAG; +import static com.graduationproject.studentinformationsystem.common.util.controller.endpoint.SisControllerEndpoint.Path.STUDENT_LESSON_REGISTRATION; +import static com.graduationproject.studentinformationsystem.common.util.controller.response.SisResponseUtil.successResponse; + +@RestController +@RequestMapping(STUDENT_LESSON_REGISTRATION) +@Api(tags = STUDENT_LESSON_REGISTRATION_API_TAG) +@RequiredArgsConstructor +public class StudentLessonRegistrationController { + + private final StudentLessonRegistrationService studentLessonRegistrationService; + + @GetMapping(StudentLessonRegistrationControllerEndpoint.GET) + @ApiOperation(value = "Get All Student Lesson Registrations By Status") + public ResponseEntity>> getAllStudentLessonRegistrationsByStatus( + @RequestParam final StudentLessonRegistrationStatus status) { + + final List registrationResponses = studentLessonRegistrationService + .getAllStudentLessonRegistrationsByStatus(status); + return successResponse(registrationResponses); + } + + @GetMapping(StudentLessonRegistrationControllerEndpoint.GET_BY_REGISTRATION_ID) + @ApiOperation(value = "Get Student Lesson Registration By Registration ID") + public ResponseEntity> getStudentLessonRegistrationDetailByRegistrationId( + @PathVariable final String registrationId) throws SisNotExistException { + + final StudentLessonRegistrationDetailResponse registrationDetailResponse = studentLessonRegistrationService + .getStudentLessonRegistrationDetailByRegistrationId(registrationId); + return successResponse(registrationDetailResponse); + } + + @PostMapping(StudentLessonRegistrationControllerEndpoint.SAVE) + @ApiOperation(value = "Save Student Lesson Registration") + public ResponseEntity> saveStudentLessonRegistration( + @RequestBody @Valid final StudentLessonRegistrationSaveRequest saveRequest) + throws SisAlreadyException, SisNotExistException { + + final StudentLessonRegistrationDetailResponse registrationDetailResponse = studentLessonRegistrationService + .saveStudentLessonRegistration(saveRequest); + return successResponse(registrationDetailResponse); + } + + @PatchMapping(StudentLessonRegistrationControllerEndpoint.APPROVE) + @ApiOperation(value = "Approve Student Lesson Registration") + public ResponseEntity> approveStudentLessonRegistration( + @RequestBody @Valid final StudentLessonRegistrationApproveRequest approveRequest) + throws SisNotExistException, SisAlreadyException { + + final StudentLessonRegistrationDetailResponse registrationDetailResponse = studentLessonRegistrationService + .approveStudentLessonRegistration(approveRequest); + return successResponse(registrationDetailResponse); + } + + @PatchMapping(StudentLessonRegistrationControllerEndpoint.REJECT) + @ApiOperation(value = "Reject Student Lesson Registration") + public ResponseEntity> activateStudent( + @RequestBody @Valid final StudentLessonRegistrationRejectRequest rejectRequest) + throws SisNotExistException, SisAlreadyException { + + final StudentLessonRegistrationDetailResponse registrationDetailResponse = studentLessonRegistrationService + .rejectStudentLessonRegistration(rejectRequest); + return successResponse(registrationDetailResponse); + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/controller/endpoint/StudentLessonRegistrationControllerEndpoint.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/controller/endpoint/StudentLessonRegistrationControllerEndpoint.java new file mode 100644 index 00000000..ffa6ff7d --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/controller/endpoint/StudentLessonRegistrationControllerEndpoint.java @@ -0,0 +1,14 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.registration.controller.endpoint; + +public class StudentLessonRegistrationControllerEndpoint { + + private StudentLessonRegistrationControllerEndpoint() { + } + + private static final String REGISTRATION_ID = "/{registrationId}"; + public static final String GET = "/get"; + public static final String GET_BY_REGISTRATION_ID = GET + REGISTRATION_ID; + public static final String SAVE = "/save"; + public static final String APPROVE = "/approve"; + public static final String REJECT = "/reject"; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/dto/converter/StudentLessonRegistrationInfoConverter.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/dto/converter/StudentLessonRegistrationInfoConverter.java new file mode 100644 index 00000000..2fa0f2e2 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/dto/converter/StudentLessonRegistrationInfoConverter.java @@ -0,0 +1,115 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.dto.converter; + +import com.graduationproject.studentinformationsystem.common.model.dto.request.SisOperationInfoRequest; +import com.graduationproject.studentinformationsystem.common.util.SisUtil; +import com.graduationproject.studentinformationsystem.university.lesson.common.model.dto.response.LessonResponse; +import com.graduationproject.studentinformationsystem.university.lesson.common.service.LessonOutService; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.dto.request.StudentLessonRegistrationApproveRequest; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.dto.request.StudentLessonRegistrationInfoRequest; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.dto.request.StudentLessonRegistrationRejectRequest; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.dto.request.StudentLessonRegistrationSaveRequest; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.dto.response.StudentLessonRegistrationDetailResponse; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.dto.response.StudentLessonRegistrationResponse; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.entity.StudentLessonRegistrationEntity; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.enums.StudentLessonRegistrationStatus; +import com.graduationproject.studentinformationsystem.university.student.model.dto.response.StudentInfoResponse; +import com.graduationproject.studentinformationsystem.university.student.service.StudentOutService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +@Component +@RequiredArgsConstructor +public class StudentLessonRegistrationInfoConverter { + + private final StudentOutService studentOutService; + private final LessonOutService lessonOutService; + + public StudentLessonRegistrationEntity generateSaveEntity(final StudentLessonRegistrationSaveRequest saveRequest) { + + final StudentLessonRegistrationInfoRequest studentLessonRegistrationInfoRequest = saveRequest.getStudentLessonRegistrationInfoRequest(); + final SisOperationInfoRequest operationInfoRequest = saveRequest.getOperationInfoRequest(); + + return StudentLessonRegistrationEntity.builder() + .registrationId(SisUtil.generateRandomUUID()) + .studentId(studentLessonRegistrationInfoRequest.getStudentId()) + .lessonsIds(SisUtil.longListToString(studentLessonRegistrationInfoRequest.getLessonsIds())) + .status(StudentLessonRegistrationStatus.WAITING) + .createdUserId(operationInfoRequest.getUserId()) + .createdDate(new Date()).build(); + } + + public StudentLessonRegistrationEntity generateApprovedEntity(final StudentLessonRegistrationApproveRequest approveRequest) { + + final SisOperationInfoRequest operationInfoRequest = approveRequest.getOperationInfoRequest(); + + return StudentLessonRegistrationEntity.builder() + .registrationId(approveRequest.getRegistrationId()) + .status(StudentLessonRegistrationStatus.APPROVED) + .modifiedUserId(operationInfoRequest.getUserId()) + .modifiedDate(new Date()).build(); + } + + public StudentLessonRegistrationEntity generateRejectedEntity(final StudentLessonRegistrationRejectRequest rejectRequest) { + + final SisOperationInfoRequest operationInfoRequest = rejectRequest.getOperationInfoRequest(); + + return StudentLessonRegistrationEntity.builder() + .registrationId(rejectRequest.getRegistrationId()) + .status(StudentLessonRegistrationStatus.REJECTED) + .modifiedUserId(operationInfoRequest.getUserId()) + .modifiedDate(new Date()).build(); + } + + public StudentLessonRegistrationDetailResponse entityToResponse(final StudentLessonRegistrationEntity registrationEntity) { + + final StudentInfoResponse studentInfoResponse = getStudentInfoResponse(registrationEntity.getStudentId()); + final List lessonIds = SisUtil.longArrayToLongList(registrationEntity.getLessonsIds()); + final List lessonResponses = new ArrayList<>(); + + lessonIds.forEach(lessonId -> lessonResponses.add(getLessonResponse(lessonId))); + + return StudentLessonRegistrationDetailResponse.builder() + .registrationId(registrationEntity.getRegistrationId()) + .status(registrationEntity.getStatus()) + .createdUserId(registrationEntity.getCreatedUserId()) + .createdDate(SisUtil.getFormattedDateTime(registrationEntity.getCreatedDate())) + .modifiedUserId(registrationEntity.getModifiedUserId()) + .modifiedDate(SisUtil.getFormattedDateTime(registrationEntity.getModifiedDate())) + .studentInfoResponse(studentInfoResponse) + .lessonResponses(lessonResponses).build(); + } + + public List entitiesToResponses(final List registrationEntities) { + + final List registrationResponses = new ArrayList<>(); + + registrationEntities.forEach(registrationEntity -> { + final StudentInfoResponse studentInfoResponse = getStudentInfoResponse(registrationEntity.getStudentId()); + + final StudentLessonRegistrationResponse registrationResponse = StudentLessonRegistrationResponse.builder() + .registrationId(registrationEntity.getRegistrationId()) + .status(registrationEntity.getStatus()) + .createdUserId(registrationEntity.getCreatedUserId()) + .createdDate(SisUtil.getFormattedDateTime(registrationEntity.getCreatedDate())) + .modifiedUserId(registrationEntity.getModifiedUserId()) + .modifiedDate(SisUtil.getFormattedDateTime(registrationEntity.getModifiedDate())) + .studentInfoResponse(studentInfoResponse).build(); + + registrationResponses.add(registrationResponse); + }); + + return registrationResponses; + } + + private StudentInfoResponse getStudentInfoResponse(final Long studentId) { + return studentOutService.getStudentInfoResponse(studentId); + } + + private LessonResponse getLessonResponse(final Long lessonId) { + return lessonOutService.getLessonResponse(lessonId); + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/dto/request/StudentLessonRegistrationApproveRequest.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/dto/request/StudentLessonRegistrationApproveRequest.java new file mode 100644 index 00000000..cc4144cb --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/dto/request/StudentLessonRegistrationApproveRequest.java @@ -0,0 +1,23 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.dto.request; + +import com.graduationproject.studentinformationsystem.common.model.dto.request.SisOperationInfoRequest; +import lombok.Getter; + +import javax.validation.Valid; +import javax.validation.constraints.NotNull; +import java.io.Serial; +import java.io.Serializable; + +@Getter +public class StudentLessonRegistrationApproveRequest implements Serializable { + + @Serial + private static final long serialVersionUID = -4277766662686555545L; + + @NotNull + private String registrationId; + + @Valid + @NotNull + private SisOperationInfoRequest operationInfoRequest; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/dto/request/StudentLessonRegistrationInfoRequest.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/dto/request/StudentLessonRegistrationInfoRequest.java new file mode 100644 index 00000000..cd2975d0 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/dto/request/StudentLessonRegistrationInfoRequest.java @@ -0,0 +1,23 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.dto.request; + +import com.graduationproject.studentinformationsystem.common.util.validation.id.StudentID; +import lombok.Getter; + +import javax.validation.constraints.NotNull; +import java.io.Serial; +import java.io.Serializable; +import java.util.List; + +@Getter +public class StudentLessonRegistrationInfoRequest implements Serializable { + + @Serial + private static final long serialVersionUID = -818997554323584139L; + + @NotNull + @StudentID + private Long studentId; + + @NotNull + private List lessonsIds; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/dto/request/StudentLessonRegistrationRejectRequest.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/dto/request/StudentLessonRegistrationRejectRequest.java new file mode 100644 index 00000000..a3a9fada --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/dto/request/StudentLessonRegistrationRejectRequest.java @@ -0,0 +1,23 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.dto.request; + +import com.graduationproject.studentinformationsystem.common.model.dto.request.SisOperationInfoRequest; +import lombok.Getter; + +import javax.validation.Valid; +import javax.validation.constraints.NotNull; +import java.io.Serial; +import java.io.Serializable; + +@Getter +public class StudentLessonRegistrationRejectRequest implements Serializable { + + @Serial + private static final long serialVersionUID = -2404839697727479952L; + + @NotNull + private String registrationId; + + @Valid + @NotNull + private SisOperationInfoRequest operationInfoRequest; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/dto/request/StudentLessonRegistrationSaveRequest.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/dto/request/StudentLessonRegistrationSaveRequest.java new file mode 100644 index 00000000..66850280 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/dto/request/StudentLessonRegistrationSaveRequest.java @@ -0,0 +1,24 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.dto.request; + +import com.graduationproject.studentinformationsystem.common.model.dto.request.SisOperationInfoRequest; +import lombok.Getter; + +import javax.validation.Valid; +import javax.validation.constraints.NotNull; +import java.io.Serial; +import java.io.Serializable; + +@Getter +public class StudentLessonRegistrationSaveRequest implements Serializable { + + @Serial + private static final long serialVersionUID = -1832299531569396048L; + + @Valid + @NotNull + private StudentLessonRegistrationInfoRequest studentLessonRegistrationInfoRequest; + + @Valid + @NotNull + private SisOperationInfoRequest operationInfoRequest; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/dto/response/StudentLessonRegistrationDetailResponse.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/dto/response/StudentLessonRegistrationDetailResponse.java new file mode 100644 index 00000000..98f873b0 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/dto/response/StudentLessonRegistrationDetailResponse.java @@ -0,0 +1,21 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.dto.response; + +import com.graduationproject.studentinformationsystem.common.model.dto.response.SisBaseResponse; +import com.graduationproject.studentinformationsystem.university.lesson.common.model.dto.response.LessonResponse; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.enums.StudentLessonRegistrationStatus; +import com.graduationproject.studentinformationsystem.university.student.model.dto.response.StudentInfoResponse; +import lombok.Getter; +import lombok.experimental.SuperBuilder; + +import java.util.List; + +@Getter +@SuperBuilder +public class StudentLessonRegistrationDetailResponse extends SisBaseResponse { + + private String registrationId; + private StudentLessonRegistrationStatus status; + + private StudentInfoResponse studentInfoResponse; + private List lessonResponses; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/dto/response/StudentLessonRegistrationResponse.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/dto/response/StudentLessonRegistrationResponse.java new file mode 100644 index 00000000..f985252a --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/dto/response/StudentLessonRegistrationResponse.java @@ -0,0 +1,17 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.dto.response; + +import com.graduationproject.studentinformationsystem.common.model.dto.response.SisBaseResponse; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.enums.StudentLessonRegistrationStatus; +import com.graduationproject.studentinformationsystem.university.student.model.dto.response.StudentInfoResponse; +import lombok.Getter; +import lombok.experimental.SuperBuilder; + +@Getter +@SuperBuilder +public class StudentLessonRegistrationResponse extends SisBaseResponse { + + private String registrationId; + private StudentLessonRegistrationStatus status; + + private StudentInfoResponse studentInfoResponse; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/entity/StudentLessonRegistrationEntity.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/entity/StudentLessonRegistrationEntity.java new file mode 100644 index 00000000..255b8645 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/entity/StudentLessonRegistrationEntity.java @@ -0,0 +1,16 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.entity; + +import com.graduationproject.studentinformationsystem.common.model.entity.SisBaseEntity; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.enums.StudentLessonRegistrationStatus; +import lombok.Getter; +import lombok.experimental.SuperBuilder; + +@Getter +@SuperBuilder +public class StudentLessonRegistrationEntity extends SisBaseEntity { + + private String registrationId; + private Long studentId; + private String lessonsIds; + private StudentLessonRegistrationStatus status; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/enums/StudentLessonRegistrationStatus.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/enums/StudentLessonRegistrationStatus.java new file mode 100644 index 00000000..9b5d6a54 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/enums/StudentLessonRegistrationStatus.java @@ -0,0 +1,16 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.enums; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum StudentLessonRegistrationStatus { + + WAITING("Onay Bekleniyor"), + APPROVED("Onaylandı"), + REJECTED("Reddedildi"), + ALL("Hepsi"); + + private final String tr; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/exception/StudentLessonRegistrationException.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/exception/StudentLessonRegistrationException.java new file mode 100644 index 00000000..efc78ce7 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/exception/StudentLessonRegistrationException.java @@ -0,0 +1,27 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.exception; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisAlreadyException; +import com.graduationproject.studentinformationsystem.common.util.exception.SisException; +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; + +public class StudentLessonRegistrationException extends SisException { + + private StudentLessonRegistrationException() { + } + + public static void throwNotExistException(final String registrationId) throws SisNotExistException { + SisException.throwNotExistException("STUDENT LESSON REGISTRATION IS NOT EXIST! registrationId:" + registrationId); + } + + public static void throwAlreadyWaitingException(final String registrationId) throws SisAlreadyException { + SisException.throwAlreadyException("STUDENT LESSON REGISTRATION IS ALREADY WAITING! registrationId:" + registrationId); + } + + public static void throwAlreadyApprovedException(final String registrationId) throws SisAlreadyException { + SisException.throwAlreadyException("STUDENT LESSON REGISTRATION IS ALREADY APPROVED! registrationId:" + registrationId); + } + + public static void throwAlreadyRejectedException(final String registrationId) throws SisAlreadyException { + SisException.throwAlreadyException("STUDENT LESSON REGISTRATION IS ALREADY REJECTED! registrationId:" + registrationId); + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/mapping/StudentLessonRegistrationMapping.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/mapping/StudentLessonRegistrationMapping.java new file mode 100644 index 00000000..7ed3f434 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/model/mapping/StudentLessonRegistrationMapping.java @@ -0,0 +1,28 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.mapping; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +@Getter +@RequiredArgsConstructor +public enum StudentLessonRegistrationMapping { + + REGISTRATION_ID("REGISTRATION_ID", "registrationId"), + STUDENT_ID("STUDENT_ID", "studentId"), + LESSONS_IDS("LESSONS_IDS", "lessonsIds"), + STATUS("STATUS", "status"), + CREATED_DATE("CREATED_DATE", "createdDate"), + CREATED_USER_ID("CREATED_USER_ID", "createdUserId"), + MODIFIED_DATE("MODIFIED_DATE", "modifiedDate"), + MODIFIED_USER_ID("MODIFIED_USER_ID", "modifiedUserId"); + + private final String columnName; + private final String modelName; + + public static final Map COLUMN_MAPPINGS = Stream.of(values()) + .collect(Collectors.toMap(StudentLessonRegistrationMapping::getColumnName, StudentLessonRegistrationMapping::getModelName)); +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/repository/StudentLessonRegistrationRepository.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/repository/StudentLessonRegistrationRepository.java new file mode 100644 index 00000000..509f08ba --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/repository/StudentLessonRegistrationRepository.java @@ -0,0 +1,27 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.registration.repository; + +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.entity.StudentLessonRegistrationEntity; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.enums.StudentLessonRegistrationStatus; + +import java.util.List; + +public interface StudentLessonRegistrationRepository { + + List getAllStudentLessonRegistrationsByStatus(StudentLessonRegistrationStatus status); + + StudentLessonRegistrationEntity getStudentLessonRegistrationByRegistrationId(String registrationId); + + void saveStudentLessonRegistration(StudentLessonRegistrationEntity registrationEntity); + + void updateStudentLessonRegistrationStatus(StudentLessonRegistrationEntity registrationEntity); + + boolean isStudentLessonRegistrationExist(String registrationId); + + boolean isStudentLessonRegistrationWaiting(String registrationId); + + boolean isStudentLessonRegistrationApproved(String registrationId); + + boolean isStudentLessonRegistrationRejected(String registrationId); + + String getRegistrationId(Long studentId); +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/repository/impl/StudentLessonRegistrationRepositoryImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/repository/impl/StudentLessonRegistrationRepositoryImpl.java new file mode 100644 index 00000000..896ba231 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/repository/impl/StudentLessonRegistrationRepositoryImpl.java @@ -0,0 +1,184 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.registration.repository.impl; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisDatabaseException; +import com.graduationproject.studentinformationsystem.common.util.log.SisErrorLogMessageUtil; +import com.graduationproject.studentinformationsystem.common.util.log.SisInfoLogMessageUtil; +import com.graduationproject.studentinformationsystem.common.util.log.SisWarnLogMessageUtil; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.entity.StudentLessonRegistrationEntity; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.enums.StudentLessonRegistrationStatus; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.repository.StudentLessonRegistrationRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; +import org.sql2o.Connection; +import org.sql2o.Query; +import org.sql2o.Sql2o; + +import java.util.Arrays; +import java.util.List; +import java.util.StringJoiner; + +import static com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.mapping.StudentLessonRegistrationMapping.*; +import static com.graduationproject.studentinformationsystem.university.lesson.student.registration.repository.impl.scripts.StudentLessonRegistrationSqlScripts.*; + +@Repository +@RequiredArgsConstructor +public class StudentLessonRegistrationRepositoryImpl implements StudentLessonRegistrationRepository { + + private static final String STUDENT_LESSON_REGISTRATION = "Student Lesson Registration"; + private final SisInfoLogMessageUtil info = SisInfoLogMessageUtil.builder().apiName(STUDENT_LESSON_REGISTRATION).build(); + private final SisWarnLogMessageUtil warn = SisWarnLogMessageUtil.builder().apiName(STUDENT_LESSON_REGISTRATION).build(); + private final SisErrorLogMessageUtil error = SisErrorLogMessageUtil.builder().apiName(STUDENT_LESSON_REGISTRATION).build(); + + private final Sql2o sql2o; + + @Override + public List getAllStudentLessonRegistrationsByStatus(final StudentLessonRegistrationStatus status) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(GET_ALL_STUDENT_LESSON_REGISTRATIONS + .concat(querySearchByStatus(CREATED_DATE.getColumnName(), status.toString())))) { + + final List registrationEntities = query + .setColumnMappings(COLUMN_MAPPINGS) + .executeAndFetch(StudentLessonRegistrationEntity.class); + + if (!registrationEntities.isEmpty()) { + info.foundAllByStatus(status.toString()); + } else { + warn.notFoundAllIdsByStatus(status.toString()); + } + return registrationEntities; + } catch (Exception exception) { + error.errorWhenGettingAllByStatus(status.toString()); + throw new SisDatabaseException(exception); + } + } + + @Override + public StudentLessonRegistrationEntity getStudentLessonRegistrationByRegistrationId(final String registrationId) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(GET_STUDENT_LESSON_REGISTRATION)) { + + final StudentLessonRegistrationEntity registrationEntity = query + .addParameter(REGISTRATION_ID.getModelName(), registrationId) + .setColumnMappings(COLUMN_MAPPINGS) + .executeAndFetchFirst(StudentLessonRegistrationEntity.class); + + info.foundById(registrationId); + return registrationEntity; + } catch (Exception exception) { + error.errorWhenGettingById(registrationId); + throw new SisDatabaseException(exception); + } + } + + @Override + public void saveStudentLessonRegistration(final StudentLessonRegistrationEntity registrationEntity) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(SAVE_STUDENT_LESSON_REGISTRATION)) { + + query.addParameter(REGISTRATION_ID.getModelName(), registrationEntity.getRegistrationId()) + .addParameter(STUDENT_ID.getModelName(), registrationEntity.getStudentId()) + .addParameter(LESSONS_IDS.getModelName(), registrationEntity.getLessonsIds()) + .addParameter(STATUS.getModelName(), registrationEntity.getStatus()) + .addParameter(CREATED_DATE.getModelName(), registrationEntity.getCreatedDate()) + .addParameter(CREATED_USER_ID.getModelName(), registrationEntity.getCreatedUserId()) + .setColumnMappings(COLUMN_MAPPINGS) + .executeUpdate(); + + info.savedById(registrationEntity.getStudentId()); + } catch (Exception exception) { + error.errorWhenSaving(); + throw new SisDatabaseException(exception); + } + } + + @Override + public void updateStudentLessonRegistrationStatus(final StudentLessonRegistrationEntity registrationEntity) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(UPDATE_STUDENT_LESSON_REGISTRATION_STATUS)) { + + query.addParameter(STATUS.getModelName(), registrationEntity.getStatus()) + .addParameter(MODIFIED_DATE.getModelName(), registrationEntity.getModifiedDate()) + .addParameter(MODIFIED_USER_ID.getModelName(), registrationEntity.getModifiedUserId()) + .addParameter(REGISTRATION_ID.getModelName(), registrationEntity.getRegistrationId()) + .executeUpdate(); + + info.statusUpdated(registrationEntity.getStatus().toString()); + } catch (Exception exception) { + error.errorWhenUpdatingStatus(); + throw new SisDatabaseException(exception); + } + } + + @Override + public boolean isStudentLessonRegistrationExist(final String registrationId) { + return checkOperation(registrationId, IS_STUDENT_LESSON_REGISTRATION_EXIST_BY_REGISTRATION_ID); + } + + @Override + public boolean isStudentLessonRegistrationWaiting(final String registrationId) { + return checkOperation(registrationId, IS_STUDENT_LESSON_REGISTRATION_WAITING_BY_REGISTRATION_ID); + } + + @Override + public boolean isStudentLessonRegistrationApproved(final String registrationId) { + return checkOperation(registrationId, IS_STUDENT_LESSON_REGISTRATION_APPROVED_BY_REGISTRATION_ID); + } + + @Override + public boolean isStudentLessonRegistrationRejected(final String registrationId) { + return checkOperation(registrationId, IS_STUDENT_LESSON_REGISTRATION_REJECTED_BY_REGISTRATION_ID); + } + + @Override + public String getRegistrationId(final Long studentId) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(GET_REGISTRATION_ID_BY_STUDENT_ID)) { + + final String registrationId = query + .addParameter(STUDENT_ID.getModelName(), studentId) + .executeScalar(String.class); + + if (registrationId != null) { + info.foundById(studentId); + return registrationId; + } else { + warn.notFoundById(studentId); + return null; + } + } catch (Exception exception) { + error.errorWhenGettingById(studentId); + throw new SisDatabaseException(exception); + } + } + + private boolean checkOperation(final String registrationId, final String sql) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(sql)) { + + final boolean operationExist = query + .addParameter(REGISTRATION_ID.getModelName(), registrationId) + .executeAndFetchFirst(Boolean.class); + + if (operationExist) { + info.foundById(registrationId); + return true; + } else { + warn.notFoundById(registrationId); + return false; + } + } catch (Exception exception) { + error.errorWhenGettingById(registrationId); + throw new SisDatabaseException(exception); + } + } + + /** + * ('status') ORDER BY orderByFieldName ASC; || If Status == ALL -> ('status1', 'status2', ...) ORDER BY orderByFieldName ASC; + */ + private static String querySearchByStatus(final String orderByFieldName, final String status) { + final String orderByIdAsc = " ORDER BY " + orderByFieldName + " DESC "; + final StringJoiner statusForQuery = new StringJoiner(",", "(", ")"); + if (status.equalsIgnoreCase(StudentLessonRegistrationStatus.ALL.toString())) { + Arrays.stream(StudentLessonRegistrationStatus.values()) + .filter(s -> s != StudentLessonRegistrationStatus.ALL) + .forEach(s -> statusForQuery.add("'" + s + "'")); + return statusForQuery + orderByIdAsc; + } else + return statusForQuery.add("'" + status + "'") + orderByIdAsc; + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/repository/impl/scripts/StudentLessonRegistrationSqlScripts.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/repository/impl/scripts/StudentLessonRegistrationSqlScripts.java new file mode 100644 index 00000000..671263e6 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/repository/impl/scripts/StudentLessonRegistrationSqlScripts.java @@ -0,0 +1,105 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.registration.repository.impl.scripts; + +import com.graduationproject.studentinformationsystem.common.util.sql.SisSqlUtil; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.enums.StudentLessonRegistrationStatus; + +import static com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.mapping.StudentLessonRegistrationMapping.REGISTRATION_ID; + +public class StudentLessonRegistrationSqlScripts { + + private static final StringBuilder sqlBuilder = new StringBuilder(); + + private StudentLessonRegistrationSqlScripts() { + } + + /** + * SELECT REGISTRATION_ID, STUDENT_ID, STATUS, + * CREATED_DATE, CREATED_USER_ID, MODIFIED_DATE, MODIFIED_USER_ID FROM STUDENT_LESSON_REGISTRATION + * WHERE STATUS IN 'status'; + */ + public static final String GET_ALL_STUDENT_LESSON_REGISTRATIONS = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("SELECT REGISTRATION_ID, STUDENT_ID, STATUS, " + + "CREATED_DATE, CREATED_USER_ID, MODIFIED_DATE, MODIFIED_USER_ID " + + "FROM STUDENT_LESSON_REGISTRATION WHERE STATUS IN ").toString(); + + /** + * SELECT REGISTRATION_ID, STUDENT_ID, LESSONS_IDS, STATUS, + * CREATED_DATE, CREATED_USER_ID, MODIFIED_DATE, MODIFIED_USER_ID FROM STUDENT_LESSON_REGISTRATION + * WHERE REGISTRATION_ID=:registrationId; + */ + public static final String GET_STUDENT_LESSON_REGISTRATION = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("SELECT REGISTRATION_ID, STUDENT_ID, LESSONS_IDS, STATUS, " + + "CREATED_DATE, CREATED_USER_ID, MODIFIED_DATE, MODIFIED_USER_ID " + + "FROM STUDENT_LESSON_REGISTRATION WHERE REGISTRATION_ID=:registrationId ").toString(); + + /** + * INSERT INTO STUDENT_LESSON_REGISTRATION (REGISTRATION_ID, STUDENT_ID, LESSONS_IDS, STATUS, + * CREATED_DATE, CREATED_USER_ID) VALUES (:registrationId, :studentId, lessonsIds, status, + * :createdDate, :createdUserId); + */ + public static final String SAVE_STUDENT_LESSON_REGISTRATION = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("INSERT INTO STUDENT_LESSON_REGISTRATION (REGISTRATION_ID, STUDENT_ID, LESSONS_IDS, " + + "STATUS, CREATED_DATE, CREATED_USER_ID) VALUES (:registrationId, :studentId, :lessonsIds, " + + ":status, :createdDate, :createdUserId) ").toString(); + + /** + * UPDATE STUDENT_LESSON_REGISTRATION SET STATUS=:status, + * MODIFIED_DATE=:modifiedDate, MODIFIED_USER_ID=:modifiedUserId + * WHERE REGISTRATION_ID=:registrationId; + */ + public static final String UPDATE_STUDENT_LESSON_REGISTRATION_STATUS = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("UPDATE STUDENT_LESSON_REGISTRATION SET STATUS=:status, " + + "MODIFIED_DATE=:modifiedDate, MODIFIED_USER_ID=:modifiedUserId " + + "WHERE REGISTRATION_ID=:registrationId").toString(); + + /** + * SELECT CASE WHEN MAX(REGISTRATION_ID) IS NULL THEN 'false' ELSE 'true' END IS_EXIST + * FROM STUDENT_LESSON_REGISTRATION WHERE REGISTRATION_ID=:registrationId; + */ + public static final String IS_STUDENT_LESSON_REGISTRATION_EXIST_BY_REGISTRATION_ID = SisSqlUtil + .isExistByColumnName("STUDENT_LESSON_REGISTRATION", + REGISTRATION_ID.getColumnName(), + REGISTRATION_ID.getModelName()); + + /** + * SELECT CASE WHEN MAX(REGISTRATION_ID) IS NULL THEN 'false' ELSE 'true' END IS_EXIST + * FROM STUDENT_LESSON_REGISTRATION WHERE REGISTRATION_ID=:registrationId AND STATUS='WAITING'; + */ + public static final String IS_STUDENT_LESSON_REGISTRATION_WAITING_BY_REGISTRATION_ID = SisSqlUtil + .isExistByColumnNameAndStatus("STUDENT_LESSON_REGISTRATION", + REGISTRATION_ID.getColumnName(), + REGISTRATION_ID.getModelName(), + StudentLessonRegistrationStatus.WAITING.toString()); + + /** + * SELECT CASE WHEN MAX(REGISTRATION_ID) IS NULL THEN 'false' ELSE 'true' END IS_EXIST + * FROM STUDENT_LESSON_REGISTRATION WHERE REGISTRATION_ID=:registrationId AND STATUS='APPROVED'; + */ + public static final String IS_STUDENT_LESSON_REGISTRATION_APPROVED_BY_REGISTRATION_ID = SisSqlUtil + .isExistByColumnNameAndStatus("STUDENT_LESSON_REGISTRATION", + REGISTRATION_ID.getColumnName(), + REGISTRATION_ID.getModelName(), + StudentLessonRegistrationStatus.APPROVED.toString()); + + /** + * SELECT CASE WHEN MAX(REGISTRATION_ID) IS NULL THEN 'false' ELSE 'true' END IS_EXIST + * FROM STUDENT_LESSON_REGISTRATION WHERE REGISTRATION_ID=:registrationId AND STATUS='REJECTED'; + */ + public static final String IS_STUDENT_LESSON_REGISTRATION_REJECTED_BY_REGISTRATION_ID = SisSqlUtil + .isExistByColumnNameAndStatus("STUDENT_LESSON_REGISTRATION", + REGISTRATION_ID.getColumnName(), + REGISTRATION_ID.getModelName(), + StudentLessonRegistrationStatus.REJECTED.toString()); + + /** + * SELECT REGISTRATION_ID FROM STUDENT_LESSON_REGISTRATION WHERE STUDENT_ID=:studentId; + */ + public static final String GET_REGISTRATION_ID_BY_STUDENT_ID = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("SELECT REGISTRATION_ID FROM STUDENT_LESSON_REGISTRATION " + + "WHERE STUDENT_ID=:studentId").toString(); +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/service/StudentLessonRegistrationService.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/service/StudentLessonRegistrationService.java new file mode 100644 index 00000000..51bb103e --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/service/StudentLessonRegistrationService.java @@ -0,0 +1,29 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.registration.service; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisAlreadyException; +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.dto.request.StudentLessonRegistrationApproveRequest; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.dto.request.StudentLessonRegistrationRejectRequest; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.dto.request.StudentLessonRegistrationSaveRequest; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.dto.response.StudentLessonRegistrationDetailResponse; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.dto.response.StudentLessonRegistrationResponse; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.enums.StudentLessonRegistrationStatus; + +import java.util.List; + +public interface StudentLessonRegistrationService { + + List getAllStudentLessonRegistrationsByStatus(StudentLessonRegistrationStatus status); + + StudentLessonRegistrationDetailResponse getStudentLessonRegistrationDetailByRegistrationId(String registrationId) + throws SisNotExistException; + + StudentLessonRegistrationDetailResponse saveStudentLessonRegistration(StudentLessonRegistrationSaveRequest saveRequest) + throws SisAlreadyException, SisNotExistException; + + StudentLessonRegistrationDetailResponse approveStudentLessonRegistration(StudentLessonRegistrationApproveRequest approveRequest) + throws SisAlreadyException, SisNotExistException; + + StudentLessonRegistrationDetailResponse rejectStudentLessonRegistration(StudentLessonRegistrationRejectRequest rejectRequest) + throws SisAlreadyException, SisNotExistException; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/service/impl/StudentLessonRegistrationServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/service/impl/StudentLessonRegistrationServiceImpl.java new file mode 100644 index 00000000..d0314846 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/service/impl/StudentLessonRegistrationServiceImpl.java @@ -0,0 +1,187 @@ +package com.graduationproject.studentinformationsystem.university.lesson.student.registration.service.impl; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisAlreadyException; +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.university.lesson.common.service.LessonOutService; +import com.graduationproject.studentinformationsystem.university.lesson.student.common.service.StudentLessonOutService; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.dto.converter.StudentLessonRegistrationInfoConverter; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.dto.request.StudentLessonRegistrationApproveRequest; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.dto.request.StudentLessonRegistrationRejectRequest; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.dto.request.StudentLessonRegistrationSaveRequest; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.dto.response.StudentLessonRegistrationDetailResponse; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.dto.response.StudentLessonRegistrationResponse; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.entity.StudentLessonRegistrationEntity; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.enums.StudentLessonRegistrationStatus; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.exception.StudentLessonRegistrationException; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.repository.StudentLessonRegistrationRepository; +import com.graduationproject.studentinformationsystem.university.lesson.student.registration.service.StudentLessonRegistrationService; +import com.graduationproject.studentinformationsystem.university.student.service.StudentOutService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +@RequiredArgsConstructor +public class StudentLessonRegistrationServiceImpl implements StudentLessonRegistrationService { + + private final StudentOutService studentOutService; + private final LessonOutService lessonOutService; + private final StudentLessonOutService studentLessonOutService; + + private final StudentLessonRegistrationRepository studentLessonRegistrationRepository; + private final StudentLessonRegistrationInfoConverter studentLessonRegistrationInfoConverter; + + @Override + public List getAllStudentLessonRegistrationsByStatus(final StudentLessonRegistrationStatus status) { + + final List registrationEntities = studentLessonRegistrationRepository + .getAllStudentLessonRegistrationsByStatus(status); + + return studentLessonRegistrationInfoConverter.entitiesToResponses(registrationEntities); + } + + @Override + public StudentLessonRegistrationDetailResponse getStudentLessonRegistrationDetailByRegistrationId(final String registrationId) + throws SisNotExistException { + + ifStudentLessonRegistrationIsNotExistThrowNotExistException(registrationId); + + final StudentLessonRegistrationEntity registrationEntity = studentLessonRegistrationRepository + .getStudentLessonRegistrationByRegistrationId(registrationId); + + return studentLessonRegistrationInfoConverter.entityToResponse(registrationEntity); + } + + @Override + public StudentLessonRegistrationDetailResponse saveStudentLessonRegistration(final StudentLessonRegistrationSaveRequest saveRequest) + throws SisAlreadyException, SisNotExistException { + + final Long studentId = saveRequest.getStudentLessonRegistrationInfoRequest().getStudentId(); + final List lessonsIds = saveRequest.getStudentLessonRegistrationInfoRequest().getLessonsIds(); + final String registrationId = studentLessonRegistrationRepository.getRegistrationId(studentId); + + checkBeforeSaving(registrationId, studentId, lessonsIds); + + final StudentLessonRegistrationEntity registrationEntity = studentLessonRegistrationInfoConverter + .generateSaveEntity(saveRequest); + + studentLessonRegistrationRepository.saveStudentLessonRegistration(registrationEntity); + return getStudentLessonRegistrationDetailByRegistrationId(registrationEntity.getRegistrationId()); + } + + @Override + public StudentLessonRegistrationDetailResponse approveStudentLessonRegistration(final StudentLessonRegistrationApproveRequest approveRequest) + throws SisNotExistException, SisAlreadyException { + + final String registrationId = approveRequest.getRegistrationId(); + + checkBeforeApproved(registrationId); + + final StudentLessonRegistrationEntity registrationEntity = studentLessonRegistrationInfoConverter + .generateApprovedEntity(approveRequest); + + studentLessonRegistrationRepository.updateStudentLessonRegistrationStatus(registrationEntity); + + final StudentLessonRegistrationDetailResponse registrationDetailResponse = getStudentLessonRegistrationDetailByRegistrationId(registrationId); + + if (StudentLessonRegistrationStatus.APPROVED.equals(registrationDetailResponse.getStatus())) { + studentLessonOutService.saveStudentLessons(registrationDetailResponse); + } + + return registrationDetailResponse; + } + + @Override + public StudentLessonRegistrationDetailResponse rejectStudentLessonRegistration(final StudentLessonRegistrationRejectRequest rejectRequest) + throws SisNotExistException, SisAlreadyException { + + final String registrationId = rejectRequest.getRegistrationId(); + + checkBeforeRejected(registrationId); + + final StudentLessonRegistrationEntity registrationEntity = studentLessonRegistrationInfoConverter + .generateRejectedEntity(rejectRequest); + + studentLessonRegistrationRepository.updateStudentLessonRegistrationStatus(registrationEntity); + return getStudentLessonRegistrationDetailByRegistrationId(registrationId); + } + + + /** + * Checks Before Processing + */ + + private void checkBeforeSaving(final String registrationId, final Long studentId, final List lessonsIds) + throws SisNotExistException, SisAlreadyException { + + if (registrationId != null) { + ifStudentLessonRegistrationIsWaitingThrowAlreadyWaitingException(registrationId); + ifStudentLessonRegistrationIsApprovedThrowAlreadyApprovedException(registrationId); + } + ifStudentIsNotExistThrowNotExistException(studentId); + for (Long lessonId : lessonsIds) { + ifLessonIsNotExistThrowNotExistException(lessonId); + } + } + + private void checkBeforeApproved(final String registrationId) + throws SisNotExistException, SisAlreadyException { + + ifStudentLessonRegistrationIsNotExistThrowNotExistException(registrationId); + ifStudentLessonRegistrationIsApprovedThrowAlreadyApprovedException(registrationId); + ifStudentLessonRegistrationIsRejectedThrowAlreadyRejectedException(registrationId); + } + + private void checkBeforeRejected(final String registrationId) + throws SisNotExistException, SisAlreadyException { + + ifStudentLessonRegistrationIsNotExistThrowNotExistException(registrationId); + ifStudentLessonRegistrationIsApprovedThrowAlreadyApprovedException(registrationId); + ifStudentLessonRegistrationIsRejectedThrowAlreadyRejectedException(registrationId); + } + + /** + * Throw Exceptions + */ + + private void ifStudentIsNotExistThrowNotExistException(final Long studentId) throws SisNotExistException { + studentOutService.ifStudentIsNotExistThrowNotExistException(studentId); + } + + private void ifLessonIsNotExistThrowNotExistException(final Long lessonId) throws SisNotExistException { + lessonOutService.ifLessonIsNotExistThrowNotExistException(lessonId); + } + + private void ifStudentLessonRegistrationIsNotExistThrowNotExistException(final String registrationId) + throws SisNotExistException { + + if (!studentLessonRegistrationRepository.isStudentLessonRegistrationExist(registrationId)) { + StudentLessonRegistrationException.throwNotExistException(registrationId); + } + } + + private void ifStudentLessonRegistrationIsWaitingThrowAlreadyWaitingException(final String registrationId) + throws SisAlreadyException { + + if (studentLessonRegistrationRepository.isStudentLessonRegistrationWaiting(registrationId)) { + StudentLessonRegistrationException.throwAlreadyWaitingException(registrationId); + } + } + + private void ifStudentLessonRegistrationIsApprovedThrowAlreadyApprovedException(final String registrationId) + throws SisAlreadyException { + + if (studentLessonRegistrationRepository.isStudentLessonRegistrationApproved(registrationId)) { + StudentLessonRegistrationException.throwAlreadyApprovedException(registrationId); + } + } + + private void ifStudentLessonRegistrationIsRejectedThrowAlreadyRejectedException(final String registrationId) + throws SisAlreadyException { + + if (studentLessonRegistrationRepository.isStudentLessonRegistrationRejected(registrationId)) { + StudentLessonRegistrationException.throwAlreadyRejectedException(registrationId); + } + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/student/service/StudentOutService.java b/src/main/java/com/graduationproject/studentinformationsystem/university/student/service/StudentOutService.java new file mode 100644 index 00000000..f095e447 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/student/service/StudentOutService.java @@ -0,0 +1,11 @@ +package com.graduationproject.studentinformationsystem.university.student.service; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.university.student.model.dto.response.StudentInfoResponse; + +public interface StudentOutService { + + StudentInfoResponse getStudentInfoResponse(Long studentId); + + void ifStudentIsNotExistThrowNotExistException(Long studentId) throws SisNotExistException; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/student/service/impl/StudentOutServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/student/service/impl/StudentOutServiceImpl.java new file mode 100644 index 00000000..90c3e771 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/student/service/impl/StudentOutServiceImpl.java @@ -0,0 +1,35 @@ +package com.graduationproject.studentinformationsystem.university.student.service.impl; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.university.student.model.dto.converter.StudentResponseConverter; +import com.graduationproject.studentinformationsystem.university.student.model.dto.response.StudentAcademicInfoResponse; +import com.graduationproject.studentinformationsystem.university.student.model.dto.response.StudentInfoResponse; +import com.graduationproject.studentinformationsystem.university.student.model.dto.response.StudentPersonalInfoResponse; +import com.graduationproject.studentinformationsystem.university.student.model.exception.StudentException; +import com.graduationproject.studentinformationsystem.university.student.service.StudentAcademicInfoService; +import com.graduationproject.studentinformationsystem.university.student.service.StudentOutService; +import com.graduationproject.studentinformationsystem.university.student.service.StudentPersonalInfoService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class StudentOutServiceImpl implements StudentOutService { + + private final StudentAcademicInfoService academicInfoService; + private final StudentPersonalInfoService personalInfoService; + + @Override + public StudentInfoResponse getStudentInfoResponse(final Long studentId) { + final StudentAcademicInfoResponse academicInfoResponse = academicInfoService.getStudentAcademicInfoById(studentId); + final StudentPersonalInfoResponse personalInfoResponse = personalInfoService.getStudentPersonalInfoById(studentId); + return StudentResponseConverter.infoResponsesToResponse(academicInfoResponse, personalInfoResponse); + } + + @Override + public void ifStudentIsNotExistThrowNotExistException(final Long studentId) throws SisNotExistException { + if (!academicInfoService.isStudentExist(studentId)) { + StudentException.throwNotExistException(studentId); + } + } +} From be7dcd92afce8842cd37f0575c846cae5bb743b8 Mon Sep 17 00:00:00 2001 From: Agit Rubar Demir <61833677+agitrubard@users.noreply.github.com> Date: Fri, 25 Feb 2022 13:38:10 +0300 Subject: [PATCH 08/13] Code Refactor (#62) * Department Status Enum Class Has Been Added to DepartmentSqlScripts Class * TeacherLessonMapping Class Has Been Refactored * TeacherLesson GET Endpoint Has Been Updated * Get All By Status Methods Have Been Updated --- .../department/controller/DepartmentController.java | 4 ++-- .../repository/impl/scripts/DepartmentSqlScripts.java | 8 ++++---- .../university/faculty/controller/FacultyController.java | 4 ++-- .../lesson/common/controller/LessonController.java | 4 ++-- .../teacher/controller/TeacherLessonController.java | 4 ++-- .../endpoint/TeacherLessonControllerEndpoint.java | 4 ++-- .../teacher/model/mapping/TeacherLessonMapping.java | 6 ------ .../university/officer/controller/OfficerController.java | 4 ++-- .../university/student/controller/StudentController.java | 4 ++-- .../university/teacher/controller/TeacherController.java | 4 ++-- 10 files changed, 20 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/department/controller/DepartmentController.java b/src/main/java/com/graduationproject/studentinformationsystem/university/department/controller/DepartmentController.java index d4024e3b..cc12c99a 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/department/controller/DepartmentController.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/department/controller/DepartmentController.java @@ -30,9 +30,9 @@ public class DepartmentController { private final DepartmentService departmentService; @GetMapping - @ApiOperation(value = "Get All Department By Status") + @ApiOperation(value = "Get All Departments By Status") public ResponseEntity>> getAllDepartmentsByStatus( - final DepartmentStatus status) { + @RequestParam final DepartmentStatus status) { final List departmentResponses = departmentService.getAllDepartmentsByStatus(status); return successResponse(departmentResponses); diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/department/repository/impl/scripts/DepartmentSqlScripts.java b/src/main/java/com/graduationproject/studentinformationsystem/university/department/repository/impl/scripts/DepartmentSqlScripts.java index b1714a86..33dfb310 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/department/repository/impl/scripts/DepartmentSqlScripts.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/department/repository/impl/scripts/DepartmentSqlScripts.java @@ -1,7 +1,7 @@ package com.graduationproject.studentinformationsystem.university.department.repository.impl.scripts; import com.graduationproject.studentinformationsystem.common.util.sql.SisSqlUtil; -import com.graduationproject.studentinformationsystem.university.officer.model.enums.OfficerStatus; +import com.graduationproject.studentinformationsystem.university.department.model.enums.DepartmentStatus; import static com.graduationproject.studentinformationsystem.university.department.model.mapping.DepartmentMapping.DEPARTMENT_ID; @@ -99,7 +99,7 @@ private DepartmentSqlScripts() { .isExistByColumnNameAndStatus("UNIV_DEPARTMENT", DEPARTMENT_ID.getColumnName(), DEPARTMENT_ID.getModelName(), - OfficerStatus.DELETED.toString()); + DepartmentStatus.DELETED.toString()); /** * SELECT CASE WHEN MAX(DEPARTMENT_ID) IS NULL THEN 'false' ELSE 'true' END IS_EXIST @@ -109,7 +109,7 @@ private DepartmentSqlScripts() { .isExistByColumnNameAndStatus("UNIV_DEPARTMENT", DEPARTMENT_ID.getColumnName(), DEPARTMENT_ID.getModelName(), - OfficerStatus.PASSIVE.toString()); + DepartmentStatus.PASSIVE.toString()); /** * SELECT CASE WHEN MAX(DEPARTMENT_ID) IS NULL THEN 'false' ELSE 'true' END IS_EXIST @@ -119,5 +119,5 @@ private DepartmentSqlScripts() { .isExistByColumnNameAndStatus("UNIV_DEPARTMENT", DEPARTMENT_ID.getColumnName(), DEPARTMENT_ID.getModelName(), - OfficerStatus.ACTIVE.toString()); + DepartmentStatus.ACTIVE.toString()); } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/faculty/controller/FacultyController.java b/src/main/java/com/graduationproject/studentinformationsystem/university/faculty/controller/FacultyController.java index 17967fab..c9f92f34 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/faculty/controller/FacultyController.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/faculty/controller/FacultyController.java @@ -30,9 +30,9 @@ public class FacultyController { private final FacultyService facultyService; @GetMapping - @ApiOperation(value = "Get All Faculty By Status") + @ApiOperation(value = "Get All Faculties By Status") public ResponseEntity>> getAllFacultiesByStatus( - final FacultyStatus status) { + @RequestParam final FacultyStatus status) { final List facultyResponses = facultyService.getAllFacultiesByStatus(status); return successResponse(facultyResponses); diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/common/controller/LessonController.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/common/controller/LessonController.java index acf6783a..9570df8a 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/common/controller/LessonController.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/common/controller/LessonController.java @@ -30,9 +30,9 @@ public class LessonController { private final LessonService lessonService; @GetMapping - @ApiOperation(value = "Get All Lesson By Status") + @ApiOperation(value = "Get All Lessons By Status") public ResponseEntity>> getAllFacultiesByStatus( - final LessonStatus status) { + @RequestParam final LessonStatus status) { final List lessonResponses = lessonService.getAllLessonsByStatus(status); return successResponse(lessonResponses); diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/controller/TeacherLessonController.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/controller/TeacherLessonController.java index bf3fc502..20042399 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/controller/TeacherLessonController.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/controller/TeacherLessonController.java @@ -38,10 +38,10 @@ public ResponseEntity>> getAllTea return successResponse(lessonResponses); } - @GetMapping(TeacherLessonControllerEndpoint.GET) + @GetMapping(TeacherLessonControllerEndpoint.GET_BY_TEACHER_ID) @ApiOperation(value = "Get Teacher All Lessons By Teacher ID") public ResponseEntity>> getTeacherLessonsById( - @RequestParam final Long teacherId) { + @PathVariable final Long teacherId) { final List lessonResponses = lessonService.getTeacherLessonsById(teacherId); return successResponse(lessonResponses); diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/controller/endpoint/TeacherLessonControllerEndpoint.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/controller/endpoint/TeacherLessonControllerEndpoint.java index 6bcd5b9c..50e5836f 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/controller/endpoint/TeacherLessonControllerEndpoint.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/controller/endpoint/TeacherLessonControllerEndpoint.java @@ -5,8 +5,8 @@ public class TeacherLessonControllerEndpoint { private TeacherLessonControllerEndpoint() { } - public static final String TEACHER_ID = "/{teacherId}"; - public static final String GET = "/get"; + private static final String TEACHER_ID = "/{teacherId}"; + public static final String GET_BY_TEACHER_ID = "/get" + TEACHER_ID; public static final String SAVE = "/save"; public static final String DELETE = "/delete"; } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/model/mapping/TeacherLessonMapping.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/model/mapping/TeacherLessonMapping.java index 37968860..9165475c 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/model/mapping/TeacherLessonMapping.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/model/mapping/TeacherLessonMapping.java @@ -13,12 +13,6 @@ public enum TeacherLessonMapping { TEACHER_ID("TEACHER_ID", "teacherId"), LESSON_ID("LESSON_ID", "lessonId"), - DEPARTMENT_ID("DEPARTMENT_ID", "departmentId"), - NAME("NAME", "name"), - SEMESTER("SEMESTER", "semester"), - CREDIT("CREDIT", "credit"), - COMPULSORY_OR_ELECTIVE("COMPULSORY_OR_ELECTIVE", "compulsoryOrElective"), - STATUS("STATUS", "status"), CREATED_DATE("CREATED_DATE", "createdDate"), CREATED_USER_ID("CREATED_USER_ID", "createdUserId"); diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/officer/controller/OfficerController.java b/src/main/java/com/graduationproject/studentinformationsystem/university/officer/controller/OfficerController.java index 2d275723..2449e455 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/officer/controller/OfficerController.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/officer/controller/OfficerController.java @@ -33,9 +33,9 @@ public class OfficerController { private final OfficerService officerService; @GetMapping - @ApiOperation(value = "Get All Officer By Status") + @ApiOperation(value = "Get All Officers By Status") public ResponseEntity>> getAllOfficersByStatus( - final OfficerStatus status) { + @RequestParam final OfficerStatus status) { final List infoResponses = officerService.getAllOfficersByStatus(status); return successResponse(infoResponses); diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/student/controller/StudentController.java b/src/main/java/com/graduationproject/studentinformationsystem/university/student/controller/StudentController.java index 93091096..f87c9bbb 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/student/controller/StudentController.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/student/controller/StudentController.java @@ -33,9 +33,9 @@ public class StudentController { private final StudentService studentService; @GetMapping - @ApiOperation(value = "Get All Student By Status") + @ApiOperation(value = "Get All Students By Status") public ResponseEntity>> getAllStudentsByStatus( - final StudentStatus status) { + @RequestParam final StudentStatus status) { final List infoResponses = studentService.getAllStudentsByStatus(status); return successResponse(infoResponses); diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/controller/TeacherController.java b/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/controller/TeacherController.java index 8f496a08..8f1acf6b 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/controller/TeacherController.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/controller/TeacherController.java @@ -33,9 +33,9 @@ public class TeacherController { private final TeacherService teacherService; @GetMapping - @ApiOperation(value = "Get All Teacher By Status") + @ApiOperation(value = "Get All Teachers By Status") public ResponseEntity>> getAllTeachersByStatus( - final TeacherStatus status) { + @RequestParam final TeacherStatus status) { final List infoResponses = teacherService.getAllTeachersByStatus(status); return successResponse(infoResponses); From 9c3c6100ee6088875404d8e2e299b5c3334094aa Mon Sep 17 00:00:00 2001 From: Agit Rubar Demir <61833677+agitrubard@users.noreply.github.com> Date: Tue, 1 Mar 2022 12:55:59 +0300 Subject: [PATCH 09/13] Student/Teacher/Officer | Password Operations APIs | SIS-115 (#63) * Department Status Enum Class Has Been Added to DepartmentSqlScripts Class * TeacherLessonMapping Class Has Been Refactored * TeacherLesson GET Endpoint Has Been Updated * Get All By Status Methods Have Been Updated * STUDENT_PASSWORD_OPERATION_API_TAG Has Been Added to SisSwaggerConfiguration Class * feUrl Field Has Been Added to SisOperationInfoRequest Class * STUDENT_PASSWORD_OPERATION Endpoint Has Been Added to SisControllerEndpoint Class * unauthorizedResponse Method Has Been Added to SisResponseUtil Class * ForgotPasswordResponse Class Has Been Deleted * PasswordOutService Classes Have Been Created * StudentLoginMapping Class Has Been Moved to common Package * StudentLoginInfoEntity Class Has Been Moved to common Package * StudentLoginRequest Class Has Been Moved to common Package * StudentLogin Repository Classes Have Been Moved to common Package * StudentLogin Service Classes Have Been Moved to common Package and forgotPassword Method Has Been Deleted Because Method Has Been Moved to PasswordOperationService * StudentLoginController Class Has Been Moved to common Package * StudentLogin Out Service Classes Have Been Created * StudentPasswordOperationMapping Class Has Been Created * StudentPasswordChangeEntity Class Has Been Created * StudentPasswordOperationEntity Class Has Been Created * StudentPasswordChangeRequest Class Has Been Created * StudentPasswordForgotRequest Class Has Been Moved to password Package * Student Password Operation Response Classes Have Been Created * StudentPasswordOperationInfoConverter Class Has Been Created * Student Password Operation Repository Classes Have Been Created * Student Password Operation Service Classes Have Been Created * Student Password Operation Controller Classes Have Been Created * Student Password Operation Out Service Classes Have Been Created * getStudentInfoDetailResponse Method Has Been Added to StudentOutService * ChangePassword URL Has Been Added to Student Mails && Service Codes Has Been Refactored and Updated * Password Operations Have Been Added to Student Saving Processes * Teacher Login Operation Classes Have Been Moved to common Package * TEACHER_PASSWORD_OPERATION_API_TAG Has Been Added to SisSwaggerConfiguration Class * TEACHER_PASSWORD_OPERATION Endpoint Have Been Added to SisControllerEndpoint Class * final Key Has Been Added to studentId Parameter in isPasswordExist Method * final Key Has Been Added to studentId Parameter in getStudentInfoDetailResponse Method * Teacher Login Repository Classes Have Been Updated * Teacher/forgotPassword Method Has Been Deleted Because Method Has Been Added to password Package * final Key Has Been Added to academicInfoResponse and personalInfoResponse Parameters in convert Method * throws SisNotExistException Has Been Added to saveTeacher Method * teacherForgotPassword Method Has Been Deleted Because Method Has Been Added to password Package * Teacher Login Out Service Classes Have Been Created * getTeacherInfoDetailResponse and ifTeacherIsNotExistThrowNotExistException Methods Have Been Added to Teacher Out Service * throws SisNotExistException Has Been Added to saveTeacher Method * TeacherPasswordOperationMapping Class Has Been Created * TeacherPasswordOperation Request Classes Have Been Created * TeacherPasswordOperation Entity Classes Have Been Created * TeacherPasswordOperationInfoConverter Class Has Been Created * TeacherPasswordOperation Repository Classes Have Been Created * TeacherPasswordOperation Response Classes Have Been Created * TeacherPasswordOperation Service Classes Have Been Created * TeacherPasswordOperation Controller Classes Have Been Created * TeacherPasswordOperation Out Service Classes Have Been Created * ChangePassword URL Has Been Added to Teacher Mails && Service Codes Has Been Refactored and Updated * Password Operations Have Been Added to Teacher Saving Processes * Officer Login Operation Classes Have Been Moved to common Package * TeacherLogin Service Classes Have Been Updated * PasswordService Bean Has Been Deleted in TeacherLoginRepository Because It's Unused * officerForgotPassword Method Has Been Deleted Because It's Unused * OFFICER_PASSWORD_OPERATION Endpoint Has Been Added to SisControllerEndpoint Class * OFFICER_PASSWORD_OPERATION_API_TAG Has Been Added to SisSwaggerConfiguration Class * throws SisNotExistException Has Been Added to saveOfficer Method * throws SisNotExistException Has Been Deleted Because It's Unused * OfficerPasswordOperationMapping Class Has Been Created * OfficerPasswordChangeEntity and OfficerPasswordOperationEntity Classes Have Been Created * OfficerPasswordChangeRequest and OfficerPasswordForgotRequest Classes Have Been Created * OfficerPasswordChangeResponse, OfficerPasswordForgotResponse and OfficerPasswordOperationResponse Classes Have Been Created * OfficerPasswordOperationInfoConverter Class Has Been Created * OfficerPasswordOperation Repository Classes Have Been Created * OfficerPasswordOperation Service Classes Have Been Created * OfficerPasswordOperation Controller Classes Have Been Created * OfficerPasswordOperation Out Service Classes Have Been Created * OfficerLogin Repository Classes Have Been Updated and isPasswordExist Method Has Been Added to OfficerLogin Repository Classes * OfficerLogin Out Service Classes Have Been Created * Officer Out Service Classes Have Been Created * ChangePassword URL Has Been Added to Officer Mails && Service Codes Has Been Refactored and Updated * Password Operations Have Been Added to Officer Saving Processes --- .../config/SisSwaggerConfiguration.java | 8 +- .../dto/request/SisOperationInfoRequest.java | 2 + .../endpoint/SisControllerEndpoint.java | 4 + .../controller/response/SisResponseUtil.java | 8 ++ .../response/ForgotPasswordResponse.java | 11 -- .../common/service/PasswordOutService.java | 6 + .../service/impl/PasswordOutServiceImpl.java | 18 +++ .../controller/OfficerLoginController.java | 19 +-- .../request/OfficerForgotPasswordRequest.java | 2 +- .../dto/request/OfficerLoginRequest.java | 2 +- .../model/entity/OfficerLoginInfoEntity.java | 2 +- .../model/mapping/OfficerLoginMapping.java | 2 +- .../repository/OfficerLoginRepository.java | 10 +- .../impl/OfficerLoginRepositoryImpl.java | 48 +++---- .../impl/scripts/OfficerLoginSqlScripts.java | 17 ++- .../service/OfficerLoginOutService.java | 6 + .../common/service/OfficerLoginService.java | 9 ++ .../impl/OfficerLoginOutServiceImpl.java | 25 ++++ .../service/impl/OfficerLoginServiceImpl.java | 28 +--- .../OfficerPasswordOperationController.java | 65 +++++++++ ...erPasswordOperationControllerEndpoint.java | 10 ++ ...OfficerPasswordOperationInfoConverter.java | 34 +++++ .../request/OfficerPasswordChangeRequest.java | 23 ++++ .../request/OfficerPasswordForgotRequest.java | 22 +++ .../OfficerPasswordChangeResponse.java | 21 +++ .../OfficerPasswordForgotResponse.java | 11 ++ .../OfficerPasswordOperationResponse.java | 16 +++ .../entity/OfficerPasswordChangeEntity.java | 12 ++ .../OfficerPasswordOperationEntity.java | 16 +++ .../OfficerPasswordOperationMapping.java | 24 ++++ .../OfficerPasswordOperationRepository.java | 20 +++ ...fficerPasswordOperationRepositoryImpl.java | 126 ++++++++++++++++++ .../OfficerPasswordOperationSqlScripts.java | 70 ++++++++++ .../OfficerPasswordOperationOutService.java | 10 ++ .../OfficerPasswordOperationService.java | 16 +++ ...fficerPasswordOperationOutServiceImpl.java | 96 +++++++++++++ .../OfficerPasswordOperationServiceImpl.java | 92 +++++++++++++ .../officer/service/OfficerLoginService.java | 15 --- .../controller/StudentLoginController.java | 19 +-- .../dto/request/StudentLoginRequest.java | 2 +- .../model/entity/StudentLoginInfoEntity.java | 2 +- .../model/mapping/StudentLoginMapping.java | 2 +- .../repository/StudentLoginRepository.java | 10 +- .../impl/StudentLoginRepositoryImpl.java | 50 +++---- .../impl/scripts/StudentLoginSqlScripts.java | 18 ++- .../service/StudentLoginOutService.java | 6 + .../common/service/StudentLoginService.java | 9 ++ .../impl/StudentLoginOutServiceImpl.java | 25 ++++ .../service/impl/StudentLoginServiceImpl.java | 23 +--- .../StudentPasswordOperationController.java | 65 +++++++++ ...ntPasswordOperationControllerEndpoint.java | 10 ++ ...StudentPasswordOperationInfoConverter.java | 34 +++++ .../request/StudentPasswordChangeRequest.java | 23 ++++ .../StudentPasswordForgotRequest.java} | 7 +- .../StudentPasswordChangeResponse.java | 21 +++ .../StudentPasswordForgotResponse.java | 11 ++ .../StudentPasswordOperationResponse.java | 16 +++ .../entity/StudentPasswordChangeEntity.java | 12 ++ .../StudentPasswordOperationEntity.java | 16 +++ .../StudentPasswordOperationMapping.java | 24 ++++ .../StudentPasswordOperationRepository.java | 20 +++ ...tudentPasswordOperationRepositoryImpl.java | 126 ++++++++++++++++++ .../StudentPasswordOperationSqlScripts.java | 70 ++++++++++ .../StudentPasswordOperationOutService.java | 10 ++ .../StudentPasswordOperationService.java | 16 +++ ...tudentPasswordOperationOutServiceImpl.java | 96 +++++++++++++ .../StudentPasswordOperationServiceImpl.java | 92 +++++++++++++ .../student/service/StudentLoginService.java | 14 -- .../controller/TeacherLoginController.java | 19 +-- .../request/TeacherForgotPasswordRequest.java | 2 +- .../dto/request/TeacherLoginRequest.java | 2 +- .../model/entity/TeacherLoginInfoEntity.java | 2 +- .../model/mapping/TeacherLoginMapping.java | 2 +- .../repository/TeacherLoginRepository.java | 10 +- .../impl/TeacherLoginRepositoryImpl.java | 50 +++---- .../impl/scripts/TeacherLoginSqlScripts.java | 18 ++- .../service/TeacherLoginOutService.java | 6 + .../common/service/TeacherLoginService.java | 9 ++ .../impl/TeacherLoginOutServiceImpl.java | 25 ++++ .../service/impl/TeacherLoginServiceImpl.java | 23 +--- .../TeacherPasswordOperationController.java | 65 +++++++++ ...erPasswordOperationControllerEndpoint.java | 10 ++ ...TeacherPasswordOperationInfoConverter.java | 34 +++++ .../request/TeacherPasswordChangeRequest.java | 23 ++++ .../request/TeacherPasswordForgotRequest.java | 22 +++ .../TeacherPasswordChangeResponse.java | 21 +++ .../TeacherPasswordForgotResponse.java | 11 ++ .../TeacherPasswordOperationResponse.java | 16 +++ .../entity/TeacherPasswordChangeEntity.java | 12 ++ .../TeacherPasswordOperationEntity.java | 16 +++ .../TeacherPasswordOperationMapping.java | 24 ++++ .../TeacherPasswordOperationRepository.java | 20 +++ ...eacherPasswordOperationRepositoryImpl.java | 126 ++++++++++++++++++ .../TeacherPasswordOperationSqlScripts.java | 70 ++++++++++ .../TeacherPasswordOperationOutService.java | 10 ++ .../TeacherPasswordOperationService.java | 16 +++ ...eacherPasswordOperationOutServiceImpl.java | 96 +++++++++++++ .../TeacherPasswordOperationServiceImpl.java | 92 +++++++++++++ .../teacher/service/TeacherLoginService.java | 14 -- .../mail/service/OfficerMailService.java | 2 +- .../mail/service/StudentMailService.java | 5 +- .../mail/service/TeacherMailService.java | 5 +- .../service/impl/OfficerMailServiceImpl.java | 78 +++++------ .../service/impl/StudentMailServiceImpl.java | 80 +++++------ .../service/impl/TeacherMailServiceImpl.java | 81 +++++------ .../officer/controller/OfficerController.java | 2 +- .../officer/service/OfficerOutService.java | 14 ++ .../officer/service/OfficerService.java | 2 +- .../service/impl/OfficerOutServiceImpl.java | 44 ++++++ .../service/impl/OfficerServiceImpl.java | 9 +- .../student/service/StudentOutService.java | 3 + .../service/impl/StudentOutServiceImpl.java | 9 ++ .../service/impl/StudentServiceImpl.java | 22 +-- .../teacher/controller/TeacherController.java | 2 +- .../TeacherInfoResponseConverter.java | 4 +- .../teacher/service/TeacherOutService.java | 6 + .../teacher/service/TeacherService.java | 2 +- .../service/impl/TeacherOutServiceImpl.java | 18 +++ .../service/impl/TeacherServiceImpl.java | 9 +- 119 files changed, 2602 insertions(+), 436 deletions(-) delete mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/common/model/response/ForgotPasswordResponse.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/common/service/PasswordOutService.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/common/service/impl/PasswordOutServiceImpl.java rename src/main/java/com/graduationproject/studentinformationsystem/login/officer/{ => common}/controller/OfficerLoginController.java (66%) rename src/main/java/com/graduationproject/studentinformationsystem/login/officer/{ => common}/model/dto/request/OfficerForgotPasswordRequest.java (94%) rename src/main/java/com/graduationproject/studentinformationsystem/login/officer/{ => common}/model/dto/request/OfficerLoginRequest.java (94%) rename src/main/java/com/graduationproject/studentinformationsystem/login/officer/{ => common}/model/entity/OfficerLoginInfoEntity.java (93%) rename src/main/java/com/graduationproject/studentinformationsystem/login/officer/{ => common}/model/mapping/OfficerLoginMapping.java (96%) rename src/main/java/com/graduationproject/studentinformationsystem/login/officer/{ => common}/repository/OfficerLoginRepository.java (60%) rename src/main/java/com/graduationproject/studentinformationsystem/login/officer/{ => common}/repository/impl/OfficerLoginRepositoryImpl.java (75%) rename src/main/java/com/graduationproject/studentinformationsystem/login/officer/{ => common}/repository/impl/scripts/OfficerLoginSqlScripts.java (75%) create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/service/OfficerLoginOutService.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/service/OfficerLoginService.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/service/impl/OfficerLoginOutServiceImpl.java rename src/main/java/com/graduationproject/studentinformationsystem/login/officer/{ => common}/service/impl/OfficerLoginServiceImpl.java (67%) create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/controller/OfficerPasswordOperationController.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/controller/endpoint/OfficerPasswordOperationControllerEndpoint.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/model/dto/converter/OfficerPasswordOperationInfoConverter.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/model/dto/request/OfficerPasswordChangeRequest.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/model/dto/request/OfficerPasswordForgotRequest.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/model/dto/response/OfficerPasswordChangeResponse.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/model/dto/response/OfficerPasswordForgotResponse.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/model/dto/response/OfficerPasswordOperationResponse.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/model/entity/OfficerPasswordChangeEntity.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/model/entity/OfficerPasswordOperationEntity.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/model/mapping/OfficerPasswordOperationMapping.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/repository/OfficerPasswordOperationRepository.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/repository/impl/OfficerPasswordOperationRepositoryImpl.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/repository/impl/scripts/OfficerPasswordOperationSqlScripts.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/service/OfficerPasswordOperationOutService.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/service/OfficerPasswordOperationService.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/service/impl/OfficerPasswordOperationOutServiceImpl.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/service/impl/OfficerPasswordOperationServiceImpl.java delete mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/officer/service/OfficerLoginService.java rename src/main/java/com/graduationproject/studentinformationsystem/login/student/{ => common}/controller/StudentLoginController.java (66%) rename src/main/java/com/graduationproject/studentinformationsystem/login/student/{ => common}/model/dto/request/StudentLoginRequest.java (94%) rename src/main/java/com/graduationproject/studentinformationsystem/login/student/{ => common}/model/entity/StudentLoginInfoEntity.java (93%) rename src/main/java/com/graduationproject/studentinformationsystem/login/student/{ => common}/model/mapping/StudentLoginMapping.java (96%) rename src/main/java/com/graduationproject/studentinformationsystem/login/student/{ => common}/repository/StudentLoginRepository.java (60%) rename src/main/java/com/graduationproject/studentinformationsystem/login/student/{ => common}/repository/impl/StudentLoginRepositoryImpl.java (74%) rename src/main/java/com/graduationproject/studentinformationsystem/login/student/{ => common}/repository/impl/scripts/StudentLoginSqlScripts.java (73%) create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/student/common/service/StudentLoginOutService.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/student/common/service/StudentLoginService.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/student/common/service/impl/StudentLoginOutServiceImpl.java rename src/main/java/com/graduationproject/studentinformationsystem/login/student/{ => common}/service/impl/StudentLoginServiceImpl.java (70%) create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/student/password/controller/StudentPasswordOperationController.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/student/password/controller/endpoint/StudentPasswordOperationControllerEndpoint.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/student/password/model/dto/converter/StudentPasswordOperationInfoConverter.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/student/password/model/dto/request/StudentPasswordChangeRequest.java rename src/main/java/com/graduationproject/studentinformationsystem/login/student/{model/dto/request/StudentForgotPasswordRequest.java => password/model/dto/request/StudentPasswordForgotRequest.java} (75%) create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/student/password/model/dto/response/StudentPasswordChangeResponse.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/student/password/model/dto/response/StudentPasswordForgotResponse.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/student/password/model/dto/response/StudentPasswordOperationResponse.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/student/password/model/entity/StudentPasswordChangeEntity.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/student/password/model/entity/StudentPasswordOperationEntity.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/student/password/model/mapping/StudentPasswordOperationMapping.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/student/password/repository/StudentPasswordOperationRepository.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/student/password/repository/impl/StudentPasswordOperationRepositoryImpl.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/student/password/repository/impl/scripts/StudentPasswordOperationSqlScripts.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/student/password/service/StudentPasswordOperationOutService.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/student/password/service/StudentPasswordOperationService.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/student/password/service/impl/StudentPasswordOperationOutServiceImpl.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/student/password/service/impl/StudentPasswordOperationServiceImpl.java delete mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/student/service/StudentLoginService.java rename src/main/java/com/graduationproject/studentinformationsystem/login/teacher/{ => common}/controller/TeacherLoginController.java (66%) rename src/main/java/com/graduationproject/studentinformationsystem/login/teacher/{ => common}/model/dto/request/TeacherForgotPasswordRequest.java (94%) rename src/main/java/com/graduationproject/studentinformationsystem/login/teacher/{ => common}/model/dto/request/TeacherLoginRequest.java (94%) rename src/main/java/com/graduationproject/studentinformationsystem/login/teacher/{ => common}/model/entity/TeacherLoginInfoEntity.java (93%) rename src/main/java/com/graduationproject/studentinformationsystem/login/teacher/{ => common}/model/mapping/TeacherLoginMapping.java (96%) rename src/main/java/com/graduationproject/studentinformationsystem/login/teacher/{ => common}/repository/TeacherLoginRepository.java (60%) rename src/main/java/com/graduationproject/studentinformationsystem/login/teacher/{ => common}/repository/impl/TeacherLoginRepositoryImpl.java (74%) rename src/main/java/com/graduationproject/studentinformationsystem/login/teacher/{ => common}/repository/impl/scripts/TeacherLoginSqlScripts.java (73%) create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/service/TeacherLoginOutService.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/service/TeacherLoginService.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/service/impl/TeacherLoginOutServiceImpl.java rename src/main/java/com/graduationproject/studentinformationsystem/login/teacher/{ => common}/service/impl/TeacherLoginServiceImpl.java (70%) create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/controller/TeacherPasswordOperationController.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/controller/endpoint/TeacherPasswordOperationControllerEndpoint.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/model/dto/converter/TeacherPasswordOperationInfoConverter.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/model/dto/request/TeacherPasswordChangeRequest.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/model/dto/request/TeacherPasswordForgotRequest.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/model/dto/response/TeacherPasswordChangeResponse.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/model/dto/response/TeacherPasswordForgotResponse.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/model/dto/response/TeacherPasswordOperationResponse.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/model/entity/TeacherPasswordChangeEntity.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/model/entity/TeacherPasswordOperationEntity.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/model/mapping/TeacherPasswordOperationMapping.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/repository/TeacherPasswordOperationRepository.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/repository/impl/TeacherPasswordOperationRepositoryImpl.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/repository/impl/scripts/TeacherPasswordOperationSqlScripts.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/service/TeacherPasswordOperationOutService.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/service/TeacherPasswordOperationService.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/service/impl/TeacherPasswordOperationOutServiceImpl.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/service/impl/TeacherPasswordOperationServiceImpl.java delete mode 100644 src/main/java/com/graduationproject/studentinformationsystem/login/teacher/service/TeacherLoginService.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/officer/service/OfficerOutService.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/officer/service/impl/OfficerOutServiceImpl.java diff --git a/src/main/java/com/graduationproject/studentinformationsystem/common/config/SisSwaggerConfiguration.java b/src/main/java/com/graduationproject/studentinformationsystem/common/config/SisSwaggerConfiguration.java index f02f3265..404c599e 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/common/config/SisSwaggerConfiguration.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/common/config/SisSwaggerConfiguration.java @@ -31,6 +31,9 @@ public class SisSwaggerConfiguration { public static final String TEACHER_LESSON_API_TAG = "Teacher Lesson Controller"; public static final String OFFICER_API_TAG = "Officer Controller"; public static final String LOGIN_API_TAG = "Login Controller"; + public static final String STUDENT_PASSWORD_OPERATION_API_TAG = "Student Password Operation Controller"; + public static final String TEACHER_PASSWORD_OPERATION_API_TAG = "Teacher Password Operation Controller"; + public static final String OFFICER_PASSWORD_OPERATION_API_TAG = "Officer Password Operation Controller"; @Bean public Docket api() { @@ -51,7 +54,10 @@ public Docket api() { new Tag(TEACHER_API_TAG, "TEACHER_ACADEMIC_INFO & TEACHER_PERSONAL_INFO"), new Tag(TEACHER_LESSON_API_TAG, "TEACHER_LESSON"), new Tag(OFFICER_API_TAG, "OFFICER_ACADEMIC_INFO & OFFICER_PERSONAL_INFO"), - new Tag(LOGIN_API_TAG, "AUTH_STUDENT_LOGIN & AUTH_TEACHER_LOGIN & AUTH_OFFICER_LOGIN") + new Tag(LOGIN_API_TAG, "AUTH_STUDENT_LOGIN & AUTH_TEACHER_LOGIN & AUTH_OFFICER_LOGIN"), + new Tag(STUDENT_PASSWORD_OPERATION_API_TAG, "AUTH_STUDENT_PASSWORD_OPERATION"), + new Tag(TEACHER_PASSWORD_OPERATION_API_TAG, "AUTH_TEACHER_PASSWORD_OPERATION"), + new Tag(OFFICER_PASSWORD_OPERATION_API_TAG, "AUTH_OFFICER_PASSWORD_OPERATION") ); } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/common/model/dto/request/SisOperationInfoRequest.java b/src/main/java/com/graduationproject/studentinformationsystem/common/model/dto/request/SisOperationInfoRequest.java index c3ae6362..492ba6ff 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/common/model/dto/request/SisOperationInfoRequest.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/common/model/dto/request/SisOperationInfoRequest.java @@ -16,4 +16,6 @@ public class SisOperationInfoRequest implements Serializable { @NotNull @OperationUserID private Long userId; + + private String feUrl; } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/common/util/controller/endpoint/SisControllerEndpoint.java b/src/main/java/com/graduationproject/studentinformationsystem/common/util/controller/endpoint/SisControllerEndpoint.java index e0d738ad..768c2205 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/common/util/controller/endpoint/SisControllerEndpoint.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/common/util/controller/endpoint/SisControllerEndpoint.java @@ -10,6 +10,7 @@ private Path() { } private static final String REGISTRATION = "/registration"; + private static final String PASSWORD_OPERATION = "/password-operation"; public static final String FACULTY = "/faculty"; public static final String DEPARTMENT = "/department"; @@ -23,5 +24,8 @@ private Path() { public static final String TEACHER_LESSON = TEACHER + LESSON; public static final String OFFICER = "/officer"; public static final String LOGIN = "/login"; + public static final String STUDENT_PASSWORD_OPERATION = STUDENT + PASSWORD_OPERATION; + public static final String TEACHER_PASSWORD_OPERATION = TEACHER + PASSWORD_OPERATION; + public static final String OFFICER_PASSWORD_OPERATION = OFFICER + PASSWORD_OPERATION; } } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/common/util/controller/response/SisResponseUtil.java b/src/main/java/com/graduationproject/studentinformationsystem/common/util/controller/response/SisResponseUtil.java index 21469b37..aeb47a56 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/common/util/controller/response/SisResponseUtil.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/common/util/controller/response/SisResponseUtil.java @@ -18,6 +18,14 @@ public static ResponseEntity successResponse() { .isSuccess(true).build(), HttpStatus.OK); } + public static ResponseEntity unauthorizedResponse() { + return new ResponseEntity<>( + SisApiResponse.builder() + .requestTime(LocalDateTime.now()) + .httpStatus(HttpStatus.UNAUTHORIZED) + .isSuccess(false).build(), HttpStatus.UNAUTHORIZED); + } + public static ResponseEntity> successResponse(final T response) { return new ResponseEntity<>( SisBaseApiResponse.builder() diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/common/model/response/ForgotPasswordResponse.java b/src/main/java/com/graduationproject/studentinformationsystem/login/common/model/response/ForgotPasswordResponse.java deleted file mode 100644 index 08cebe01..00000000 --- a/src/main/java/com/graduationproject/studentinformationsystem/login/common/model/response/ForgotPasswordResponse.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.graduationproject.studentinformationsystem.login.common.model.response; - -import lombok.Builder; -import lombok.Getter; - -@Getter -@Builder -public class ForgotPasswordResponse { - - private boolean isForgotPasswordSuccess; -} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/common/service/PasswordOutService.java b/src/main/java/com/graduationproject/studentinformationsystem/login/common/service/PasswordOutService.java new file mode 100644 index 00000000..9b1aae59 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/common/service/PasswordOutService.java @@ -0,0 +1,6 @@ +package com.graduationproject.studentinformationsystem.login.common.service; + +public interface PasswordOutService { + + String getEncodedPassword(String newPassword); +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/common/service/impl/PasswordOutServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/login/common/service/impl/PasswordOutServiceImpl.java new file mode 100644 index 00000000..9c2a79bc --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/common/service/impl/PasswordOutServiceImpl.java @@ -0,0 +1,18 @@ +package com.graduationproject.studentinformationsystem.login.common.service.impl; + +import com.graduationproject.studentinformationsystem.login.common.service.PasswordOutService; +import com.graduationproject.studentinformationsystem.login.common.service.PasswordService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class PasswordOutServiceImpl implements PasswordOutService { + + private final PasswordService passwordService; + + @Override + public String getEncodedPassword(String newPassword) { + return passwordService.encodePassword(newPassword); + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/controller/OfficerLoginController.java b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/controller/OfficerLoginController.java similarity index 66% rename from src/main/java/com/graduationproject/studentinformationsystem/login/officer/controller/OfficerLoginController.java rename to src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/controller/OfficerLoginController.java index 2db77e14..245f1f28 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/controller/OfficerLoginController.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/controller/OfficerLoginController.java @@ -1,13 +1,10 @@ -package com.graduationproject.studentinformationsystem.login.officer.controller; +package com.graduationproject.studentinformationsystem.login.officer.common.controller; import com.graduationproject.studentinformationsystem.common.util.controller.response.SisBaseApiResponse; -import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; import com.graduationproject.studentinformationsystem.login.common.controller.enpoint.LoginControllerEndpoint; -import com.graduationproject.studentinformationsystem.login.common.model.response.ForgotPasswordResponse; import com.graduationproject.studentinformationsystem.login.common.model.response.LoginResponse; -import com.graduationproject.studentinformationsystem.login.officer.model.dto.request.OfficerForgotPasswordRequest; -import com.graduationproject.studentinformationsystem.login.officer.model.dto.request.OfficerLoginRequest; -import com.graduationproject.studentinformationsystem.login.officer.service.OfficerLoginService; +import com.graduationproject.studentinformationsystem.login.officer.common.model.dto.request.OfficerLoginRequest; +import com.graduationproject.studentinformationsystem.login.officer.common.service.OfficerLoginService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; @@ -39,14 +36,4 @@ public ResponseEntity> officerLogin( final LoginResponse loginResponse = loginService.login(loginRequest); return successResponse(loginResponse); } - - @PostMapping(LoginControllerEndpoint.OFFICER_FORGOT_PASSWORD) - @ApiOperation(value = "Officer Forgot Password") - public ResponseEntity> officerForgotPassword( - @RequestBody @Valid final OfficerForgotPasswordRequest forgotPasswordRequest) - throws SisNotExistException { - - final ForgotPasswordResponse forgotPasswordResponse = loginService.forgotPassword(forgotPasswordRequest); - return successResponse(forgotPasswordResponse); - } } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/model/dto/request/OfficerForgotPasswordRequest.java b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/model/dto/request/OfficerForgotPasswordRequest.java similarity index 94% rename from src/main/java/com/graduationproject/studentinformationsystem/login/officer/model/dto/request/OfficerForgotPasswordRequest.java rename to src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/model/dto/request/OfficerForgotPasswordRequest.java index d7fd59ee..e12daa75 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/model/dto/request/OfficerForgotPasswordRequest.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/model/dto/request/OfficerForgotPasswordRequest.java @@ -1,4 +1,4 @@ -package com.graduationproject.studentinformationsystem.login.officer.model.dto.request; +package com.graduationproject.studentinformationsystem.login.officer.common.model.dto.request; import com.graduationproject.studentinformationsystem.common.util.validation.id.OfficerID; import lombok.Getter; diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/model/dto/request/OfficerLoginRequest.java b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/model/dto/request/OfficerLoginRequest.java similarity index 94% rename from src/main/java/com/graduationproject/studentinformationsystem/login/officer/model/dto/request/OfficerLoginRequest.java rename to src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/model/dto/request/OfficerLoginRequest.java index 6732768a..afa21197 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/model/dto/request/OfficerLoginRequest.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/model/dto/request/OfficerLoginRequest.java @@ -1,4 +1,4 @@ -package com.graduationproject.studentinformationsystem.login.officer.model.dto.request; +package com.graduationproject.studentinformationsystem.login.officer.common.model.dto.request; import com.graduationproject.studentinformationsystem.common.util.validation.id.OfficerID; import lombok.Getter; diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/model/entity/OfficerLoginInfoEntity.java b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/model/entity/OfficerLoginInfoEntity.java similarity index 93% rename from src/main/java/com/graduationproject/studentinformationsystem/login/officer/model/entity/OfficerLoginInfoEntity.java rename to src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/model/entity/OfficerLoginInfoEntity.java index eef0479e..a14e82dc 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/model/entity/OfficerLoginInfoEntity.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/model/entity/OfficerLoginInfoEntity.java @@ -1,4 +1,4 @@ -package com.graduationproject.studentinformationsystem.login.officer.model.entity; +package com.graduationproject.studentinformationsystem.login.officer.common.model.entity; import com.graduationproject.studentinformationsystem.common.model.entity.SisBaseLoginInfoEntity; import lombok.Getter; diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/model/mapping/OfficerLoginMapping.java b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/model/mapping/OfficerLoginMapping.java similarity index 96% rename from src/main/java/com/graduationproject/studentinformationsystem/login/officer/model/mapping/OfficerLoginMapping.java rename to src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/model/mapping/OfficerLoginMapping.java index 82acb861..adb2877a 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/model/mapping/OfficerLoginMapping.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/model/mapping/OfficerLoginMapping.java @@ -1,4 +1,4 @@ -package com.graduationproject.studentinformationsystem.login.officer.model.mapping; +package com.graduationproject.studentinformationsystem.login.officer.common.model.mapping; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/repository/OfficerLoginRepository.java b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/repository/OfficerLoginRepository.java similarity index 60% rename from src/main/java/com/graduationproject/studentinformationsystem/login/officer/repository/OfficerLoginRepository.java rename to src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/repository/OfficerLoginRepository.java index 4e4ffd67..4d4ac478 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/repository/OfficerLoginRepository.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/repository/OfficerLoginRepository.java @@ -1,6 +1,6 @@ -package com.graduationproject.studentinformationsystem.login.officer.repository; +package com.graduationproject.studentinformationsystem.login.officer.common.repository; -import com.graduationproject.studentinformationsystem.login.officer.model.entity.OfficerLoginInfoEntity; +import com.graduationproject.studentinformationsystem.login.officer.common.model.entity.OfficerLoginInfoEntity; public interface OfficerLoginRepository { @@ -8,11 +8,13 @@ public interface OfficerLoginRepository { String getPassword(Long officerId); - void saveFirstPassword(Long officerId, String password); + void savePassword(Long officerId, String encodedPassword); - void updatePassword(Long officerId, String password); + void updatePassword(Long officerId, String encodedPassword); void updateLoginInfo(OfficerLoginInfoEntity loginInfoEntity); void updateFailCounter(Long officerId); + + boolean isPasswordExist(Long officerId); } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/repository/impl/OfficerLoginRepositoryImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/repository/impl/OfficerLoginRepositoryImpl.java similarity index 75% rename from src/main/java/com/graduationproject/studentinformationsystem/login/officer/repository/impl/OfficerLoginRepositoryImpl.java rename to src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/repository/impl/OfficerLoginRepositoryImpl.java index ae93ad46..dd4e0070 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/repository/impl/OfficerLoginRepositoryImpl.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/repository/impl/OfficerLoginRepositoryImpl.java @@ -1,24 +1,21 @@ -package com.graduationproject.studentinformationsystem.login.officer.repository.impl; +package com.graduationproject.studentinformationsystem.login.officer.common.repository.impl; import com.graduationproject.studentinformationsystem.common.util.exception.SisDatabaseException; -import com.graduationproject.studentinformationsystem.login.common.service.PasswordService; -import com.graduationproject.studentinformationsystem.login.officer.model.entity.OfficerLoginInfoEntity; -import com.graduationproject.studentinformationsystem.login.officer.repository.OfficerLoginRepository; +import com.graduationproject.studentinformationsystem.login.officer.common.model.entity.OfficerLoginInfoEntity; +import com.graduationproject.studentinformationsystem.login.officer.common.repository.OfficerLoginRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; import org.sql2o.Connection; import org.sql2o.Query; import org.sql2o.Sql2o; -import static com.graduationproject.studentinformationsystem.login.officer.model.mapping.OfficerLoginMapping.*; -import static com.graduationproject.studentinformationsystem.login.officer.repository.impl.scripts.OfficerLoginSqlScripts.*; +import static com.graduationproject.studentinformationsystem.login.officer.common.model.mapping.OfficerLoginMapping.*; +import static com.graduationproject.studentinformationsystem.login.officer.common.repository.impl.scripts.OfficerLoginSqlScripts.*; @Repository @RequiredArgsConstructor public class OfficerLoginRepositoryImpl implements OfficerLoginRepository { - private final PasswordService passwordService; - private final Sql2o sql2o; @Override @@ -52,11 +49,11 @@ public String getPassword(final Long officerId) { } @Override - public void saveFirstPassword(final Long officerId, final String password) { + public void savePassword(final Long officerId, final String encodedPassword) { try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(SAVE_OFFICER_FIRST_PASSWORD)) { query.addParameter(OFFICER_ID.getModelName(), officerId) - .addParameter(PASSWORD.getModelName(), passwordService.encodePassword(password)) + .addParameter(PASSWORD.getModelName(), encodedPassword) .addParameter(FAIL_COUNTER.getModelName(), 0) .executeUpdate(); @@ -68,11 +65,12 @@ public void saveFirstPassword(final Long officerId, final String password) { } @Override - public void updatePassword(final Long officerId, final String password) { + public void updatePassword(final Long officerId, final String encodedPassword) { try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(UPDATE_OFFICER_PASSWORD)) { query.addParameter(OFFICER_ID.getModelName(), officerId) - .addParameter(PASSWORD.getModelName(), passwordService.encodePassword(password)) + .addParameter(PASSWORD.getModelName(), encodedPassword) + .addParameter(FAIL_COUNTER.getModelName(), 0) .executeUpdate(); // TODO: Specific Info Log Must be Added @@ -113,21 +111,17 @@ public void updateFailCounter(final Long officerId) { } } -// TODO: Change or Update Password -// @Override -// public void updatePassword(final OfficerLoginInfoEntity loginInfoEntity) { -// try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(UPDATE_OFFICER_PASSWORD)) { -// -// query.addParameter(OFFICER_ID.getModelName(), loginInfoEntity.getOfficerId()) -// .addParameter(PASSWORD.getModelName(), loginInfoEntity.getPassword()) -// .addParameter(FAIL_COUNTER.getModelName(), loginInfoEntity.getFailCounter()) -// .addParameter(LAST_LOGIN_DATE.getModelName(), loginInfoEntity.getLastLoginDate()) -// .executeUpdate(); -// + @Override + public boolean isPasswordExist(final Long officerId) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(IS_OFFICER_PASSWORD_EXIST)) { + + return query.addParameter(OFFICER_ID.getModelName(), officerId) + .executeScalar(Boolean.class); + // TODO: Specific Info Log Must be Added -// } catch (Exception exception) { + } catch (Exception exception) { // TODO: Specific Error Log Must be Added -// throw new SisDatabaseException(exception); -// } -// } + throw new SisDatabaseException(exception); + } + } } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/repository/impl/scripts/OfficerLoginSqlScripts.java b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/repository/impl/scripts/OfficerLoginSqlScripts.java similarity index 75% rename from src/main/java/com/graduationproject/studentinformationsystem/login/officer/repository/impl/scripts/OfficerLoginSqlScripts.java rename to src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/repository/impl/scripts/OfficerLoginSqlScripts.java index 6d5b4e4e..793b1df1 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/repository/impl/scripts/OfficerLoginSqlScripts.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/repository/impl/scripts/OfficerLoginSqlScripts.java @@ -1,4 +1,4 @@ -package com.graduationproject.studentinformationsystem.login.officer.repository.impl.scripts; +package com.graduationproject.studentinformationsystem.login.officer.common.repository.impl.scripts; public class OfficerLoginSqlScripts { @@ -30,11 +30,12 @@ private OfficerLoginSqlScripts() { " FAIL_COUNTER=:failCounter").toString(); /** - * UPDATE AUTH_OFFICER_LOGIN SET PASSWORD=:password WHERE OFFICER_ID=:officerId; + * UPDATE AUTH_OFFICER_LOGIN SET PASSWORD=:password, FAIL_COUNTER=:failCounter WHERE OFFICER_ID=:officerId; */ public static final String UPDATE_OFFICER_PASSWORD = sqlBuilder.delete(0, sqlBuilder.length()) - .append("UPDATE AUTH_OFFICER_LOGIN SET PASSWORD=:password WHERE OFFICER_ID=:officerId").toString(); + .append("UPDATE AUTH_OFFICER_LOGIN SET PASSWORD=:password, FAIL_COUNTER=:failCounter " + + "WHERE OFFICER_ID=:officerId").toString(); /** * UPDATE AUTH_OFFICER_LOGIN SET FAIL_COUNTER=:failCounter, LAST_LOGIN_DATE=:lastLoginDate @@ -52,4 +53,14 @@ private OfficerLoginSqlScripts() { sqlBuilder.delete(0, sqlBuilder.length()) .append("UPDATE AUTH_OFFICER_LOGIN SET FAIL_COUNTER=:failCounter " + "WHERE OFFICER_ID=:officerId").toString(); + + /** + * SELECT CASE WHEN MAX(OFFICER_ID) IS NULL THEN 'false' ELSE 'true' END IS_EXIST + * FROM AUTH_OFFICER_LOGIN WHERE OFFICER_ID=:officerId; + */ + public static final String IS_OFFICER_PASSWORD_EXIST = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("SELECT CASE WHEN MAX(OFFICER_ID) IS NULL THEN 'false' ELSE 'true' END IS_EXIST " + + "FROM AUTH_OFFICER_LOGIN WHERE OFFICER_ID=:officerId").toString(); + } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/service/OfficerLoginOutService.java b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/service/OfficerLoginOutService.java new file mode 100644 index 00000000..6b1298da --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/service/OfficerLoginOutService.java @@ -0,0 +1,6 @@ +package com.graduationproject.studentinformationsystem.login.officer.common.service; + +public interface OfficerLoginOutService { + + void saveOrUpdatePassword(Long officerId, String encodedPassword); +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/service/OfficerLoginService.java b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/service/OfficerLoginService.java new file mode 100644 index 00000000..afe4a687 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/service/OfficerLoginService.java @@ -0,0 +1,9 @@ +package com.graduationproject.studentinformationsystem.login.officer.common.service; + +import com.graduationproject.studentinformationsystem.login.common.model.response.LoginResponse; +import com.graduationproject.studentinformationsystem.login.officer.common.model.dto.request.OfficerLoginRequest; + +public interface OfficerLoginService { + + LoginResponse login(OfficerLoginRequest loginRequest); +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/service/impl/OfficerLoginOutServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/service/impl/OfficerLoginOutServiceImpl.java new file mode 100644 index 00000000..80d94bf3 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/service/impl/OfficerLoginOutServiceImpl.java @@ -0,0 +1,25 @@ +package com.graduationproject.studentinformationsystem.login.officer.common.service.impl; + +import com.graduationproject.studentinformationsystem.login.officer.common.repository.OfficerLoginRepository; +import com.graduationproject.studentinformationsystem.login.officer.common.service.OfficerLoginOutService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class OfficerLoginOutServiceImpl implements OfficerLoginOutService { + + private final OfficerLoginRepository officerLoginRepository; + + @Override + public void saveOrUpdatePassword(final Long officerId, final String encodedPassword) { + + boolean isPasswordExist = officerLoginRepository.isPasswordExist(officerId); + + if (!isPasswordExist) { + officerLoginRepository.savePassword(officerId, encodedPassword); + } else { + officerLoginRepository.updatePassword(officerId, encodedPassword); + } + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/service/impl/OfficerLoginServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/service/impl/OfficerLoginServiceImpl.java similarity index 67% rename from src/main/java/com/graduationproject/studentinformationsystem/login/officer/service/impl/OfficerLoginServiceImpl.java rename to src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/service/impl/OfficerLoginServiceImpl.java index 3401b379..00b7d93b 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/service/impl/OfficerLoginServiceImpl.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/common/service/impl/OfficerLoginServiceImpl.java @@ -1,18 +1,12 @@ -package com.graduationproject.studentinformationsystem.login.officer.service.impl; +package com.graduationproject.studentinformationsystem.login.officer.common.service.impl; -import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; -import com.graduationproject.studentinformationsystem.login.common.model.response.ForgotPasswordResponse; import com.graduationproject.studentinformationsystem.login.common.model.response.LoginResponse; import com.graduationproject.studentinformationsystem.login.common.service.PasswordService; -import com.graduationproject.studentinformationsystem.login.officer.model.dto.request.OfficerForgotPasswordRequest; -import com.graduationproject.studentinformationsystem.login.officer.model.dto.request.OfficerLoginRequest; -import com.graduationproject.studentinformationsystem.login.officer.model.entity.OfficerLoginInfoEntity; -import com.graduationproject.studentinformationsystem.login.officer.repository.OfficerLoginRepository; -import com.graduationproject.studentinformationsystem.login.officer.service.OfficerLoginService; -import com.graduationproject.studentinformationsystem.university.mail.service.OfficerMailService; -import com.graduationproject.studentinformationsystem.university.officer.model.dto.response.OfficerInfoDetailResponse; +import com.graduationproject.studentinformationsystem.login.officer.common.model.dto.request.OfficerLoginRequest; +import com.graduationproject.studentinformationsystem.login.officer.common.model.entity.OfficerLoginInfoEntity; +import com.graduationproject.studentinformationsystem.login.officer.common.repository.OfficerLoginRepository; +import com.graduationproject.studentinformationsystem.login.officer.common.service.OfficerLoginService; import com.graduationproject.studentinformationsystem.university.officer.service.OfficerAcademicInfoService; -import com.graduationproject.studentinformationsystem.university.officer.service.OfficerService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -22,9 +16,7 @@ @RequiredArgsConstructor public class OfficerLoginServiceImpl implements OfficerLoginService { - private final OfficerService studentService; private final OfficerAcademicInfoService academicInfoService; - private final OfficerMailService mailService; private final OfficerLoginRepository loginRepository; private final PasswordService passwordService; @@ -48,16 +40,6 @@ public LoginResponse login(final OfficerLoginRequest loginRequest) { return getFailLoginResponse(); } - @Override - public ForgotPasswordResponse forgotPassword(final OfficerForgotPasswordRequest forgotPasswordRequest) throws SisNotExistException { - final OfficerInfoDetailResponse infoDetailResponse = studentService.getOfficerDetailById(forgotPasswordRequest.getOfficerId()); - - mailService.sendForgotPasswordEmail(infoDetailResponse); - - return ForgotPasswordResponse.builder() - .isForgotPasswordSuccess(true).build(); - } - private boolean isOfficerActive(final Long officerId) { return academicInfoService.isOfficerActive(officerId); diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/controller/OfficerPasswordOperationController.java b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/controller/OfficerPasswordOperationController.java new file mode 100644 index 00000000..eb14e556 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/controller/OfficerPasswordOperationController.java @@ -0,0 +1,65 @@ +package com.graduationproject.studentinformationsystem.login.officer.password.controller; + +import com.graduationproject.studentinformationsystem.common.util.controller.response.SisApiResponse; +import com.graduationproject.studentinformationsystem.common.util.controller.response.SisBaseApiResponse; +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.login.officer.password.controller.endpoint.OfficerPasswordOperationControllerEndpoint; +import com.graduationproject.studentinformationsystem.login.officer.password.model.dto.request.OfficerPasswordChangeRequest; +import com.graduationproject.studentinformationsystem.login.officer.password.model.dto.request.OfficerPasswordForgotRequest; +import com.graduationproject.studentinformationsystem.login.officer.password.model.dto.response.OfficerPasswordChangeResponse; +import com.graduationproject.studentinformationsystem.login.officer.password.model.dto.response.OfficerPasswordForgotResponse; +import com.graduationproject.studentinformationsystem.login.officer.password.service.OfficerPasswordOperationService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; + +import static com.graduationproject.studentinformationsystem.common.config.SisSwaggerConfiguration.OFFICER_PASSWORD_OPERATION_API_TAG; +import static com.graduationproject.studentinformationsystem.common.util.controller.endpoint.SisControllerEndpoint.Path.OFFICER_PASSWORD_OPERATION; +import static com.graduationproject.studentinformationsystem.common.util.controller.response.SisResponseUtil.successResponse; +import static com.graduationproject.studentinformationsystem.common.util.controller.response.SisResponseUtil.unauthorizedResponse; + +@RestController +@RequestMapping(OFFICER_PASSWORD_OPERATION) +@Api(tags = OFFICER_PASSWORD_OPERATION_API_TAG) +@RequiredArgsConstructor +public class OfficerPasswordOperationController { + + private final OfficerPasswordOperationService passwordOperationService; + + @GetMapping + @ApiOperation(value = "Is Officer Password Change Operation Enabled") + public ResponseEntity isPasswordChangeOperationEnabled( + @RequestParam final String operationId) throws SisNotExistException { + + final boolean isPasswordChangeEnabled = passwordOperationService.isPasswordChangeEnabled(operationId); + + if (isPasswordChangeEnabled) { + return successResponse(); + } else { + return unauthorizedResponse(); + } + } + + @PostMapping(OfficerPasswordOperationControllerEndpoint.CHANGE_PASSWORD) + @ApiOperation(value = "Change Officer Password") + public ResponseEntity> changePassword( + @RequestBody final OfficerPasswordChangeRequest passwordChangeRequest) throws SisNotExistException { + + final OfficerPasswordChangeResponse passwordChangeResponse = passwordOperationService.changePassword(passwordChangeRequest); + return successResponse(passwordChangeResponse); + } + + @PostMapping(OfficerPasswordOperationControllerEndpoint.FORGOT_PASSWORD) + @ApiOperation(value = "Officer Forgot Password") + public ResponseEntity> forgotPassword( + @RequestBody @Valid final OfficerPasswordForgotRequest passwordForgotRequest) + throws SisNotExistException { + + final OfficerPasswordForgotResponse passwordOperationResponse = passwordOperationService.forgotPassword(passwordForgotRequest); + return successResponse(passwordOperationResponse); + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/controller/endpoint/OfficerPasswordOperationControllerEndpoint.java b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/controller/endpoint/OfficerPasswordOperationControllerEndpoint.java new file mode 100644 index 00000000..7dd82f28 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/controller/endpoint/OfficerPasswordOperationControllerEndpoint.java @@ -0,0 +1,10 @@ +package com.graduationproject.studentinformationsystem.login.officer.password.controller.endpoint; + +public class OfficerPasswordOperationControllerEndpoint { + + private OfficerPasswordOperationControllerEndpoint() { + } + + public static final String CHANGE_PASSWORD = "/change-password"; + public static final String FORGOT_PASSWORD = "/forgot-password"; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/model/dto/converter/OfficerPasswordOperationInfoConverter.java b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/model/dto/converter/OfficerPasswordOperationInfoConverter.java new file mode 100644 index 00000000..6f63a1cb --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/model/dto/converter/OfficerPasswordOperationInfoConverter.java @@ -0,0 +1,34 @@ +package com.graduationproject.studentinformationsystem.login.officer.password.model.dto.converter; + +import com.graduationproject.studentinformationsystem.common.util.SisUtil; +import com.graduationproject.studentinformationsystem.login.officer.password.model.dto.response.OfficerPasswordOperationResponse; +import com.graduationproject.studentinformationsystem.login.officer.password.model.entity.OfficerPasswordOperationEntity; +import org.springframework.stereotype.Component; + +import java.time.LocalDateTime; + +@Component +public class OfficerPasswordOperationInfoConverter { + + public OfficerPasswordOperationEntity generateEntity(final Long officerId, final String feUrl) { + + return OfficerPasswordOperationEntity.builder() + .operationId(SisUtil.generateRandomUUID()) + .officerId(officerId) + .expireDate(LocalDateTime.now().plusDays(1)) + .feUrl(feUrl) + .build(); + } + + public OfficerPasswordOperationResponse entityToResponse(final OfficerPasswordOperationEntity passwordOperationEntity) { + + final String operationId = passwordOperationEntity.getOperationId(); + + return OfficerPasswordOperationResponse.builder() + .operationId(operationId) + .officerId(passwordOperationEntity.getOfficerId()) + .expireDate(passwordOperationEntity.getExpireDate()) + .passwordChangeUrl(passwordOperationEntity.getFeUrl() + "/login/officer/change-password/" + operationId) + .build(); + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/model/dto/request/OfficerPasswordChangeRequest.java b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/model/dto/request/OfficerPasswordChangeRequest.java new file mode 100644 index 00000000..5725f621 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/model/dto/request/OfficerPasswordChangeRequest.java @@ -0,0 +1,23 @@ +package com.graduationproject.studentinformationsystem.login.officer.password.model.dto.request; + +import lombok.Getter; + +import javax.validation.constraints.NotNull; +import java.io.Serial; +import java.io.Serializable; + +@Getter +public class OfficerPasswordChangeRequest implements Serializable { + + @Serial + private static final long serialVersionUID = 2439291607232931077L; + + @NotNull + private String operationId; + + @NotNull + private String newPassword; + + @NotNull + private String newPasswordRepeat; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/model/dto/request/OfficerPasswordForgotRequest.java b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/model/dto/request/OfficerPasswordForgotRequest.java new file mode 100644 index 00000000..e553d199 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/model/dto/request/OfficerPasswordForgotRequest.java @@ -0,0 +1,22 @@ +package com.graduationproject.studentinformationsystem.login.officer.password.model.dto.request; + +import com.graduationproject.studentinformationsystem.common.util.validation.id.OfficerID; +import lombok.Getter; + +import javax.validation.constraints.NotNull; +import java.io.Serial; +import java.io.Serializable; + +@Getter +public class OfficerPasswordForgotRequest implements Serializable { + + @Serial + private static final long serialVersionUID = 8073197753505975378L; + + @NotNull + @OfficerID + private Long officerId; + + @NotNull + private String feUrl; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/model/dto/response/OfficerPasswordChangeResponse.java b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/model/dto/response/OfficerPasswordChangeResponse.java new file mode 100644 index 00000000..001dd9bd --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/model/dto/response/OfficerPasswordChangeResponse.java @@ -0,0 +1,21 @@ +package com.graduationproject.studentinformationsystem.login.officer.password.model.dto.response; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class OfficerPasswordChangeResponse { + + private boolean isPasswordChanged; + + public static OfficerPasswordChangeResponse getSuccessResponse() { + return OfficerPasswordChangeResponse.builder() + .isPasswordChanged(true).build(); + } + + public static OfficerPasswordChangeResponse getFailResponse() { + return OfficerPasswordChangeResponse.builder() + .isPasswordChanged(false).build(); + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/model/dto/response/OfficerPasswordForgotResponse.java b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/model/dto/response/OfficerPasswordForgotResponse.java new file mode 100644 index 00000000..a3b76c99 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/model/dto/response/OfficerPasswordForgotResponse.java @@ -0,0 +1,11 @@ +package com.graduationproject.studentinformationsystem.login.officer.password.model.dto.response; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class OfficerPasswordForgotResponse { + + private boolean isForgotPasswordSuccess; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/model/dto/response/OfficerPasswordOperationResponse.java b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/model/dto/response/OfficerPasswordOperationResponse.java new file mode 100644 index 00000000..835e3a8d --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/model/dto/response/OfficerPasswordOperationResponse.java @@ -0,0 +1,16 @@ +package com.graduationproject.studentinformationsystem.login.officer.password.model.dto.response; + +import lombok.Builder; +import lombok.Getter; + +import java.time.LocalDateTime; + +@Getter +@Builder +public class OfficerPasswordOperationResponse { + + private String operationId; + private Long officerId; + private LocalDateTime expireDate; + private String passwordChangeUrl; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/model/entity/OfficerPasswordChangeEntity.java b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/model/entity/OfficerPasswordChangeEntity.java new file mode 100644 index 00000000..9dbb8888 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/model/entity/OfficerPasswordChangeEntity.java @@ -0,0 +1,12 @@ +package com.graduationproject.studentinformationsystem.login.officer.password.model.entity; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class OfficerPasswordChangeEntity { + + protected String newPassword; + protected String newPasswordRepeat; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/model/entity/OfficerPasswordOperationEntity.java b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/model/entity/OfficerPasswordOperationEntity.java new file mode 100644 index 00000000..cab06ba7 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/model/entity/OfficerPasswordOperationEntity.java @@ -0,0 +1,16 @@ +package com.graduationproject.studentinformationsystem.login.officer.password.model.entity; + +import lombok.Builder; +import lombok.Getter; + +import java.time.LocalDateTime; + +@Getter +@Builder +public class OfficerPasswordOperationEntity { + + private String operationId; + private Long officerId; + private LocalDateTime expireDate; + private String feUrl; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/model/mapping/OfficerPasswordOperationMapping.java b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/model/mapping/OfficerPasswordOperationMapping.java new file mode 100644 index 00000000..75adb774 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/model/mapping/OfficerPasswordOperationMapping.java @@ -0,0 +1,24 @@ +package com.graduationproject.studentinformationsystem.login.officer.password.model.mapping; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +@Getter +@RequiredArgsConstructor +public enum OfficerPasswordOperationMapping { + + OPERATION_ID("OPERATION_ID", "operationId"), + OFFICER_ID("OFFICER_ID", "officerId"), + EXPIRE_DATE("EXPIRE_DATE", "expireDate"), + FE_URL("FE_URL", "feUrl"); + + private final String columnName; + private final String modelName; + + public static final Map COLUMN_MAPPINGS = Stream.of(values()) + .collect(Collectors.toMap(OfficerPasswordOperationMapping::getColumnName, OfficerPasswordOperationMapping::getModelName)); +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/repository/OfficerPasswordOperationRepository.java b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/repository/OfficerPasswordOperationRepository.java new file mode 100644 index 00000000..c9f938b4 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/repository/OfficerPasswordOperationRepository.java @@ -0,0 +1,20 @@ +package com.graduationproject.studentinformationsystem.login.officer.password.repository; + +import com.graduationproject.studentinformationsystem.login.officer.password.model.entity.OfficerPasswordOperationEntity; + +public interface OfficerPasswordOperationRepository { + + OfficerPasswordOperationEntity getPasswordOperation(Long officerId); + + void savePasswordOperation(OfficerPasswordOperationEntity passwordOperationEntity); + + void updatePasswordOperation(OfficerPasswordOperationEntity passwordOperationEntity); + + void deletePasswordOperation(String operationId); + + boolean isPasswordChangeEnabled(String operationId); + + boolean isOperationExist(Long officerId); + + Long getOfficerId(String operationId); +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/repository/impl/OfficerPasswordOperationRepositoryImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/repository/impl/OfficerPasswordOperationRepositoryImpl.java new file mode 100644 index 00000000..8b1d7d09 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/repository/impl/OfficerPasswordOperationRepositoryImpl.java @@ -0,0 +1,126 @@ +package com.graduationproject.studentinformationsystem.login.officer.password.repository.impl; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisDatabaseException; +import com.graduationproject.studentinformationsystem.login.officer.password.model.entity.OfficerPasswordOperationEntity; +import com.graduationproject.studentinformationsystem.login.officer.password.repository.OfficerPasswordOperationRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; +import org.sql2o.Connection; +import org.sql2o.Query; +import org.sql2o.Sql2o; + +import static com.graduationproject.studentinformationsystem.login.officer.password.model.mapping.OfficerPasswordOperationMapping.*; +import static com.graduationproject.studentinformationsystem.login.officer.password.repository.impl.scripts.OfficerPasswordOperationSqlScripts.*; + +@Repository +@RequiredArgsConstructor +public class OfficerPasswordOperationRepositoryImpl implements OfficerPasswordOperationRepository { + + private final Sql2o sql2o; + + @Override + public OfficerPasswordOperationEntity getPasswordOperation(final Long officerId) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(GET_OFFICER_PASSWORD_OPERATION)) { + + return query.addParameter(OFFICER_ID.getModelName(), officerId) + .setColumnMappings(COLUMN_MAPPINGS) + .executeAndFetchFirst(OfficerPasswordOperationEntity.class); + +// TODO: Specific Info Log Must be Added + } catch (Exception exception) { +// TODO: Specific Log Error Must be Added + throw new SisDatabaseException(exception); + } + } + + @Override + public void savePasswordOperation(final OfficerPasswordOperationEntity passwordOperationEntity) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(SAVE_OFFICER_PASSWORD_OPERATION)) { + + query.addParameter(OPERATION_ID.getModelName(), passwordOperationEntity.getOperationId()) + .addParameter(OFFICER_ID.getModelName(), passwordOperationEntity.getOfficerId()) + .addParameter(EXPIRE_DATE.getModelName(), passwordOperationEntity.getExpireDate()) + .addParameter(FE_URL.getModelName(), passwordOperationEntity.getFeUrl()) + .executeUpdate(); + +// TODO: Specific Info Log Must be Added + } catch (Exception exception) { +// TODO: Specific Error Log Must be Added + throw new SisDatabaseException(exception); + } + } + + @Override + public void updatePasswordOperation(final OfficerPasswordOperationEntity passwordOperationEntity) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(UPDATE_OFFICER_PASSWORD_OPERATION)) { + + query.addParameter(OPERATION_ID.getModelName(), passwordOperationEntity.getOperationId()) + .addParameter(OFFICER_ID.getModelName(), passwordOperationEntity.getOfficerId()) + .addParameter(EXPIRE_DATE.getModelName(), passwordOperationEntity.getExpireDate()) + .addParameter(FE_URL.getModelName(), passwordOperationEntity.getFeUrl()) + .executeUpdate(); + +// TODO: Specific Info Log Must be Added + } catch (Exception exception) { +// TODO: Specific Error Log Must be Added + throw new SisDatabaseException(exception); + } + } + + @Override + public void deletePasswordOperation(final String operationId) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(DELETE_OFFICER_PASSWORD_OPERATION)) { + + query.addParameter(OPERATION_ID.getModelName(), operationId) + .setColumnMappings(COLUMN_MAPPINGS) + .executeUpdate(); + +// TODO: Specific Info Log Must be Added + } catch (Exception exception) { +// TODO: Specific Error Log Must be Added + throw new SisDatabaseException(exception); + } + } + + @Override + public boolean isPasswordChangeEnabled(final String operationId) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(IS_PASSWORD_CHANGE_ENABLED)) { + + return query.addParameter(OPERATION_ID.getModelName(), operationId) + .executeScalar(Boolean.class); + +// TODO: Specific Info Log Must be Added + } catch (Exception exception) { +// TODO: Specific Error Log Must be Added + throw new SisDatabaseException(exception); + } + } + + @Override + public boolean isOperationExist(final Long officerId) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(IS_OPERATION_EXIST)) { + + return query.addParameter(OFFICER_ID.getModelName(), officerId) + .executeScalar(Boolean.class); + +// TODO: Specific Info Log Must be Added + } catch (Exception exception) { +// TODO: Specific Error Log Must be Added + throw new SisDatabaseException(exception); + } + } + + @Override + public Long getOfficerId(final String operationId) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(GET_OFFICER_ID)) { + + return query.addParameter(OPERATION_ID.getModelName(), operationId) + .executeScalar(Long.class); + +// TODO: Specific Info Log Must be Added + } catch (Exception exception) { +// TODO: Specific Error Log Must be Added + throw new SisDatabaseException(exception); + } + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/repository/impl/scripts/OfficerPasswordOperationSqlScripts.java b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/repository/impl/scripts/OfficerPasswordOperationSqlScripts.java new file mode 100644 index 00000000..cc22887b --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/repository/impl/scripts/OfficerPasswordOperationSqlScripts.java @@ -0,0 +1,70 @@ +package com.graduationproject.studentinformationsystem.login.officer.password.repository.impl.scripts; + +public class OfficerPasswordOperationSqlScripts { + + private static final StringBuilder sqlBuilder = new StringBuilder(); + + private OfficerPasswordOperationSqlScripts() { + } + + /** + * SELECT OPERATION_ID, OFFICER_ID, EXPIRE_DATE, FE_URL FROM AUTH_OFFICER_PASSWORD_OPERATION + * WHERE OFFICER_ID=:officerId; + */ + public static final String GET_OFFICER_PASSWORD_OPERATION = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("SELECT OPERATION_ID, OFFICER_ID, EXPIRE_DATE, FE_URL " + + "FROM AUTH_OFFICER_PASSWORD_OPERATION WHERE OFFICER_ID=:officerId").toString(); + + /** + * INSERT INTO AUTH_OFFICER_PASSWORD_OPERATION SET OPERATION_ID=:operationId, + * OFFICER_ID=:officerId, EXPIRE_DATE=:expireDate, FE_URL=:feUrl; + */ + public static final String SAVE_OFFICER_PASSWORD_OPERATION = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("INSERT INTO AUTH_OFFICER_PASSWORD_OPERATION SET OPERATION_ID=:operationId, " + + "OFFICER_ID=:officerId, EXPIRE_DATE=:expireDate, FE_URL=:feUrl").toString(); + + /** + * UPDATE AUTH_OFFICER_PASSWORD_OPERATION SET OPERATION_ID=:operationId, EXPIRE_DATE=:expireDate, FE_URL=:feUrl + * WHERE OFFICER_ID=:officerId; + */ + public static final String UPDATE_OFFICER_PASSWORD_OPERATION = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("UPDATE AUTH_OFFICER_PASSWORD_OPERATION SET OPERATION_ID=:operationId, " + + "EXPIRE_DATE=:expireDate, FE_URL=:feUrl WHERE OFFICER_ID=:officerId").toString(); + + /** + * DELETE FROM AUTH_OFFICER_PASSWORD_OPERATION WHERE OPERATION_ID=:operationId; + */ + public static final String DELETE_OFFICER_PASSWORD_OPERATION = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("DELETE FROM AUTH_OFFICER_PASSWORD_OPERATION WHERE OPERATION_ID=:operationId").toString(); + + /** + * SELECT CASE WHEN MAX(EXPIRE_DATE) IS NULL THEN 'false' ELSE 'true' END IS_EXIST + * FROM AUTH_OFFICER_PASSWORD_OPERATION WHERE OPERATION_ID=:operationId AND EXPIRE_DATE > NOW(); + */ + public static final String IS_PASSWORD_CHANGE_ENABLED = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("SELECT CASE WHEN MAX(EXPIRE_DATE) IS NULL THEN 'false' ELSE 'true' END IS_EXIST " + + "FROM AUTH_OFFICER_PASSWORD_OPERATION " + + "WHERE OPERATION_ID=:operationId AND EXPIRE_DATE > NOW()").toString(); + + /** + * SELECT CASE WHEN MAX(OFFICER_ID) IS NULL THEN 'false' ELSE 'true' END IS_EXIST + * FROM AUTH_OFFICER_PASSWORD_OPERATION WHERE OFFICER_ID=:officerId; + */ + public static final String IS_OPERATION_EXIST = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("SELECT CASE WHEN MAX(OFFICER_ID) IS NULL THEN 'false' ELSE 'true' END IS_EXIST " + + "FROM AUTH_OFFICER_PASSWORD_OPERATION WHERE OFFICER_ID=:officerId").toString(); + + /** + * SELECT OFFICER_ID FROM AUTH_OFFICER_PASSWORD_OPERATION WHERE OPERATION_ID=:operationId; + */ + public static final String GET_OFFICER_ID = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("SELECT OFFICER_ID FROM AUTH_OFFICER_PASSWORD_OPERATION " + + "WHERE OPERATION_ID=:operationId").toString(); +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/service/OfficerPasswordOperationOutService.java b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/service/OfficerPasswordOperationOutService.java new file mode 100644 index 00000000..562f9c2f --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/service/OfficerPasswordOperationOutService.java @@ -0,0 +1,10 @@ +package com.graduationproject.studentinformationsystem.login.officer.password.service; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; + +public interface OfficerPasswordOperationOutService { + + String getPasswordChangeUrl(Long officerId); + + void saveOrUpdatePasswordOperation(Long officerId, String feUrl) throws SisNotExistException; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/service/OfficerPasswordOperationService.java b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/service/OfficerPasswordOperationService.java new file mode 100644 index 00000000..8a91b417 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/service/OfficerPasswordOperationService.java @@ -0,0 +1,16 @@ +package com.graduationproject.studentinformationsystem.login.officer.password.service; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.login.officer.password.model.dto.request.OfficerPasswordChangeRequest; +import com.graduationproject.studentinformationsystem.login.officer.password.model.dto.request.OfficerPasswordForgotRequest; +import com.graduationproject.studentinformationsystem.login.officer.password.model.dto.response.OfficerPasswordChangeResponse; +import com.graduationproject.studentinformationsystem.login.officer.password.model.dto.response.OfficerPasswordForgotResponse; + +public interface OfficerPasswordOperationService { + + OfficerPasswordChangeResponse changePassword(OfficerPasswordChangeRequest passwordChangeRequest) throws SisNotExistException; + + OfficerPasswordForgotResponse forgotPassword(OfficerPasswordForgotRequest passwordForgotRequest) throws SisNotExistException; + + boolean isPasswordChangeEnabled(String operationId) throws SisNotExistException; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/service/impl/OfficerPasswordOperationOutServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/service/impl/OfficerPasswordOperationOutServiceImpl.java new file mode 100644 index 00000000..688d310b --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/service/impl/OfficerPasswordOperationOutServiceImpl.java @@ -0,0 +1,96 @@ +package com.graduationproject.studentinformationsystem.login.officer.password.service.impl; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.login.officer.password.model.dto.converter.OfficerPasswordOperationInfoConverter; +import com.graduationproject.studentinformationsystem.login.officer.password.model.dto.response.OfficerPasswordOperationResponse; +import com.graduationproject.studentinformationsystem.login.officer.password.model.entity.OfficerPasswordOperationEntity; +import com.graduationproject.studentinformationsystem.login.officer.password.repository.OfficerPasswordOperationRepository; +import com.graduationproject.studentinformationsystem.login.officer.password.service.OfficerPasswordOperationOutService; +import com.graduationproject.studentinformationsystem.university.officer.service.OfficerOutService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class OfficerPasswordOperationOutServiceImpl implements OfficerPasswordOperationOutService { + + private final OfficerOutService officerOutService; + + private final OfficerPasswordOperationRepository passwordOperationRepository; + private final OfficerPasswordOperationInfoConverter passwordOperationInfoConverter; + + @Override + public String getPasswordChangeUrl(final Long officerId) { + + final OfficerPasswordOperationResponse passwordOperationResponse = getPasswordOperation(officerId); + + return passwordOperationResponse.getPasswordChangeUrl(); + } + + @Override + public void saveOrUpdatePasswordOperation(final Long officerId, final String feUrl) throws SisNotExistException { + + boolean isOperationExist = isOperationExist(officerId); + + if (!isOperationExist) { + savePasswordOperation(officerId, feUrl); + } else { + updatePasswordOperation(officerId, feUrl); + } + } + + private OfficerPasswordOperationResponse getPasswordOperation(final Long officerId) { + + final OfficerPasswordOperationEntity passwordOperationEntity = passwordOperationRepository.getPasswordOperation(officerId); + + return passwordOperationInfoConverter.entityToResponse(passwordOperationEntity); + } + + private void savePasswordOperation(final Long officerId, final String feUrl) + throws SisNotExistException { + + checkBeforeSaving(officerId); + + final OfficerPasswordOperationEntity passwordOperationEntity = passwordOperationInfoConverter + .generateEntity(officerId, feUrl); + + passwordOperationRepository.savePasswordOperation(passwordOperationEntity); + } + + private void updatePasswordOperation(final Long officerId, final String feUrl) + throws SisNotExistException { + + checkBeforeUpdating(officerId); + + final OfficerPasswordOperationEntity passwordOperationEntity = passwordOperationInfoConverter + .generateEntity(officerId, feUrl); + + passwordOperationRepository.updatePasswordOperation(passwordOperationEntity); + } + + public boolean isOperationExist(final Long officerId) { + return passwordOperationRepository.isOperationExist(officerId); + } + + + /** + * Checks Before Processing + */ + + private void checkBeforeSaving(final Long officerId) throws SisNotExistException { + ifOfficerIsNotExistThrowNotExistException(officerId); + } + + private void checkBeforeUpdating(final Long officerId) throws SisNotExistException { + ifOfficerIsNotExistThrowNotExistException(officerId); + } + + + /** + * Throw Exceptions + */ + + private void ifOfficerIsNotExistThrowNotExistException(final Long officerId) throws SisNotExistException { + officerOutService.ifOfficerIsNotExistThrowNotExistException(officerId); + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/service/impl/OfficerPasswordOperationServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/service/impl/OfficerPasswordOperationServiceImpl.java new file mode 100644 index 00000000..6b2274fe --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/password/service/impl/OfficerPasswordOperationServiceImpl.java @@ -0,0 +1,92 @@ +package com.graduationproject.studentinformationsystem.login.officer.password.service.impl; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.login.common.service.PasswordOutService; +import com.graduationproject.studentinformationsystem.login.officer.common.service.OfficerLoginOutService; +import com.graduationproject.studentinformationsystem.login.officer.password.model.dto.request.OfficerPasswordChangeRequest; +import com.graduationproject.studentinformationsystem.login.officer.password.model.dto.request.OfficerPasswordForgotRequest; +import com.graduationproject.studentinformationsystem.login.officer.password.model.dto.response.OfficerPasswordChangeResponse; +import com.graduationproject.studentinformationsystem.login.officer.password.model.dto.response.OfficerPasswordForgotResponse; +import com.graduationproject.studentinformationsystem.login.officer.password.repository.OfficerPasswordOperationRepository; +import com.graduationproject.studentinformationsystem.login.officer.password.service.OfficerPasswordOperationOutService; +import com.graduationproject.studentinformationsystem.login.officer.password.service.OfficerPasswordOperationService; +import com.graduationproject.studentinformationsystem.university.mail.service.OfficerMailService; +import com.graduationproject.studentinformationsystem.university.officer.model.dto.response.OfficerInfoDetailResponse; +import com.graduationproject.studentinformationsystem.university.officer.service.OfficerOutService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class OfficerPasswordOperationServiceImpl implements OfficerPasswordOperationService { + + protected final OfficerLoginOutService officerLoginOutService; + protected final PasswordOutService passwordOutService; + + private final OfficerOutService officerOutService; + private final OfficerMailService officerMailService; + + private final OfficerPasswordOperationOutService passwordOperationOutService; + private final OfficerPasswordOperationRepository passwordOperationRepository; + + @Override + public OfficerPasswordChangeResponse changePassword(final OfficerPasswordChangeRequest passwordChangeRequest) { + + final boolean operationAndPasswordsCheck = operationAndPasswordsCheck(passwordChangeRequest); + + if (operationAndPasswordsCheck) { + final String operationId = passwordChangeRequest.getOperationId(); + final Long officerId = passwordOperationRepository.getOfficerId(operationId); + final String password = passwordOutService.getEncodedPassword(passwordChangeRequest.getNewPassword()); + + officerLoginOutService.saveOrUpdatePassword(officerId, password); + passwordOperationRepository.deletePasswordOperation(operationId); + + return OfficerPasswordChangeResponse.getSuccessResponse(); + } + return OfficerPasswordChangeResponse.getFailResponse(); + } + + @Override + public OfficerPasswordForgotResponse forgotPassword(OfficerPasswordForgotRequest passwordForgotRequest) + throws SisNotExistException { + + final Long officerId = passwordForgotRequest.getOfficerId(); + ifOfficerIsNotExistThrowNotExistException(officerId); + + final OfficerInfoDetailResponse infoDetailResponse = officerOutService.getOfficerInfoDetailResponse(officerId); + + passwordOperationOutService.saveOrUpdatePasswordOperation(officerId, passwordForgotRequest.getFeUrl()); + officerMailService.sendForgotPasswordEmail(infoDetailResponse); + + return OfficerPasswordForgotResponse.builder() + .isForgotPasswordSuccess(true) + .build(); + } + + @Override + public boolean isPasswordChangeEnabled(final String operationId) { + return passwordOperationRepository.isPasswordChangeEnabled(operationId); + } + + + private boolean operationAndPasswordsCheck(OfficerPasswordChangeRequest passwordChangeRequest) { + final String operationId = passwordChangeRequest.getOperationId(); + final String newPassword = passwordChangeRequest.getNewPassword(); + final String newPasswordRepeat = passwordChangeRequest.getNewPasswordRepeat(); + + final boolean isPasswordChangeEnabled = isPasswordChangeEnabled(operationId); + final boolean checkPasswords = newPassword.matches(newPasswordRepeat); + + return isPasswordChangeEnabled && checkPasswords; + } + + + /** + * Throw Exceptions + */ + + private void ifOfficerIsNotExistThrowNotExistException(final Long officerId) throws SisNotExistException { + officerOutService.ifOfficerIsNotExistThrowNotExistException(officerId); + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/service/OfficerLoginService.java b/src/main/java/com/graduationproject/studentinformationsystem/login/officer/service/OfficerLoginService.java deleted file mode 100644 index 9992c9e6..00000000 --- a/src/main/java/com/graduationproject/studentinformationsystem/login/officer/service/OfficerLoginService.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.graduationproject.studentinformationsystem.login.officer.service; - -import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; -import com.graduationproject.studentinformationsystem.login.common.model.response.ForgotPasswordResponse; -import com.graduationproject.studentinformationsystem.login.common.model.response.LoginResponse; -import com.graduationproject.studentinformationsystem.login.officer.model.dto.request.OfficerForgotPasswordRequest; -import com.graduationproject.studentinformationsystem.login.officer.model.dto.request.OfficerLoginRequest; - -public interface OfficerLoginService { - - LoginResponse login(OfficerLoginRequest loginRequest); - - ForgotPasswordResponse forgotPassword(OfficerForgotPasswordRequest forgotPasswordRequest) - throws SisNotExistException; -} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/student/controller/StudentLoginController.java b/src/main/java/com/graduationproject/studentinformationsystem/login/student/common/controller/StudentLoginController.java similarity index 66% rename from src/main/java/com/graduationproject/studentinformationsystem/login/student/controller/StudentLoginController.java rename to src/main/java/com/graduationproject/studentinformationsystem/login/student/common/controller/StudentLoginController.java index 8269bc71..5c1b0291 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/login/student/controller/StudentLoginController.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/student/common/controller/StudentLoginController.java @@ -1,13 +1,10 @@ -package com.graduationproject.studentinformationsystem.login.student.controller; +package com.graduationproject.studentinformationsystem.login.student.common.controller; import com.graduationproject.studentinformationsystem.common.util.controller.response.SisBaseApiResponse; -import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; import com.graduationproject.studentinformationsystem.login.common.controller.enpoint.LoginControllerEndpoint; -import com.graduationproject.studentinformationsystem.login.common.model.response.ForgotPasswordResponse; import com.graduationproject.studentinformationsystem.login.common.model.response.LoginResponse; -import com.graduationproject.studentinformationsystem.login.student.model.dto.request.StudentForgotPasswordRequest; -import com.graduationproject.studentinformationsystem.login.student.model.dto.request.StudentLoginRequest; -import com.graduationproject.studentinformationsystem.login.student.service.StudentLoginService; +import com.graduationproject.studentinformationsystem.login.student.common.model.dto.request.StudentLoginRequest; +import com.graduationproject.studentinformationsystem.login.student.common.service.StudentLoginService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; @@ -39,14 +36,4 @@ public ResponseEntity> studentLogin( final LoginResponse loginResponse = loginService.login(loginRequest); return successResponse(loginResponse); } - - @PostMapping(LoginControllerEndpoint.STUDENT_FORGOT_PASSWORD) - @ApiOperation(value = "Student Forgot Password") - public ResponseEntity> studentForgotPassword( - @RequestBody @Valid final StudentForgotPasswordRequest forgotPasswordRequest) - throws SisNotExistException { - - final ForgotPasswordResponse forgotPasswordResponse = loginService.forgotPassword(forgotPasswordRequest); - return successResponse(forgotPasswordResponse); - } } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/student/model/dto/request/StudentLoginRequest.java b/src/main/java/com/graduationproject/studentinformationsystem/login/student/common/model/dto/request/StudentLoginRequest.java similarity index 94% rename from src/main/java/com/graduationproject/studentinformationsystem/login/student/model/dto/request/StudentLoginRequest.java rename to src/main/java/com/graduationproject/studentinformationsystem/login/student/common/model/dto/request/StudentLoginRequest.java index b7d9786a..e837c1fb 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/login/student/model/dto/request/StudentLoginRequest.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/student/common/model/dto/request/StudentLoginRequest.java @@ -1,4 +1,4 @@ -package com.graduationproject.studentinformationsystem.login.student.model.dto.request; +package com.graduationproject.studentinformationsystem.login.student.common.model.dto.request; import com.graduationproject.studentinformationsystem.common.util.validation.id.StudentID; import lombok.Getter; diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/student/model/entity/StudentLoginInfoEntity.java b/src/main/java/com/graduationproject/studentinformationsystem/login/student/common/model/entity/StudentLoginInfoEntity.java similarity index 93% rename from src/main/java/com/graduationproject/studentinformationsystem/login/student/model/entity/StudentLoginInfoEntity.java rename to src/main/java/com/graduationproject/studentinformationsystem/login/student/common/model/entity/StudentLoginInfoEntity.java index 47566ce1..1e727eb8 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/login/student/model/entity/StudentLoginInfoEntity.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/student/common/model/entity/StudentLoginInfoEntity.java @@ -1,4 +1,4 @@ -package com.graduationproject.studentinformationsystem.login.student.model.entity; +package com.graduationproject.studentinformationsystem.login.student.common.model.entity; import com.graduationproject.studentinformationsystem.common.model.entity.SisBaseLoginInfoEntity; import lombok.Getter; diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/student/model/mapping/StudentLoginMapping.java b/src/main/java/com/graduationproject/studentinformationsystem/login/student/common/model/mapping/StudentLoginMapping.java similarity index 96% rename from src/main/java/com/graduationproject/studentinformationsystem/login/student/model/mapping/StudentLoginMapping.java rename to src/main/java/com/graduationproject/studentinformationsystem/login/student/common/model/mapping/StudentLoginMapping.java index 0a362342..e5d6376b 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/login/student/model/mapping/StudentLoginMapping.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/student/common/model/mapping/StudentLoginMapping.java @@ -1,4 +1,4 @@ -package com.graduationproject.studentinformationsystem.login.student.model.mapping; +package com.graduationproject.studentinformationsystem.login.student.common.model.mapping; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/student/repository/StudentLoginRepository.java b/src/main/java/com/graduationproject/studentinformationsystem/login/student/common/repository/StudentLoginRepository.java similarity index 60% rename from src/main/java/com/graduationproject/studentinformationsystem/login/student/repository/StudentLoginRepository.java rename to src/main/java/com/graduationproject/studentinformationsystem/login/student/common/repository/StudentLoginRepository.java index 4fb11162..e8367192 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/login/student/repository/StudentLoginRepository.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/student/common/repository/StudentLoginRepository.java @@ -1,6 +1,6 @@ -package com.graduationproject.studentinformationsystem.login.student.repository; +package com.graduationproject.studentinformationsystem.login.student.common.repository; -import com.graduationproject.studentinformationsystem.login.student.model.entity.StudentLoginInfoEntity; +import com.graduationproject.studentinformationsystem.login.student.common.model.entity.StudentLoginInfoEntity; public interface StudentLoginRepository { @@ -8,11 +8,13 @@ public interface StudentLoginRepository { String getPassword(Long studentId); - void saveFirstPassword(Long studentId, String password); + void savePassword(Long studentId, String encodedPassword); - void updatePassword(Long studentId, String password); + void updatePassword(Long studentId, String encodedPassword); void updateLoginInfo(StudentLoginInfoEntity loginInfoEntity); void updateFailCounter(Long studentId); + + boolean isPasswordExist(Long studentId); } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/student/repository/impl/StudentLoginRepositoryImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/login/student/common/repository/impl/StudentLoginRepositoryImpl.java similarity index 74% rename from src/main/java/com/graduationproject/studentinformationsystem/login/student/repository/impl/StudentLoginRepositoryImpl.java rename to src/main/java/com/graduationproject/studentinformationsystem/login/student/common/repository/impl/StudentLoginRepositoryImpl.java index 5decd6e9..a0725544 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/login/student/repository/impl/StudentLoginRepositoryImpl.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/student/common/repository/impl/StudentLoginRepositoryImpl.java @@ -1,24 +1,21 @@ -package com.graduationproject.studentinformationsystem.login.student.repository.impl; +package com.graduationproject.studentinformationsystem.login.student.common.repository.impl; import com.graduationproject.studentinformationsystem.common.util.exception.SisDatabaseException; -import com.graduationproject.studentinformationsystem.login.common.service.PasswordService; -import com.graduationproject.studentinformationsystem.login.student.model.entity.StudentLoginInfoEntity; -import com.graduationproject.studentinformationsystem.login.student.repository.StudentLoginRepository; +import com.graduationproject.studentinformationsystem.login.student.common.model.entity.StudentLoginInfoEntity; +import com.graduationproject.studentinformationsystem.login.student.common.repository.StudentLoginRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; import org.sql2o.Connection; import org.sql2o.Query; import org.sql2o.Sql2o; -import static com.graduationproject.studentinformationsystem.login.student.model.mapping.StudentLoginMapping.*; -import static com.graduationproject.studentinformationsystem.login.student.repository.impl.scripts.StudentLoginSqlScripts.*; +import static com.graduationproject.studentinformationsystem.login.student.common.model.mapping.StudentLoginMapping.*; +import static com.graduationproject.studentinformationsystem.login.student.common.repository.impl.scripts.StudentLoginSqlScripts.*; @Repository @RequiredArgsConstructor public class StudentLoginRepositoryImpl implements StudentLoginRepository { - private final PasswordService passwordService; - private final Sql2o sql2o; @Override @@ -52,11 +49,11 @@ public String getPassword(final Long studentId) { } @Override - public void saveFirstPassword(final Long studentId, final String password) { - try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(SAVE_STUDENT_FIRST_PASSWORD)) { + public void savePassword(final Long studentId, final String encodedPassword) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(SAVE_STUDENT_PASSWORD)) { query.addParameter(STUDENT_ID.getModelName(), studentId) - .addParameter(PASSWORD.getModelName(), passwordService.encodePassword(password)) + .addParameter(PASSWORD.getModelName(), encodedPassword) .addParameter(FAIL_COUNTER.getModelName(), 0) .executeUpdate(); @@ -68,11 +65,12 @@ public void saveFirstPassword(final Long studentId, final String password) { } @Override - public void updatePassword(final Long studentId, final String password) { + public void updatePassword(final Long studentId, final String encodedPassword) { try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(UPDATE_STUDENT_PASSWORD)) { query.addParameter(STUDENT_ID.getModelName(), studentId) - .addParameter(PASSWORD.getModelName(), passwordService.encodePassword(password)) + .addParameter(PASSWORD.getModelName(), encodedPassword) + .addParameter(FAIL_COUNTER.getModelName(), 0) .executeUpdate(); // TODO: Specific Info Log Must be Added @@ -113,21 +111,17 @@ public void updateFailCounter(final Long studentId) { } } -// TODO: Change or Update Password -// @Override -// public void updatePassword(final StudentLoginEntity loginInfoEntity) { -// try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(UPDATE_STUDENT_PASSWORD)) { -// -// query.addParameter(STUDENT_ID.getModelName(), loginInfoEntity.getStudentId()) -// .addParameter(PASSWORD.getModelName(), loginInfoEntity.getPassword()) -// .addParameter(FAIL_COUNTER.getModelName(), loginInfoEntity.getFailCounter()) -// .addParameter(LAST_LOGIN_DATE.getModelName(), loginInfoEntity.getLastLoginDate()) -// .executeUpdate(); -// + @Override + public boolean isPasswordExist(final Long studentId) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(IS_STUDENT_PASSWORD_EXIST)) { + + return query.addParameter(STUDENT_ID.getModelName(), studentId) + .executeScalar(Boolean.class); + // TODO: Specific Info Log Must be Added -// } catch (Exception exception) { + } catch (Exception exception) { // TODO: Specific Error Log Must be Added -// throw new SisDatabaseException(exception); -// } -// } + throw new SisDatabaseException(exception); + } + } } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/student/repository/impl/scripts/StudentLoginSqlScripts.java b/src/main/java/com/graduationproject/studentinformationsystem/login/student/common/repository/impl/scripts/StudentLoginSqlScripts.java similarity index 73% rename from src/main/java/com/graduationproject/studentinformationsystem/login/student/repository/impl/scripts/StudentLoginSqlScripts.java rename to src/main/java/com/graduationproject/studentinformationsystem/login/student/common/repository/impl/scripts/StudentLoginSqlScripts.java index 38f46716..ffb66edf 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/login/student/repository/impl/scripts/StudentLoginSqlScripts.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/student/common/repository/impl/scripts/StudentLoginSqlScripts.java @@ -1,4 +1,4 @@ -package com.graduationproject.studentinformationsystem.login.student.repository.impl.scripts; +package com.graduationproject.studentinformationsystem.login.student.common.repository.impl.scripts; public class StudentLoginSqlScripts { @@ -24,17 +24,18 @@ private StudentLoginSqlScripts() { /** * INSERT INTO AUTH_STUDENT_LOGIN SET STUDENT_ID=:studentId, PASSWORD=:password, FAIL_COUNTER=:failCounter; */ - public static final String SAVE_STUDENT_FIRST_PASSWORD = + public static final String SAVE_STUDENT_PASSWORD = sqlBuilder.delete(0, sqlBuilder.length()) .append("INSERT INTO AUTH_STUDENT_LOGIN SET STUDENT_ID=:studentId, PASSWORD=:password," + " FAIL_COUNTER=:failCounter").toString(); /** - * UPDATE AUTH_STUDENT_LOGIN SET PASSWORD=:password WHERE STUDENT_ID=:studentId; + * UPDATE AUTH_STUDENT_LOGIN SET PASSWORD=:password, FAIL_COUNTER=:failCounter WHERE STUDENT_ID=:studentId; */ public static final String UPDATE_STUDENT_PASSWORD = sqlBuilder.delete(0, sqlBuilder.length()) - .append("UPDATE AUTH_STUDENT_LOGIN SET PASSWORD=:password WHERE STUDENT_ID=:studentId").toString(); + .append("UPDATE AUTH_STUDENT_LOGIN SET PASSWORD=:password, FAIL_COUNTER=:failCounter " + + "WHERE STUDENT_ID=:studentId").toString(); /** * UPDATE AUTH_STUDENT_LOGIN SET FAIL_COUNTER=:failCounter, LAST_LOGIN_DATE=:lastLoginDate @@ -52,4 +53,13 @@ private StudentLoginSqlScripts() { sqlBuilder.delete(0, sqlBuilder.length()) .append("UPDATE AUTH_STUDENT_LOGIN SET FAIL_COUNTER=:failCounter " + "WHERE STUDENT_ID=:studentId").toString(); + + /** + * SELECT CASE WHEN MAX(STUDENT_ID) IS NULL THEN 'false' ELSE 'true' END IS_EXIST + * FROM AUTH_STUDENT_LOGIN WHERE STUDENT_ID=:studentId; + */ + public static final String IS_STUDENT_PASSWORD_EXIST = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("SELECT CASE WHEN MAX(STUDENT_ID) IS NULL THEN 'false' ELSE 'true' END IS_EXIST " + + "FROM AUTH_STUDENT_LOGIN WHERE STUDENT_ID=:studentId").toString(); } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/student/common/service/StudentLoginOutService.java b/src/main/java/com/graduationproject/studentinformationsystem/login/student/common/service/StudentLoginOutService.java new file mode 100644 index 00000000..f4b9cc85 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/student/common/service/StudentLoginOutService.java @@ -0,0 +1,6 @@ +package com.graduationproject.studentinformationsystem.login.student.common.service; + +public interface StudentLoginOutService { + + void saveOrUpdatePassword(Long studentId, String encodedPassword); +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/student/common/service/StudentLoginService.java b/src/main/java/com/graduationproject/studentinformationsystem/login/student/common/service/StudentLoginService.java new file mode 100644 index 00000000..cbc2201b --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/student/common/service/StudentLoginService.java @@ -0,0 +1,9 @@ +package com.graduationproject.studentinformationsystem.login.student.common.service; + +import com.graduationproject.studentinformationsystem.login.common.model.response.LoginResponse; +import com.graduationproject.studentinformationsystem.login.student.common.model.dto.request.StudentLoginRequest; + +public interface StudentLoginService { + + LoginResponse login(StudentLoginRequest loginRequest); +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/student/common/service/impl/StudentLoginOutServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/login/student/common/service/impl/StudentLoginOutServiceImpl.java new file mode 100644 index 00000000..6d64c875 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/student/common/service/impl/StudentLoginOutServiceImpl.java @@ -0,0 +1,25 @@ +package com.graduationproject.studentinformationsystem.login.student.common.service.impl; + +import com.graduationproject.studentinformationsystem.login.student.common.repository.StudentLoginRepository; +import com.graduationproject.studentinformationsystem.login.student.common.service.StudentLoginOutService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class StudentLoginOutServiceImpl implements StudentLoginOutService { + + private final StudentLoginRepository studentLoginRepository; + + @Override + public void saveOrUpdatePassword(final Long studentId, final String encodedPassword) { + + boolean isPasswordExist = studentLoginRepository.isPasswordExist(studentId); + + if (!isPasswordExist) { + studentLoginRepository.savePassword(studentId, encodedPassword); + } else { + studentLoginRepository.updatePassword(studentId, encodedPassword); + } + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/student/service/impl/StudentLoginServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/login/student/common/service/impl/StudentLoginServiceImpl.java similarity index 70% rename from src/main/java/com/graduationproject/studentinformationsystem/login/student/service/impl/StudentLoginServiceImpl.java rename to src/main/java/com/graduationproject/studentinformationsystem/login/student/common/service/impl/StudentLoginServiceImpl.java index a4eddc8b..5a5ed38b 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/login/student/service/impl/StudentLoginServiceImpl.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/student/common/service/impl/StudentLoginServiceImpl.java @@ -1,17 +1,12 @@ -package com.graduationproject.studentinformationsystem.login.student.service.impl; +package com.graduationproject.studentinformationsystem.login.student.common.service.impl; -import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; -import com.graduationproject.studentinformationsystem.login.common.model.response.ForgotPasswordResponse; import com.graduationproject.studentinformationsystem.login.common.model.response.LoginResponse; import com.graduationproject.studentinformationsystem.login.common.service.PasswordService; -import com.graduationproject.studentinformationsystem.login.student.model.dto.request.StudentForgotPasswordRequest; -import com.graduationproject.studentinformationsystem.login.student.model.dto.request.StudentLoginRequest; -import com.graduationproject.studentinformationsystem.login.student.model.entity.StudentLoginInfoEntity; -import com.graduationproject.studentinformationsystem.login.student.repository.StudentLoginRepository; -import com.graduationproject.studentinformationsystem.login.student.service.StudentLoginService; -import com.graduationproject.studentinformationsystem.university.mail.service.StudentMailService; +import com.graduationproject.studentinformationsystem.login.student.common.model.dto.request.StudentLoginRequest; +import com.graduationproject.studentinformationsystem.login.student.common.model.entity.StudentLoginInfoEntity; +import com.graduationproject.studentinformationsystem.login.student.common.repository.StudentLoginRepository; +import com.graduationproject.studentinformationsystem.login.student.common.service.StudentLoginService; import com.graduationproject.studentinformationsystem.university.student.service.StudentAcademicInfoService; -import com.graduationproject.studentinformationsystem.university.student.service.StudentService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -21,9 +16,7 @@ @RequiredArgsConstructor public class StudentLoginServiceImpl implements StudentLoginService { - private final StudentService studentService; private final StudentAcademicInfoService academicInfoService; - private final StudentMailService mailService; private final StudentLoginRepository loginRepository; private final PasswordService passwordService; @@ -47,12 +40,6 @@ public LoginResponse login(StudentLoginRequest loginRequest) { return getFailLoginResponse(); } - @Override - public ForgotPasswordResponse forgotPassword(StudentForgotPasswordRequest forgotPasswordRequest) throws SisNotExistException { - mailService.sendForgotPasswordEmail(studentService.getStudentDetailById(forgotPasswordRequest.getStudentId())); - return ForgotPasswordResponse.builder().isForgotPasswordSuccess(true).build(); - } - private boolean isStudentActive(Long studentId) { return academicInfoService.isStudentActive(studentId); diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/controller/StudentPasswordOperationController.java b/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/controller/StudentPasswordOperationController.java new file mode 100644 index 00000000..93b1112e --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/controller/StudentPasswordOperationController.java @@ -0,0 +1,65 @@ +package com.graduationproject.studentinformationsystem.login.student.password.controller; + +import com.graduationproject.studentinformationsystem.common.util.controller.response.SisApiResponse; +import com.graduationproject.studentinformationsystem.common.util.controller.response.SisBaseApiResponse; +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.login.student.password.controller.endpoint.StudentPasswordOperationControllerEndpoint; +import com.graduationproject.studentinformationsystem.login.student.password.model.dto.request.StudentPasswordChangeRequest; +import com.graduationproject.studentinformationsystem.login.student.password.model.dto.request.StudentPasswordForgotRequest; +import com.graduationproject.studentinformationsystem.login.student.password.model.dto.response.StudentPasswordChangeResponse; +import com.graduationproject.studentinformationsystem.login.student.password.model.dto.response.StudentPasswordForgotResponse; +import com.graduationproject.studentinformationsystem.login.student.password.service.StudentPasswordOperationService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; + +import static com.graduationproject.studentinformationsystem.common.config.SisSwaggerConfiguration.STUDENT_PASSWORD_OPERATION_API_TAG; +import static com.graduationproject.studentinformationsystem.common.util.controller.endpoint.SisControllerEndpoint.Path.STUDENT_PASSWORD_OPERATION; +import static com.graduationproject.studentinformationsystem.common.util.controller.response.SisResponseUtil.successResponse; +import static com.graduationproject.studentinformationsystem.common.util.controller.response.SisResponseUtil.unauthorizedResponse; + +@RestController +@RequestMapping(STUDENT_PASSWORD_OPERATION) +@Api(tags = STUDENT_PASSWORD_OPERATION_API_TAG) +@RequiredArgsConstructor +public class StudentPasswordOperationController { + + private final StudentPasswordOperationService passwordOperationService; + + @GetMapping + @ApiOperation(value = "Is Student Password Change Operation Enabled") + public ResponseEntity isPasswordChangeOperationEnabled( + @RequestParam final String operationId) throws SisNotExistException { + + final boolean isPasswordChangeEnabled = passwordOperationService.isPasswordChangeEnabled(operationId); + + if (isPasswordChangeEnabled) { + return successResponse(); + } else { + return unauthorizedResponse(); + } + } + + @PostMapping(StudentPasswordOperationControllerEndpoint.CHANGE_PASSWORD) + @ApiOperation(value = "Change Student Password") + public ResponseEntity> changePassword( + @RequestBody final StudentPasswordChangeRequest passwordChangeRequest) throws SisNotExistException { + + final StudentPasswordChangeResponse passwordChangeResponse = passwordOperationService.changePassword(passwordChangeRequest); + return successResponse(passwordChangeResponse); + } + + @PostMapping(StudentPasswordOperationControllerEndpoint.FORGOT_PASSWORD) + @ApiOperation(value = "Student Forgot Password") + public ResponseEntity> forgotPassword( + @RequestBody @Valid final StudentPasswordForgotRequest passwordForgotRequest) + throws SisNotExistException { + + final StudentPasswordForgotResponse passwordOperationResponse = passwordOperationService.forgotPassword(passwordForgotRequest); + return successResponse(passwordOperationResponse); + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/controller/endpoint/StudentPasswordOperationControllerEndpoint.java b/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/controller/endpoint/StudentPasswordOperationControllerEndpoint.java new file mode 100644 index 00000000..7e6700d6 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/controller/endpoint/StudentPasswordOperationControllerEndpoint.java @@ -0,0 +1,10 @@ +package com.graduationproject.studentinformationsystem.login.student.password.controller.endpoint; + +public class StudentPasswordOperationControllerEndpoint { + + private StudentPasswordOperationControllerEndpoint() { + } + + public static final String CHANGE_PASSWORD = "/change-password"; + public static final String FORGOT_PASSWORD = "/forgot-password"; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/model/dto/converter/StudentPasswordOperationInfoConverter.java b/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/model/dto/converter/StudentPasswordOperationInfoConverter.java new file mode 100644 index 00000000..a86ba899 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/model/dto/converter/StudentPasswordOperationInfoConverter.java @@ -0,0 +1,34 @@ +package com.graduationproject.studentinformationsystem.login.student.password.model.dto.converter; + +import com.graduationproject.studentinformationsystem.common.util.SisUtil; +import com.graduationproject.studentinformationsystem.login.student.password.model.dto.response.StudentPasswordOperationResponse; +import com.graduationproject.studentinformationsystem.login.student.password.model.entity.StudentPasswordOperationEntity; +import org.springframework.stereotype.Component; + +import java.time.LocalDateTime; + +@Component +public class StudentPasswordOperationInfoConverter { + + public StudentPasswordOperationEntity generateEntity(final Long studentId, final String feUrl) { + + return StudentPasswordOperationEntity.builder() + .operationId(SisUtil.generateRandomUUID()) + .studentId(studentId) + .expireDate(LocalDateTime.now().plusDays(1)) + .feUrl(feUrl) + .build(); + } + + public StudentPasswordOperationResponse entityToResponse(final StudentPasswordOperationEntity passwordOperationEntity) { + + final String operationId = passwordOperationEntity.getOperationId(); + + return StudentPasswordOperationResponse.builder() + .operationId(operationId) + .studentId(passwordOperationEntity.getStudentId()) + .expireDate(passwordOperationEntity.getExpireDate()) + .passwordChangeUrl(passwordOperationEntity.getFeUrl() + "/login/student/change-password/" + operationId) + .build(); + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/model/dto/request/StudentPasswordChangeRequest.java b/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/model/dto/request/StudentPasswordChangeRequest.java new file mode 100644 index 00000000..95293d77 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/model/dto/request/StudentPasswordChangeRequest.java @@ -0,0 +1,23 @@ +package com.graduationproject.studentinformationsystem.login.student.password.model.dto.request; + +import lombok.Getter; + +import javax.validation.constraints.NotNull; +import java.io.Serial; +import java.io.Serializable; + +@Getter +public class StudentPasswordChangeRequest implements Serializable { + + @Serial + private static final long serialVersionUID = 6980895876807894275L; + + @NotNull + private String operationId; + + @NotNull + private String newPassword; + + @NotNull + private String newPasswordRepeat; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/student/model/dto/request/StudentForgotPasswordRequest.java b/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/model/dto/request/StudentPasswordForgotRequest.java similarity index 75% rename from src/main/java/com/graduationproject/studentinformationsystem/login/student/model/dto/request/StudentForgotPasswordRequest.java rename to src/main/java/com/graduationproject/studentinformationsystem/login/student/password/model/dto/request/StudentPasswordForgotRequest.java index 62331e91..f448772c 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/login/student/model/dto/request/StudentForgotPasswordRequest.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/model/dto/request/StudentPasswordForgotRequest.java @@ -1,4 +1,4 @@ -package com.graduationproject.studentinformationsystem.login.student.model.dto.request; +package com.graduationproject.studentinformationsystem.login.student.password.model.dto.request; import com.graduationproject.studentinformationsystem.common.util.validation.id.StudentID; import lombok.Getter; @@ -8,7 +8,7 @@ import java.io.Serializable; @Getter -public class StudentForgotPasswordRequest implements Serializable { +public class StudentPasswordForgotRequest implements Serializable { @Serial private static final long serialVersionUID = -6073520178120747403L; @@ -16,4 +16,7 @@ public class StudentForgotPasswordRequest implements Serializable { @NotNull @StudentID private Long studentId; + + @NotNull + private String feUrl; } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/model/dto/response/StudentPasswordChangeResponse.java b/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/model/dto/response/StudentPasswordChangeResponse.java new file mode 100644 index 00000000..70235e78 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/model/dto/response/StudentPasswordChangeResponse.java @@ -0,0 +1,21 @@ +package com.graduationproject.studentinformationsystem.login.student.password.model.dto.response; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class StudentPasswordChangeResponse { + + private boolean isPasswordChanged; + + public static StudentPasswordChangeResponse getSuccessResponse() { + return StudentPasswordChangeResponse.builder() + .isPasswordChanged(true).build(); + } + + public static StudentPasswordChangeResponse getFailResponse() { + return StudentPasswordChangeResponse.builder() + .isPasswordChanged(false).build(); + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/model/dto/response/StudentPasswordForgotResponse.java b/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/model/dto/response/StudentPasswordForgotResponse.java new file mode 100644 index 00000000..36032c03 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/model/dto/response/StudentPasswordForgotResponse.java @@ -0,0 +1,11 @@ +package com.graduationproject.studentinformationsystem.login.student.password.model.dto.response; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class StudentPasswordForgotResponse { + + private boolean isForgotPasswordSuccess; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/model/dto/response/StudentPasswordOperationResponse.java b/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/model/dto/response/StudentPasswordOperationResponse.java new file mode 100644 index 00000000..d16587f4 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/model/dto/response/StudentPasswordOperationResponse.java @@ -0,0 +1,16 @@ +package com.graduationproject.studentinformationsystem.login.student.password.model.dto.response; + +import lombok.Builder; +import lombok.Getter; + +import java.time.LocalDateTime; + +@Getter +@Builder +public class StudentPasswordOperationResponse { + + private String operationId; + private Long studentId; + private LocalDateTime expireDate; + private String passwordChangeUrl; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/model/entity/StudentPasswordChangeEntity.java b/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/model/entity/StudentPasswordChangeEntity.java new file mode 100644 index 00000000..90c7c3e1 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/model/entity/StudentPasswordChangeEntity.java @@ -0,0 +1,12 @@ +package com.graduationproject.studentinformationsystem.login.student.password.model.entity; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class StudentPasswordChangeEntity { + + protected String newPassword; + protected String newPasswordRepeat; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/model/entity/StudentPasswordOperationEntity.java b/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/model/entity/StudentPasswordOperationEntity.java new file mode 100644 index 00000000..d45b6707 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/model/entity/StudentPasswordOperationEntity.java @@ -0,0 +1,16 @@ +package com.graduationproject.studentinformationsystem.login.student.password.model.entity; + +import lombok.Builder; +import lombok.Getter; + +import java.time.LocalDateTime; + +@Getter +@Builder +public class StudentPasswordOperationEntity { + + private String operationId; + private Long studentId; + private LocalDateTime expireDate; + private String feUrl; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/model/mapping/StudentPasswordOperationMapping.java b/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/model/mapping/StudentPasswordOperationMapping.java new file mode 100644 index 00000000..6a34ba3c --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/model/mapping/StudentPasswordOperationMapping.java @@ -0,0 +1,24 @@ +package com.graduationproject.studentinformationsystem.login.student.password.model.mapping; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +@Getter +@RequiredArgsConstructor +public enum StudentPasswordOperationMapping { + + OPERATION_ID("OPERATION_ID", "operationId"), + STUDENT_ID("STUDENT_ID", "studentId"), + EXPIRE_DATE("EXPIRE_DATE", "expireDate"), + FE_URL("FE_URL", "feUrl"); + + private final String columnName; + private final String modelName; + + public static final Map COLUMN_MAPPINGS = Stream.of(values()) + .collect(Collectors.toMap(StudentPasswordOperationMapping::getColumnName, StudentPasswordOperationMapping::getModelName)); +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/repository/StudentPasswordOperationRepository.java b/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/repository/StudentPasswordOperationRepository.java new file mode 100644 index 00000000..f4b16fa2 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/repository/StudentPasswordOperationRepository.java @@ -0,0 +1,20 @@ +package com.graduationproject.studentinformationsystem.login.student.password.repository; + +import com.graduationproject.studentinformationsystem.login.student.password.model.entity.StudentPasswordOperationEntity; + +public interface StudentPasswordOperationRepository { + + StudentPasswordOperationEntity getPasswordOperation(Long studentId); + + void savePasswordOperation(StudentPasswordOperationEntity passwordOperationEntity); + + void updatePasswordOperation(StudentPasswordOperationEntity passwordOperationEntity); + + void deletePasswordOperation(String operationId); + + boolean isPasswordChangeEnabled(String operationId); + + boolean isOperationExist(Long studentId); + + Long getStudentId(String operationId); +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/repository/impl/StudentPasswordOperationRepositoryImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/repository/impl/StudentPasswordOperationRepositoryImpl.java new file mode 100644 index 00000000..3d005d22 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/repository/impl/StudentPasswordOperationRepositoryImpl.java @@ -0,0 +1,126 @@ +package com.graduationproject.studentinformationsystem.login.student.password.repository.impl; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisDatabaseException; +import com.graduationproject.studentinformationsystem.login.student.password.model.entity.StudentPasswordOperationEntity; +import com.graduationproject.studentinformationsystem.login.student.password.repository.StudentPasswordOperationRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; +import org.sql2o.Connection; +import org.sql2o.Query; +import org.sql2o.Sql2o; + +import static com.graduationproject.studentinformationsystem.login.student.password.model.mapping.StudentPasswordOperationMapping.*; +import static com.graduationproject.studentinformationsystem.login.student.password.repository.impl.scripts.StudentPasswordOperationSqlScripts.*; + +@Repository +@RequiredArgsConstructor +public class StudentPasswordOperationRepositoryImpl implements StudentPasswordOperationRepository { + + private final Sql2o sql2o; + + @Override + public StudentPasswordOperationEntity getPasswordOperation(final Long studentId) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(GET_STUDENT_PASSWORD_OPERATION)) { + + return query.addParameter(STUDENT_ID.getModelName(), studentId) + .setColumnMappings(COLUMN_MAPPINGS) + .executeAndFetchFirst(StudentPasswordOperationEntity.class); + +// TODO: Specific Info Log Must be Added + } catch (Exception exception) { +// TODO: Specific Log Error Must be Added + throw new SisDatabaseException(exception); + } + } + + @Override + public void savePasswordOperation(final StudentPasswordOperationEntity passwordOperationEntity) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(SAVE_STUDENT_PASSWORD_OPERATION)) { + + query.addParameter(OPERATION_ID.getModelName(), passwordOperationEntity.getOperationId()) + .addParameter(STUDENT_ID.getModelName(), passwordOperationEntity.getStudentId()) + .addParameter(EXPIRE_DATE.getModelName(), passwordOperationEntity.getExpireDate()) + .addParameter(FE_URL.getModelName(), passwordOperationEntity.getFeUrl()) + .executeUpdate(); + +// TODO: Specific Info Log Must be Added + } catch (Exception exception) { +// TODO: Specific Error Log Must be Added + throw new SisDatabaseException(exception); + } + } + + @Override + public void updatePasswordOperation(final StudentPasswordOperationEntity passwordOperationEntity) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(UPDATE_STUDENT_PASSWORD_OPERATION)) { + + query.addParameter(OPERATION_ID.getModelName(), passwordOperationEntity.getOperationId()) + .addParameter(STUDENT_ID.getModelName(), passwordOperationEntity.getStudentId()) + .addParameter(EXPIRE_DATE.getModelName(), passwordOperationEntity.getExpireDate()) + .addParameter(FE_URL.getModelName(), passwordOperationEntity.getFeUrl()) + .executeUpdate(); + +// TODO: Specific Info Log Must be Added + } catch (Exception exception) { +// TODO: Specific Error Log Must be Added + throw new SisDatabaseException(exception); + } + } + + @Override + public void deletePasswordOperation(final String operationId) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(DELETE_STUDENT_PASSWORD_OPERATION)) { + + query.addParameter(OPERATION_ID.getModelName(), operationId) + .setColumnMappings(COLUMN_MAPPINGS) + .executeUpdate(); + +// TODO: Specific Info Log Must be Added + } catch (Exception exception) { +// TODO: Specific Error Log Must be Added + throw new SisDatabaseException(exception); + } + } + + @Override + public boolean isPasswordChangeEnabled(final String operationId) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(IS_PASSWORD_CHANGE_ENABLED)) { + + return query.addParameter(OPERATION_ID.getModelName(), operationId) + .executeScalar(Boolean.class); + +// TODO: Specific Info Log Must be Added + } catch (Exception exception) { +// TODO: Specific Error Log Must be Added + throw new SisDatabaseException(exception); + } + } + + @Override + public boolean isOperationExist(final Long studentId) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(IS_OPERATION_EXIST)) { + + return query.addParameter(STUDENT_ID.getModelName(), studentId) + .executeScalar(Boolean.class); + +// TODO: Specific Info Log Must be Added + } catch (Exception exception) { +// TODO: Specific Error Log Must be Added + throw new SisDatabaseException(exception); + } + } + + @Override + public Long getStudentId(final String operationId) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(GET_STUDENT_ID)) { + + return query.addParameter(OPERATION_ID.getModelName(), operationId) + .executeScalar(Long.class); + +// TODO: Specific Info Log Must be Added + } catch (Exception exception) { +// TODO: Specific Error Log Must be Added + throw new SisDatabaseException(exception); + } + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/repository/impl/scripts/StudentPasswordOperationSqlScripts.java b/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/repository/impl/scripts/StudentPasswordOperationSqlScripts.java new file mode 100644 index 00000000..56d1321b --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/repository/impl/scripts/StudentPasswordOperationSqlScripts.java @@ -0,0 +1,70 @@ +package com.graduationproject.studentinformationsystem.login.student.password.repository.impl.scripts; + +public class StudentPasswordOperationSqlScripts { + + private static final StringBuilder sqlBuilder = new StringBuilder(); + + private StudentPasswordOperationSqlScripts() { + } + + /** + * SELECT OPERATION_ID, STUDENT_ID, EXPIRE_DATE, FE_URL FROM AUTH_STUDENT_PASSWORD_OPERATION + * WHERE STUDENT_ID=:studentId; + */ + public static final String GET_STUDENT_PASSWORD_OPERATION = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("SELECT OPERATION_ID, STUDENT_ID, EXPIRE_DATE, FE_URL " + + "FROM AUTH_STUDENT_PASSWORD_OPERATION WHERE STUDENT_ID=:studentId").toString(); + + /** + * INSERT INTO AUTH_STUDENT_PASSWORD_OPERATION SET OPERATION_ID=:operationId, + * STUDENT_ID=:studentId, EXPIRE_DATE=:expireDate, FE_URL=:feUrl; + */ + public static final String SAVE_STUDENT_PASSWORD_OPERATION = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("INSERT INTO AUTH_STUDENT_PASSWORD_OPERATION SET OPERATION_ID=:operationId, " + + "STUDENT_ID=:studentId, EXPIRE_DATE=:expireDate, FE_URL=:feUrl").toString(); + + /** + * UPDATE AUTH_STUDENT_PASSWORD_OPERATION SET OPERATION_ID=:operationId, EXPIRE_DATE=:expireDate, FE_URL=:feUrl + * WHERE STUDENT_ID=:studentId; + */ + public static final String UPDATE_STUDENT_PASSWORD_OPERATION = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("UPDATE AUTH_STUDENT_PASSWORD_OPERATION SET OPERATION_ID=:operationId, " + + "EXPIRE_DATE=:expireDate, FE_URL=:feUrl WHERE STUDENT_ID=:studentId").toString(); + + /** + * DELETE FROM AUTH_STUDENT_PASSWORD_OPERATION WHERE OPERATION_ID=:operationId; + */ + public static final String DELETE_STUDENT_PASSWORD_OPERATION = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("DELETE FROM AUTH_STUDENT_PASSWORD_OPERATION WHERE OPERATION_ID=:operationId").toString(); + + /** + * SELECT CASE WHEN MAX(EXPIRE_DATE) IS NULL THEN 'false' ELSE 'true' END IS_EXIST + * FROM AUTH_STUDENT_PASSWORD_OPERATION WHERE OPERATION_ID=:operationId AND EXPIRE_DATE > NOW(); + */ + public static final String IS_PASSWORD_CHANGE_ENABLED = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("SELECT CASE WHEN MAX(EXPIRE_DATE) IS NULL THEN 'false' ELSE 'true' END IS_EXIST " + + "FROM AUTH_STUDENT_PASSWORD_OPERATION " + + "WHERE OPERATION_ID=:operationId AND EXPIRE_DATE > NOW()").toString(); + + /** + * SELECT CASE WHEN MAX(STUDENT_ID) IS NULL THEN 'false' ELSE 'true' END IS_EXIST + * FROM AUTH_STUDENT_PASSWORD_OPERATION WHERE STUDENT_ID=:studentId; + */ + public static final String IS_OPERATION_EXIST = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("SELECT CASE WHEN MAX(STUDENT_ID) IS NULL THEN 'false' ELSE 'true' END IS_EXIST " + + "FROM AUTH_STUDENT_PASSWORD_OPERATION WHERE STUDENT_ID=:studentId").toString(); + + /** + * SELECT STUDENT_ID FROM AUTH_STUDENT_PASSWORD_OPERATION WHERE OPERATION_ID=:operationId; + */ + public static final String GET_STUDENT_ID = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("SELECT STUDENT_ID FROM AUTH_STUDENT_PASSWORD_OPERATION " + + "WHERE OPERATION_ID=:operationId").toString(); +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/service/StudentPasswordOperationOutService.java b/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/service/StudentPasswordOperationOutService.java new file mode 100644 index 00000000..5a54c754 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/service/StudentPasswordOperationOutService.java @@ -0,0 +1,10 @@ +package com.graduationproject.studentinformationsystem.login.student.password.service; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; + +public interface StudentPasswordOperationOutService { + + String getPasswordChangeUrl(Long studentId); + + void saveOrUpdatePasswordOperation(Long studentId, String feUrl) throws SisNotExistException; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/service/StudentPasswordOperationService.java b/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/service/StudentPasswordOperationService.java new file mode 100644 index 00000000..8cd02a01 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/service/StudentPasswordOperationService.java @@ -0,0 +1,16 @@ +package com.graduationproject.studentinformationsystem.login.student.password.service; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.login.student.password.model.dto.request.StudentPasswordChangeRequest; +import com.graduationproject.studentinformationsystem.login.student.password.model.dto.request.StudentPasswordForgotRequest; +import com.graduationproject.studentinformationsystem.login.student.password.model.dto.response.StudentPasswordChangeResponse; +import com.graduationproject.studentinformationsystem.login.student.password.model.dto.response.StudentPasswordForgotResponse; + +public interface StudentPasswordOperationService { + + StudentPasswordChangeResponse changePassword(StudentPasswordChangeRequest passwordChangeRequest) throws SisNotExistException; + + StudentPasswordForgotResponse forgotPassword(StudentPasswordForgotRequest passwordForgotRequest) throws SisNotExistException; + + boolean isPasswordChangeEnabled(String operationId) throws SisNotExistException; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/service/impl/StudentPasswordOperationOutServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/service/impl/StudentPasswordOperationOutServiceImpl.java new file mode 100644 index 00000000..0be23f49 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/service/impl/StudentPasswordOperationOutServiceImpl.java @@ -0,0 +1,96 @@ +package com.graduationproject.studentinformationsystem.login.student.password.service.impl; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.login.student.password.model.dto.converter.StudentPasswordOperationInfoConverter; +import com.graduationproject.studentinformationsystem.login.student.password.model.dto.response.StudentPasswordOperationResponse; +import com.graduationproject.studentinformationsystem.login.student.password.model.entity.StudentPasswordOperationEntity; +import com.graduationproject.studentinformationsystem.login.student.password.repository.StudentPasswordOperationRepository; +import com.graduationproject.studentinformationsystem.login.student.password.service.StudentPasswordOperationOutService; +import com.graduationproject.studentinformationsystem.university.student.service.StudentOutService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class StudentPasswordOperationOutServiceImpl implements StudentPasswordOperationOutService { + + private final StudentOutService studentOutService; + + private final StudentPasswordOperationRepository passwordOperationRepository; + private final StudentPasswordOperationInfoConverter passwordOperationInfoConverter; + + @Override + public String getPasswordChangeUrl(final Long studentId) { + + final StudentPasswordOperationResponse passwordOperationResponse = getPasswordOperation(studentId); + + return passwordOperationResponse.getPasswordChangeUrl(); + } + + @Override + public void saveOrUpdatePasswordOperation(final Long studentId, final String feUrl) throws SisNotExistException { + + boolean isOperationExist = isOperationExist(studentId); + + if (!isOperationExist) { + savePasswordOperation(studentId, feUrl); + } else { + updatePasswordOperation(studentId, feUrl); + } + } + + private StudentPasswordOperationResponse getPasswordOperation(final Long studentId) { + + final StudentPasswordOperationEntity passwordOperationEntity = passwordOperationRepository.getPasswordOperation(studentId); + + return passwordOperationInfoConverter.entityToResponse(passwordOperationEntity); + } + + private void savePasswordOperation(final Long studentId, final String feUrl) + throws SisNotExistException { + + checkBeforeSaving(studentId); + + final StudentPasswordOperationEntity passwordOperationEntity = passwordOperationInfoConverter + .generateEntity(studentId, feUrl); + + passwordOperationRepository.savePasswordOperation(passwordOperationEntity); + } + + private void updatePasswordOperation(final Long studentId, final String feUrl) + throws SisNotExistException { + + checkBeforeUpdating(studentId); + + final StudentPasswordOperationEntity passwordOperationEntity = passwordOperationInfoConverter + .generateEntity(studentId, feUrl); + + passwordOperationRepository.updatePasswordOperation(passwordOperationEntity); + } + + public boolean isOperationExist(final Long studentId) { + return passwordOperationRepository.isOperationExist(studentId); + } + + + /** + * Checks Before Processing + */ + + private void checkBeforeSaving(final Long studentId) throws SisNotExistException { + ifStudentIsNotExistThrowNotExistException(studentId); + } + + private void checkBeforeUpdating(final Long studentId) throws SisNotExistException { + ifStudentIsNotExistThrowNotExistException(studentId); + } + + + /** + * Throw Exceptions + */ + + private void ifStudentIsNotExistThrowNotExistException(final Long studentId) throws SisNotExistException { + studentOutService.ifStudentIsNotExistThrowNotExistException(studentId); + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/service/impl/StudentPasswordOperationServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/service/impl/StudentPasswordOperationServiceImpl.java new file mode 100644 index 00000000..d78bd45b --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/student/password/service/impl/StudentPasswordOperationServiceImpl.java @@ -0,0 +1,92 @@ +package com.graduationproject.studentinformationsystem.login.student.password.service.impl; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.login.common.service.PasswordOutService; +import com.graduationproject.studentinformationsystem.login.student.common.service.StudentLoginOutService; +import com.graduationproject.studentinformationsystem.login.student.password.model.dto.request.StudentPasswordChangeRequest; +import com.graduationproject.studentinformationsystem.login.student.password.model.dto.request.StudentPasswordForgotRequest; +import com.graduationproject.studentinformationsystem.login.student.password.model.dto.response.StudentPasswordChangeResponse; +import com.graduationproject.studentinformationsystem.login.student.password.model.dto.response.StudentPasswordForgotResponse; +import com.graduationproject.studentinformationsystem.login.student.password.repository.StudentPasswordOperationRepository; +import com.graduationproject.studentinformationsystem.login.student.password.service.StudentPasswordOperationOutService; +import com.graduationproject.studentinformationsystem.login.student.password.service.StudentPasswordOperationService; +import com.graduationproject.studentinformationsystem.university.mail.service.StudentMailService; +import com.graduationproject.studentinformationsystem.university.student.model.dto.response.StudentInfoDetailResponse; +import com.graduationproject.studentinformationsystem.university.student.service.StudentOutService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class StudentPasswordOperationServiceImpl implements StudentPasswordOperationService { + + protected final StudentLoginOutService studentLoginOutService; + protected final PasswordOutService passwordOutService; + + private final StudentOutService studentOutService; + private final StudentMailService studentMailService; + + private final StudentPasswordOperationOutService passwordOperationOutService; + private final StudentPasswordOperationRepository passwordOperationRepository; + + @Override + public StudentPasswordChangeResponse changePassword(final StudentPasswordChangeRequest passwordChangeRequest) { + + final boolean operationAndPasswordsCheck = operationAndPasswordsCheck(passwordChangeRequest); + + if (operationAndPasswordsCheck) { + final String operationId = passwordChangeRequest.getOperationId(); + final Long studentId = passwordOperationRepository.getStudentId(operationId); + final String password = passwordOutService.getEncodedPassword(passwordChangeRequest.getNewPassword()); + + studentLoginOutService.saveOrUpdatePassword(studentId, password); + passwordOperationRepository.deletePasswordOperation(operationId); + + return StudentPasswordChangeResponse.getSuccessResponse(); + } + return StudentPasswordChangeResponse.getFailResponse(); + } + + @Override + public StudentPasswordForgotResponse forgotPassword(StudentPasswordForgotRequest passwordForgotRequest) + throws SisNotExistException { + + final Long studentId = passwordForgotRequest.getStudentId(); + ifStudentIsNotExistThrowNotExistException(studentId); + + final StudentInfoDetailResponse infoDetailResponse = studentOutService.getStudentInfoDetailResponse(studentId); + + passwordOperationOutService.saveOrUpdatePasswordOperation(studentId, passwordForgotRequest.getFeUrl()); + studentMailService.sendForgotPasswordEmail(infoDetailResponse); + + return StudentPasswordForgotResponse.builder() + .isForgotPasswordSuccess(true) + .build(); + } + + @Override + public boolean isPasswordChangeEnabled(final String operationId) { + return passwordOperationRepository.isPasswordChangeEnabled(operationId); + } + + + private boolean operationAndPasswordsCheck(StudentPasswordChangeRequest passwordChangeRequest) { + final String operationId = passwordChangeRequest.getOperationId(); + final String newPassword = passwordChangeRequest.getNewPassword(); + final String newPasswordRepeat = passwordChangeRequest.getNewPasswordRepeat(); + + final boolean isPasswordChangeEnabled = isPasswordChangeEnabled(operationId); + final boolean checkPasswords = newPassword.matches(newPasswordRepeat); + + return isPasswordChangeEnabled && checkPasswords; + } + + + /** + * Throw Exceptions + */ + + private void ifStudentIsNotExistThrowNotExistException(final Long studentId) throws SisNotExistException { + studentOutService.ifStudentIsNotExistThrowNotExistException(studentId); + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/student/service/StudentLoginService.java b/src/main/java/com/graduationproject/studentinformationsystem/login/student/service/StudentLoginService.java deleted file mode 100644 index 0c36dc6b..00000000 --- a/src/main/java/com/graduationproject/studentinformationsystem/login/student/service/StudentLoginService.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.graduationproject.studentinformationsystem.login.student.service; - -import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; -import com.graduationproject.studentinformationsystem.login.common.model.response.ForgotPasswordResponse; -import com.graduationproject.studentinformationsystem.login.common.model.response.LoginResponse; -import com.graduationproject.studentinformationsystem.login.student.model.dto.request.StudentForgotPasswordRequest; -import com.graduationproject.studentinformationsystem.login.student.model.dto.request.StudentLoginRequest; - -public interface StudentLoginService { - - LoginResponse login(StudentLoginRequest loginRequest); - - ForgotPasswordResponse forgotPassword(StudentForgotPasswordRequest forgotPasswordRequest) throws SisNotExistException; -} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/controller/TeacherLoginController.java b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/controller/TeacherLoginController.java similarity index 66% rename from src/main/java/com/graduationproject/studentinformationsystem/login/teacher/controller/TeacherLoginController.java rename to src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/controller/TeacherLoginController.java index 1a01b892..aa7d853a 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/controller/TeacherLoginController.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/controller/TeacherLoginController.java @@ -1,13 +1,10 @@ -package com.graduationproject.studentinformationsystem.login.teacher.controller; +package com.graduationproject.studentinformationsystem.login.teacher.common.controller; import com.graduationproject.studentinformationsystem.common.util.controller.response.SisBaseApiResponse; -import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; import com.graduationproject.studentinformationsystem.login.common.controller.enpoint.LoginControllerEndpoint; -import com.graduationproject.studentinformationsystem.login.common.model.response.ForgotPasswordResponse; import com.graduationproject.studentinformationsystem.login.common.model.response.LoginResponse; -import com.graduationproject.studentinformationsystem.login.teacher.model.dto.request.TeacherForgotPasswordRequest; -import com.graduationproject.studentinformationsystem.login.teacher.model.dto.request.TeacherLoginRequest; -import com.graduationproject.studentinformationsystem.login.teacher.service.TeacherLoginService; +import com.graduationproject.studentinformationsystem.login.teacher.common.model.dto.request.TeacherLoginRequest; +import com.graduationproject.studentinformationsystem.login.teacher.common.service.TeacherLoginService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; @@ -39,14 +36,4 @@ public ResponseEntity> teacherLogin( final LoginResponse loginResponse = loginService.login(loginRequest); return successResponse(loginResponse); } - - @PostMapping(LoginControllerEndpoint.TEACHER_FORGOT_PASSWORD) - @ApiOperation(value = "Teacher Forgot Password") - public ResponseEntity> teacherForgotPassword( - @RequestBody @Valid final TeacherForgotPasswordRequest forgotPasswordRequest) - throws SisNotExistException { - - final ForgotPasswordResponse forgotPasswordResponse = loginService.forgotPassword(forgotPasswordRequest); - return successResponse(forgotPasswordResponse); - } } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/model/dto/request/TeacherForgotPasswordRequest.java b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/model/dto/request/TeacherForgotPasswordRequest.java similarity index 94% rename from src/main/java/com/graduationproject/studentinformationsystem/login/teacher/model/dto/request/TeacherForgotPasswordRequest.java rename to src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/model/dto/request/TeacherForgotPasswordRequest.java index 3c54a22f..b506efc8 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/model/dto/request/TeacherForgotPasswordRequest.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/model/dto/request/TeacherForgotPasswordRequest.java @@ -1,4 +1,4 @@ -package com.graduationproject.studentinformationsystem.login.teacher.model.dto.request; +package com.graduationproject.studentinformationsystem.login.teacher.common.model.dto.request; import com.graduationproject.studentinformationsystem.common.util.validation.id.TeacherID; import lombok.Getter; diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/model/dto/request/TeacherLoginRequest.java b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/model/dto/request/TeacherLoginRequest.java similarity index 94% rename from src/main/java/com/graduationproject/studentinformationsystem/login/teacher/model/dto/request/TeacherLoginRequest.java rename to src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/model/dto/request/TeacherLoginRequest.java index fb4da2e8..8e6ab7ce 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/model/dto/request/TeacherLoginRequest.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/model/dto/request/TeacherLoginRequest.java @@ -1,4 +1,4 @@ -package com.graduationproject.studentinformationsystem.login.teacher.model.dto.request; +package com.graduationproject.studentinformationsystem.login.teacher.common.model.dto.request; import com.graduationproject.studentinformationsystem.common.util.validation.id.TeacherID; import lombok.Getter; diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/model/entity/TeacherLoginInfoEntity.java b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/model/entity/TeacherLoginInfoEntity.java similarity index 93% rename from src/main/java/com/graduationproject/studentinformationsystem/login/teacher/model/entity/TeacherLoginInfoEntity.java rename to src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/model/entity/TeacherLoginInfoEntity.java index a97a4cf6..3e86c6ed 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/model/entity/TeacherLoginInfoEntity.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/model/entity/TeacherLoginInfoEntity.java @@ -1,4 +1,4 @@ -package com.graduationproject.studentinformationsystem.login.teacher.model.entity; +package com.graduationproject.studentinformationsystem.login.teacher.common.model.entity; import com.graduationproject.studentinformationsystem.common.model.entity.SisBaseLoginInfoEntity; import lombok.Getter; diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/model/mapping/TeacherLoginMapping.java b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/model/mapping/TeacherLoginMapping.java similarity index 96% rename from src/main/java/com/graduationproject/studentinformationsystem/login/teacher/model/mapping/TeacherLoginMapping.java rename to src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/model/mapping/TeacherLoginMapping.java index abd862e1..092ebec4 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/model/mapping/TeacherLoginMapping.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/model/mapping/TeacherLoginMapping.java @@ -1,4 +1,4 @@ -package com.graduationproject.studentinformationsystem.login.teacher.model.mapping; +package com.graduationproject.studentinformationsystem.login.teacher.common.model.mapping; import lombok.Getter; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/repository/TeacherLoginRepository.java b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/repository/TeacherLoginRepository.java similarity index 60% rename from src/main/java/com/graduationproject/studentinformationsystem/login/teacher/repository/TeacherLoginRepository.java rename to src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/repository/TeacherLoginRepository.java index 3847c9dd..ea241b80 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/repository/TeacherLoginRepository.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/repository/TeacherLoginRepository.java @@ -1,6 +1,6 @@ -package com.graduationproject.studentinformationsystem.login.teacher.repository; +package com.graduationproject.studentinformationsystem.login.teacher.common.repository; -import com.graduationproject.studentinformationsystem.login.teacher.model.entity.TeacherLoginInfoEntity; +import com.graduationproject.studentinformationsystem.login.teacher.common.model.entity.TeacherLoginInfoEntity; public interface TeacherLoginRepository { @@ -8,11 +8,13 @@ public interface TeacherLoginRepository { String getPassword(Long teacherId); - void saveFirstPassword(Long teacherId, String password); + void savePassword(Long teacherId, String encodedPassword); - void updatePassword(Long teacherId, String password); + void updatePassword(Long teacherId, String encodedPassword); void updateLoginInfo(TeacherLoginInfoEntity loginInfoEntity); void updateFailCounter(Long teacherId); + + boolean isPasswordExist(Long teacherId); } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/repository/impl/TeacherLoginRepositoryImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/repository/impl/TeacherLoginRepositoryImpl.java similarity index 74% rename from src/main/java/com/graduationproject/studentinformationsystem/login/teacher/repository/impl/TeacherLoginRepositoryImpl.java rename to src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/repository/impl/TeacherLoginRepositoryImpl.java index f62256a9..5ed62689 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/repository/impl/TeacherLoginRepositoryImpl.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/repository/impl/TeacherLoginRepositoryImpl.java @@ -1,24 +1,21 @@ -package com.graduationproject.studentinformationsystem.login.teacher.repository.impl; +package com.graduationproject.studentinformationsystem.login.teacher.common.repository.impl; import com.graduationproject.studentinformationsystem.common.util.exception.SisDatabaseException; -import com.graduationproject.studentinformationsystem.login.common.service.PasswordService; -import com.graduationproject.studentinformationsystem.login.teacher.model.entity.TeacherLoginInfoEntity; -import com.graduationproject.studentinformationsystem.login.teacher.repository.TeacherLoginRepository; +import com.graduationproject.studentinformationsystem.login.teacher.common.model.entity.TeacherLoginInfoEntity; +import com.graduationproject.studentinformationsystem.login.teacher.common.repository.TeacherLoginRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Repository; import org.sql2o.Connection; import org.sql2o.Query; import org.sql2o.Sql2o; -import static com.graduationproject.studentinformationsystem.login.teacher.model.mapping.TeacherLoginMapping.*; -import static com.graduationproject.studentinformationsystem.login.teacher.repository.impl.scripts.TeacherLoginSqlScripts.*; +import static com.graduationproject.studentinformationsystem.login.teacher.common.model.mapping.TeacherLoginMapping.*; +import static com.graduationproject.studentinformationsystem.login.teacher.common.repository.impl.scripts.TeacherLoginSqlScripts.*; @Repository @RequiredArgsConstructor public class TeacherLoginRepositoryImpl implements TeacherLoginRepository { - private final PasswordService passwordService; - private final Sql2o sql2o; @Override @@ -52,11 +49,11 @@ public String getPassword(final Long teacherId) { } @Override - public void saveFirstPassword(final Long teacherId, final String password) { - try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(SAVE_TEACHER_FIRST_PASSWORD)) { + public void savePassword(final Long teacherId, final String encodedPassword) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(SAVE_TEACHER_PASSWORD)) { query.addParameter(TEACHER_ID.getModelName(), teacherId) - .addParameter(PASSWORD.getModelName(), passwordService.encodePassword(password)) + .addParameter(PASSWORD.getModelName(), encodedPassword) .addParameter(FAIL_COUNTER.getModelName(), 0) .executeUpdate(); @@ -68,11 +65,12 @@ public void saveFirstPassword(final Long teacherId, final String password) { } @Override - public void updatePassword(final Long teacherId, final String password) { + public void updatePassword(final Long teacherId, final String encodedPassword) { try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(UPDATE_TEACHER_PASSWORD)) { query.addParameter(TEACHER_ID.getModelName(), teacherId) - .addParameter(PASSWORD.getModelName(), passwordService.encodePassword(password)) + .addParameter(PASSWORD.getModelName(), encodedPassword) + .addParameter(FAIL_COUNTER.getModelName(), 0) .executeUpdate(); // TODO: Specific Info Log Must be Added @@ -113,21 +111,17 @@ public void updateFailCounter(final Long teacherId) { } } -// TODO: Change or Update Password -// @Override -// public void updatePassword(final TeacherLoginInfoEntity loginInfoEntity) { -// try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(UPDATE_TEACHER_PASSWORD)) { -// -// query.addParameter(TEACHER_ID.getModelName(), loginInfoEntity.getTeacherId()) -// .addParameter(PASSWORD.getModelName(), loginInfoEntity.getPassword()) -// .addParameter(FAIL_COUNTER.getModelName(), loginInfoEntity.getFailCounter()) -// .addParameter(LAST_LOGIN_DATE.getModelName(), loginInfoEntity.getLastLoginDate()) -// .executeUpdate(); -// + @Override + public boolean isPasswordExist(final Long teacherId) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(IS_TEACHER_PASSWORD_EXIST)) { + + return query.addParameter(TEACHER_ID.getModelName(), teacherId) + .executeScalar(Boolean.class); + // TODO: Specific Info Log Must be Added -// } catch (Exception exception) { + } catch (Exception exception) { // TODO: Specific Error Log Must be Added -// throw new SisDatabaseException(exception); -// } -// } + throw new SisDatabaseException(exception); + } + } } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/repository/impl/scripts/TeacherLoginSqlScripts.java b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/repository/impl/scripts/TeacherLoginSqlScripts.java similarity index 73% rename from src/main/java/com/graduationproject/studentinformationsystem/login/teacher/repository/impl/scripts/TeacherLoginSqlScripts.java rename to src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/repository/impl/scripts/TeacherLoginSqlScripts.java index 2a98237c..95f7246e 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/repository/impl/scripts/TeacherLoginSqlScripts.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/repository/impl/scripts/TeacherLoginSqlScripts.java @@ -1,4 +1,4 @@ -package com.graduationproject.studentinformationsystem.login.teacher.repository.impl.scripts; +package com.graduationproject.studentinformationsystem.login.teacher.common.repository.impl.scripts; public class TeacherLoginSqlScripts { @@ -24,17 +24,18 @@ private TeacherLoginSqlScripts() { /** * INSERT INTO AUTH_TEACHER_LOGIN SET TEACHER_ID=:teacherId, PASSWORD=:password, FAIL_COUNTER=:failCounter; */ - public static final String SAVE_TEACHER_FIRST_PASSWORD = + public static final String SAVE_TEACHER_PASSWORD = sqlBuilder.delete(0, sqlBuilder.length()) .append("INSERT INTO AUTH_TEACHER_LOGIN SET TEACHER_ID=:teacherId, PASSWORD=:password," + " FAIL_COUNTER=:failCounter").toString(); /** - * UPDATE AUTH_TEACHER_LOGIN SET PASSWORD=:password WHERE TEACHER_ID=:teacherId; + * UPDATE AUTH_TEACHER_LOGIN SET PASSWORD=:password, FAIL_COUNTER=:failCounter WHERE TEACHER_ID=:teacherId; */ public static final String UPDATE_TEACHER_PASSWORD = sqlBuilder.delete(0, sqlBuilder.length()) - .append("UPDATE AUTH_TEACHER_LOGIN SET PASSWORD=:password WHERE TEACHER_ID=:teacherId").toString(); + .append("UPDATE AUTH_TEACHER_LOGIN SET PASSWORD=:password, FAIL_COUNTER=:failCounter " + + "WHERE TEACHER_ID=:teacherId").toString(); /** * UPDATE AUTH_TEACHER_LOGIN SET FAIL_COUNTER=:failCounter, LAST_LOGIN_DATE=:lastLoginDate @@ -52,4 +53,13 @@ private TeacherLoginSqlScripts() { sqlBuilder.delete(0, sqlBuilder.length()) .append("UPDATE AUTH_TEACHER_LOGIN SET FAIL_COUNTER=:failCounter " + "WHERE TEACHER_ID=:teacherId").toString(); + + /** + * SELECT CASE WHEN MAX(TEACHER_ID) IS NULL THEN 'false' ELSE 'true' END IS_EXIST + * FROM AUTH_TEACHER_LOGIN WHERE TEACHER_ID=:teacherId; + */ + public static final String IS_TEACHER_PASSWORD_EXIST = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("SELECT CASE WHEN MAX(TEACHER_ID) IS NULL THEN 'false' ELSE 'true' END IS_EXIST " + + "FROM AUTH_TEACHER_LOGIN WHERE TEACHER_ID=:teacherId").toString(); } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/service/TeacherLoginOutService.java b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/service/TeacherLoginOutService.java new file mode 100644 index 00000000..96b496e6 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/service/TeacherLoginOutService.java @@ -0,0 +1,6 @@ +package com.graduationproject.studentinformationsystem.login.teacher.common.service; + +public interface TeacherLoginOutService { + + void saveOrUpdatePassword(Long teacherId, String encodedPassword); +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/service/TeacherLoginService.java b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/service/TeacherLoginService.java new file mode 100644 index 00000000..50d63d09 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/service/TeacherLoginService.java @@ -0,0 +1,9 @@ +package com.graduationproject.studentinformationsystem.login.teacher.common.service; + +import com.graduationproject.studentinformationsystem.login.common.model.response.LoginResponse; +import com.graduationproject.studentinformationsystem.login.teacher.common.model.dto.request.TeacherLoginRequest; + +public interface TeacherLoginService { + + LoginResponse login(TeacherLoginRequest loginRequest); +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/service/impl/TeacherLoginOutServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/service/impl/TeacherLoginOutServiceImpl.java new file mode 100644 index 00000000..657eaea7 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/service/impl/TeacherLoginOutServiceImpl.java @@ -0,0 +1,25 @@ +package com.graduationproject.studentinformationsystem.login.teacher.common.service.impl; + +import com.graduationproject.studentinformationsystem.login.teacher.common.repository.TeacherLoginRepository; +import com.graduationproject.studentinformationsystem.login.teacher.common.service.TeacherLoginOutService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class TeacherLoginOutServiceImpl implements TeacherLoginOutService { + + private final TeacherLoginRepository teacherLoginRepository; + + @Override + public void saveOrUpdatePassword(final Long teacherId, final String encodedPassword) { + + boolean isPasswordExist = teacherLoginRepository.isPasswordExist(teacherId); + + if (!isPasswordExist) { + teacherLoginRepository.savePassword(teacherId, encodedPassword); + } else { + teacherLoginRepository.updatePassword(teacherId, encodedPassword); + } + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/service/impl/TeacherLoginServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/service/impl/TeacherLoginServiceImpl.java similarity index 70% rename from src/main/java/com/graduationproject/studentinformationsystem/login/teacher/service/impl/TeacherLoginServiceImpl.java rename to src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/service/impl/TeacherLoginServiceImpl.java index 66a9ef37..258ceab0 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/service/impl/TeacherLoginServiceImpl.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/common/service/impl/TeacherLoginServiceImpl.java @@ -1,17 +1,12 @@ -package com.graduationproject.studentinformationsystem.login.teacher.service.impl; +package com.graduationproject.studentinformationsystem.login.teacher.common.service.impl; -import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; -import com.graduationproject.studentinformationsystem.login.common.model.response.ForgotPasswordResponse; import com.graduationproject.studentinformationsystem.login.common.model.response.LoginResponse; import com.graduationproject.studentinformationsystem.login.common.service.PasswordService; -import com.graduationproject.studentinformationsystem.login.teacher.model.dto.request.TeacherForgotPasswordRequest; -import com.graduationproject.studentinformationsystem.login.teacher.model.dto.request.TeacherLoginRequest; -import com.graduationproject.studentinformationsystem.login.teacher.model.entity.TeacherLoginInfoEntity; -import com.graduationproject.studentinformationsystem.login.teacher.repository.TeacherLoginRepository; -import com.graduationproject.studentinformationsystem.login.teacher.service.TeacherLoginService; -import com.graduationproject.studentinformationsystem.university.mail.service.TeacherMailService; +import com.graduationproject.studentinformationsystem.login.teacher.common.model.dto.request.TeacherLoginRequest; +import com.graduationproject.studentinformationsystem.login.teacher.common.model.entity.TeacherLoginInfoEntity; +import com.graduationproject.studentinformationsystem.login.teacher.common.repository.TeacherLoginRepository; +import com.graduationproject.studentinformationsystem.login.teacher.common.service.TeacherLoginService; import com.graduationproject.studentinformationsystem.university.teacher.service.TeacherAcademicInfoService; -import com.graduationproject.studentinformationsystem.university.teacher.service.TeacherService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -22,9 +17,7 @@ @RequiredArgsConstructor public class TeacherLoginServiceImpl implements TeacherLoginService { - private final TeacherService teacherService; private final TeacherAcademicInfoService academicInfoService; - private final TeacherMailService mailService; private final TeacherLoginRepository loginRepository; private final PasswordService passwordService; @@ -48,12 +41,6 @@ public LoginResponse login(TeacherLoginRequest loginRequest) { return getFailLoginResponse(); } - @Override - public ForgotPasswordResponse forgotPassword(TeacherForgotPasswordRequest forgotPasswordRequest) throws SisNotExistException { - mailService.sendForgotPasswordEmail(teacherService.getTeacherDetailById(forgotPasswordRequest.getTeacherId())); - return ForgotPasswordResponse.builder().isForgotPasswordSuccess(true).build(); - } - private boolean isTeacherActive(Long teacherId) { return academicInfoService.isTeacherActive(teacherId); diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/controller/TeacherPasswordOperationController.java b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/controller/TeacherPasswordOperationController.java new file mode 100644 index 00000000..a9b3c5bc --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/controller/TeacherPasswordOperationController.java @@ -0,0 +1,65 @@ +package com.graduationproject.studentinformationsystem.login.teacher.password.controller; + +import com.graduationproject.studentinformationsystem.common.util.controller.response.SisApiResponse; +import com.graduationproject.studentinformationsystem.common.util.controller.response.SisBaseApiResponse; +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.login.teacher.password.controller.endpoint.TeacherPasswordOperationControllerEndpoint; +import com.graduationproject.studentinformationsystem.login.teacher.password.model.dto.request.TeacherPasswordChangeRequest; +import com.graduationproject.studentinformationsystem.login.teacher.password.model.dto.request.TeacherPasswordForgotRequest; +import com.graduationproject.studentinformationsystem.login.teacher.password.model.dto.response.TeacherPasswordChangeResponse; +import com.graduationproject.studentinformationsystem.login.teacher.password.model.dto.response.TeacherPasswordForgotResponse; +import com.graduationproject.studentinformationsystem.login.teacher.password.service.TeacherPasswordOperationService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; + +import static com.graduationproject.studentinformationsystem.common.config.SisSwaggerConfiguration.TEACHER_PASSWORD_OPERATION_API_TAG; +import static com.graduationproject.studentinformationsystem.common.util.controller.endpoint.SisControllerEndpoint.Path.TEACHER_PASSWORD_OPERATION; +import static com.graduationproject.studentinformationsystem.common.util.controller.response.SisResponseUtil.successResponse; +import static com.graduationproject.studentinformationsystem.common.util.controller.response.SisResponseUtil.unauthorizedResponse; + +@RestController +@RequestMapping(TEACHER_PASSWORD_OPERATION) +@Api(tags = TEACHER_PASSWORD_OPERATION_API_TAG) +@RequiredArgsConstructor +public class TeacherPasswordOperationController { + + private final TeacherPasswordOperationService passwordOperationService; + + @GetMapping + @ApiOperation(value = "Is Teacher Password Change Operation Enabled") + public ResponseEntity isPasswordChangeOperationEnabled( + @RequestParam final String operationId) throws SisNotExistException { + + final boolean isPasswordChangeEnabled = passwordOperationService.isPasswordChangeEnabled(operationId); + + if (isPasswordChangeEnabled) { + return successResponse(); + } else { + return unauthorizedResponse(); + } + } + + @PostMapping(TeacherPasswordOperationControllerEndpoint.CHANGE_PASSWORD) + @ApiOperation(value = "Change Teacher Password") + public ResponseEntity> changePassword( + @RequestBody final TeacherPasswordChangeRequest passwordChangeRequest) throws SisNotExistException { + + final TeacherPasswordChangeResponse passwordChangeResponse = passwordOperationService.changePassword(passwordChangeRequest); + return successResponse(passwordChangeResponse); + } + + @PostMapping(TeacherPasswordOperationControllerEndpoint.FORGOT_PASSWORD) + @ApiOperation(value = "Teacher Forgot Password") + public ResponseEntity> forgotPassword( + @RequestBody @Valid final TeacherPasswordForgotRequest passwordForgotRequest) + throws SisNotExistException { + + final TeacherPasswordForgotResponse passwordOperationResponse = passwordOperationService.forgotPassword(passwordForgotRequest); + return successResponse(passwordOperationResponse); + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/controller/endpoint/TeacherPasswordOperationControllerEndpoint.java b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/controller/endpoint/TeacherPasswordOperationControllerEndpoint.java new file mode 100644 index 00000000..4125eb0e --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/controller/endpoint/TeacherPasswordOperationControllerEndpoint.java @@ -0,0 +1,10 @@ +package com.graduationproject.studentinformationsystem.login.teacher.password.controller.endpoint; + +public class TeacherPasswordOperationControllerEndpoint { + + private TeacherPasswordOperationControllerEndpoint() { + } + + public static final String CHANGE_PASSWORD = "/change-password"; + public static final String FORGOT_PASSWORD = "/forgot-password"; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/model/dto/converter/TeacherPasswordOperationInfoConverter.java b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/model/dto/converter/TeacherPasswordOperationInfoConverter.java new file mode 100644 index 00000000..61da2ebd --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/model/dto/converter/TeacherPasswordOperationInfoConverter.java @@ -0,0 +1,34 @@ +package com.graduationproject.studentinformationsystem.login.teacher.password.model.dto.converter; + +import com.graduationproject.studentinformationsystem.common.util.SisUtil; +import com.graduationproject.studentinformationsystem.login.teacher.password.model.dto.response.TeacherPasswordOperationResponse; +import com.graduationproject.studentinformationsystem.login.teacher.password.model.entity.TeacherPasswordOperationEntity; +import org.springframework.stereotype.Component; + +import java.time.LocalDateTime; + +@Component +public class TeacherPasswordOperationInfoConverter { + + public TeacherPasswordOperationEntity generateEntity(final Long teacherId, final String feUrl) { + + return TeacherPasswordOperationEntity.builder() + .operationId(SisUtil.generateRandomUUID()) + .teacherId(teacherId) + .expireDate(LocalDateTime.now().plusDays(1)) + .feUrl(feUrl) + .build(); + } + + public TeacherPasswordOperationResponse entityToResponse(final TeacherPasswordOperationEntity passwordOperationEntity) { + + final String operationId = passwordOperationEntity.getOperationId(); + + return TeacherPasswordOperationResponse.builder() + .operationId(operationId) + .teacherId(passwordOperationEntity.getTeacherId()) + .expireDate(passwordOperationEntity.getExpireDate()) + .passwordChangeUrl(passwordOperationEntity.getFeUrl() + "/login/teacher/change-password/" + operationId) + .build(); + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/model/dto/request/TeacherPasswordChangeRequest.java b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/model/dto/request/TeacherPasswordChangeRequest.java new file mode 100644 index 00000000..4b58c678 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/model/dto/request/TeacherPasswordChangeRequest.java @@ -0,0 +1,23 @@ +package com.graduationproject.studentinformationsystem.login.teacher.password.model.dto.request; + +import lombok.Getter; + +import javax.validation.constraints.NotNull; +import java.io.Serial; +import java.io.Serializable; + +@Getter +public class TeacherPasswordChangeRequest implements Serializable { + + @Serial + private static final long serialVersionUID = -2742530497673012860L; + + @NotNull + private String operationId; + + @NotNull + private String newPassword; + + @NotNull + private String newPasswordRepeat; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/model/dto/request/TeacherPasswordForgotRequest.java b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/model/dto/request/TeacherPasswordForgotRequest.java new file mode 100644 index 00000000..5cb7b20b --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/model/dto/request/TeacherPasswordForgotRequest.java @@ -0,0 +1,22 @@ +package com.graduationproject.studentinformationsystem.login.teacher.password.model.dto.request; + +import com.graduationproject.studentinformationsystem.common.util.validation.id.TeacherID; +import lombok.Getter; + +import javax.validation.constraints.NotNull; +import java.io.Serial; +import java.io.Serializable; + +@Getter +public class TeacherPasswordForgotRequest implements Serializable { + + @Serial + private static final long serialVersionUID = 150037221929036553L; + + @NotNull + @TeacherID + private Long teacherId; + + @NotNull + private String feUrl; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/model/dto/response/TeacherPasswordChangeResponse.java b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/model/dto/response/TeacherPasswordChangeResponse.java new file mode 100644 index 00000000..bc0dc9fe --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/model/dto/response/TeacherPasswordChangeResponse.java @@ -0,0 +1,21 @@ +package com.graduationproject.studentinformationsystem.login.teacher.password.model.dto.response; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class TeacherPasswordChangeResponse { + + private boolean isPasswordChanged; + + public static TeacherPasswordChangeResponse getSuccessResponse() { + return TeacherPasswordChangeResponse.builder() + .isPasswordChanged(true).build(); + } + + public static TeacherPasswordChangeResponse getFailResponse() { + return TeacherPasswordChangeResponse.builder() + .isPasswordChanged(false).build(); + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/model/dto/response/TeacherPasswordForgotResponse.java b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/model/dto/response/TeacherPasswordForgotResponse.java new file mode 100644 index 00000000..25de6030 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/model/dto/response/TeacherPasswordForgotResponse.java @@ -0,0 +1,11 @@ +package com.graduationproject.studentinformationsystem.login.teacher.password.model.dto.response; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class TeacherPasswordForgotResponse { + + private boolean isForgotPasswordSuccess; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/model/dto/response/TeacherPasswordOperationResponse.java b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/model/dto/response/TeacherPasswordOperationResponse.java new file mode 100644 index 00000000..f72f0c23 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/model/dto/response/TeacherPasswordOperationResponse.java @@ -0,0 +1,16 @@ +package com.graduationproject.studentinformationsystem.login.teacher.password.model.dto.response; + +import lombok.Builder; +import lombok.Getter; + +import java.time.LocalDateTime; + +@Getter +@Builder +public class TeacherPasswordOperationResponse { + + private String operationId; + private Long teacherId; + private LocalDateTime expireDate; + private String passwordChangeUrl; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/model/entity/TeacherPasswordChangeEntity.java b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/model/entity/TeacherPasswordChangeEntity.java new file mode 100644 index 00000000..2fde9619 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/model/entity/TeacherPasswordChangeEntity.java @@ -0,0 +1,12 @@ +package com.graduationproject.studentinformationsystem.login.teacher.password.model.entity; + +import lombok.Builder; +import lombok.Getter; + +@Getter +@Builder +public class TeacherPasswordChangeEntity { + + protected String newPassword; + protected String newPasswordRepeat; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/model/entity/TeacherPasswordOperationEntity.java b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/model/entity/TeacherPasswordOperationEntity.java new file mode 100644 index 00000000..ae9443bd --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/model/entity/TeacherPasswordOperationEntity.java @@ -0,0 +1,16 @@ +package com.graduationproject.studentinformationsystem.login.teacher.password.model.entity; + +import lombok.Builder; +import lombok.Getter; + +import java.time.LocalDateTime; + +@Getter +@Builder +public class TeacherPasswordOperationEntity { + + private String operationId; + private Long teacherId; + private LocalDateTime expireDate; + private String feUrl; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/model/mapping/TeacherPasswordOperationMapping.java b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/model/mapping/TeacherPasswordOperationMapping.java new file mode 100644 index 00000000..d504cfa4 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/model/mapping/TeacherPasswordOperationMapping.java @@ -0,0 +1,24 @@ +package com.graduationproject.studentinformationsystem.login.teacher.password.model.mapping; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +@Getter +@RequiredArgsConstructor +public enum TeacherPasswordOperationMapping { + + OPERATION_ID("OPERATION_ID", "operationId"), + TEACHER_ID("TEACHER_ID", "teacherId"), + EXPIRE_DATE("EXPIRE_DATE", "expireDate"), + FE_URL("FE_URL", "feUrl"); + + private final String columnName; + private final String modelName; + + public static final Map COLUMN_MAPPINGS = Stream.of(values()) + .collect(Collectors.toMap(TeacherPasswordOperationMapping::getColumnName, TeacherPasswordOperationMapping::getModelName)); +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/repository/TeacherPasswordOperationRepository.java b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/repository/TeacherPasswordOperationRepository.java new file mode 100644 index 00000000..83306135 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/repository/TeacherPasswordOperationRepository.java @@ -0,0 +1,20 @@ +package com.graduationproject.studentinformationsystem.login.teacher.password.repository; + +import com.graduationproject.studentinformationsystem.login.teacher.password.model.entity.TeacherPasswordOperationEntity; + +public interface TeacherPasswordOperationRepository { + + TeacherPasswordOperationEntity getPasswordOperation(Long teacherId); + + void savePasswordOperation(TeacherPasswordOperationEntity passwordOperationEntity); + + void updatePasswordOperation(TeacherPasswordOperationEntity passwordOperationEntity); + + void deletePasswordOperation(String operationId); + + boolean isPasswordChangeEnabled(String operationId); + + boolean isOperationExist(Long teacherId); + + Long getTeacherId(String operationId); +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/repository/impl/TeacherPasswordOperationRepositoryImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/repository/impl/TeacherPasswordOperationRepositoryImpl.java new file mode 100644 index 00000000..cfe67893 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/repository/impl/TeacherPasswordOperationRepositoryImpl.java @@ -0,0 +1,126 @@ +package com.graduationproject.studentinformationsystem.login.teacher.password.repository.impl; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisDatabaseException; +import com.graduationproject.studentinformationsystem.login.teacher.password.model.entity.TeacherPasswordOperationEntity; +import com.graduationproject.studentinformationsystem.login.teacher.password.repository.TeacherPasswordOperationRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; +import org.sql2o.Connection; +import org.sql2o.Query; +import org.sql2o.Sql2o; + +import static com.graduationproject.studentinformationsystem.login.teacher.password.model.mapping.TeacherPasswordOperationMapping.*; +import static com.graduationproject.studentinformationsystem.login.teacher.password.repository.impl.scripts.TeacherPasswordOperationSqlScripts.*; + +@Repository +@RequiredArgsConstructor +public class TeacherPasswordOperationRepositoryImpl implements TeacherPasswordOperationRepository { + + private final Sql2o sql2o; + + @Override + public TeacherPasswordOperationEntity getPasswordOperation(final Long teacherId) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(GET_TEACHER_PASSWORD_OPERATION)) { + + return query.addParameter(TEACHER_ID.getModelName(), teacherId) + .setColumnMappings(COLUMN_MAPPINGS) + .executeAndFetchFirst(TeacherPasswordOperationEntity.class); + +// TODO: Specific Info Log Must be Added + } catch (Exception exception) { +// TODO: Specific Log Error Must be Added + throw new SisDatabaseException(exception); + } + } + + @Override + public void savePasswordOperation(final TeacherPasswordOperationEntity passwordOperationEntity) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(SAVE_TEACHER_PASSWORD_OPERATION)) { + + query.addParameter(OPERATION_ID.getModelName(), passwordOperationEntity.getOperationId()) + .addParameter(TEACHER_ID.getModelName(), passwordOperationEntity.getTeacherId()) + .addParameter(EXPIRE_DATE.getModelName(), passwordOperationEntity.getExpireDate()) + .addParameter(FE_URL.getModelName(), passwordOperationEntity.getFeUrl()) + .executeUpdate(); + +// TODO: Specific Info Log Must be Added + } catch (Exception exception) { +// TODO: Specific Error Log Must be Added + throw new SisDatabaseException(exception); + } + } + + @Override + public void updatePasswordOperation(final TeacherPasswordOperationEntity passwordOperationEntity) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(UPDATE_TEACHER_PASSWORD_OPERATION)) { + + query.addParameter(OPERATION_ID.getModelName(), passwordOperationEntity.getOperationId()) + .addParameter(TEACHER_ID.getModelName(), passwordOperationEntity.getTeacherId()) + .addParameter(EXPIRE_DATE.getModelName(), passwordOperationEntity.getExpireDate()) + .addParameter(FE_URL.getModelName(), passwordOperationEntity.getFeUrl()) + .executeUpdate(); + +// TODO: Specific Info Log Must be Added + } catch (Exception exception) { +// TODO: Specific Error Log Must be Added + throw new SisDatabaseException(exception); + } + } + + @Override + public void deletePasswordOperation(final String operationId) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(DELETE_TEACHER_PASSWORD_OPERATION)) { + + query.addParameter(OPERATION_ID.getModelName(), operationId) + .setColumnMappings(COLUMN_MAPPINGS) + .executeUpdate(); + +// TODO: Specific Info Log Must be Added + } catch (Exception exception) { +// TODO: Specific Error Log Must be Added + throw new SisDatabaseException(exception); + } + } + + @Override + public boolean isPasswordChangeEnabled(final String operationId) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(IS_PASSWORD_CHANGE_ENABLED)) { + + return query.addParameter(OPERATION_ID.getModelName(), operationId) + .executeScalar(Boolean.class); + +// TODO: Specific Info Log Must be Added + } catch (Exception exception) { +// TODO: Specific Error Log Must be Added + throw new SisDatabaseException(exception); + } + } + + @Override + public boolean isOperationExist(final Long teacherId) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(IS_OPERATION_EXIST)) { + + return query.addParameter(TEACHER_ID.getModelName(), teacherId) + .executeScalar(Boolean.class); + +// TODO: Specific Info Log Must be Added + } catch (Exception exception) { +// TODO: Specific Error Log Must be Added + throw new SisDatabaseException(exception); + } + } + + @Override + public Long getTeacherId(final String operationId) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(GET_TEACHER_ID)) { + + return query.addParameter(OPERATION_ID.getModelName(), operationId) + .executeScalar(Long.class); + +// TODO: Specific Info Log Must be Added + } catch (Exception exception) { +// TODO: Specific Error Log Must be Added + throw new SisDatabaseException(exception); + } + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/repository/impl/scripts/TeacherPasswordOperationSqlScripts.java b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/repository/impl/scripts/TeacherPasswordOperationSqlScripts.java new file mode 100644 index 00000000..be1f192e --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/repository/impl/scripts/TeacherPasswordOperationSqlScripts.java @@ -0,0 +1,70 @@ +package com.graduationproject.studentinformationsystem.login.teacher.password.repository.impl.scripts; + +public class TeacherPasswordOperationSqlScripts { + + private static final StringBuilder sqlBuilder = new StringBuilder(); + + private TeacherPasswordOperationSqlScripts() { + } + + /** + * SELECT OPERATION_ID, TEACHER_ID, EXPIRE_DATE, FE_URL FROM AUTH_TEACHER_PASSWORD_OPERATION + * WHERE TEACHER_ID=:teacherId; + */ + public static final String GET_TEACHER_PASSWORD_OPERATION = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("SELECT OPERATION_ID, TEACHER_ID, EXPIRE_DATE, FE_URL " + + "FROM AUTH_TEACHER_PASSWORD_OPERATION WHERE TEACHER_ID=:teacherId").toString(); + + /** + * INSERT INTO AUTH_TEACHER_PASSWORD_OPERATION SET OPERATION_ID=:operationId, + * TEACHER_ID=:teacherId, EXPIRE_DATE=:expireDate, FE_URL=:feUrl; + */ + public static final String SAVE_TEACHER_PASSWORD_OPERATION = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("INSERT INTO AUTH_TEACHER_PASSWORD_OPERATION SET OPERATION_ID=:operationId, " + + "TEACHER_ID=:teacherId, EXPIRE_DATE=:expireDate, FE_URL=:feUrl").toString(); + + /** + * UPDATE AUTH_TEACHER_PASSWORD_OPERATION SET OPERATION_ID=:operationId, EXPIRE_DATE=:expireDate, FE_URL=:feUrl + * WHERE TEACHER_ID=:teacherId; + */ + public static final String UPDATE_TEACHER_PASSWORD_OPERATION = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("UPDATE AUTH_TEACHER_PASSWORD_OPERATION SET OPERATION_ID=:operationId, " + + "EXPIRE_DATE=:expireDate, FE_URL=:feUrl WHERE TEACHER_ID=:teacherId").toString(); + + /** + * DELETE FROM AUTH_TEACHER_PASSWORD_OPERATION WHERE OPERATION_ID=:operationId; + */ + public static final String DELETE_TEACHER_PASSWORD_OPERATION = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("DELETE FROM AUTH_TEACHER_PASSWORD_OPERATION WHERE OPERATION_ID=:operationId").toString(); + + /** + * SELECT CASE WHEN MAX(EXPIRE_DATE) IS NULL THEN 'false' ELSE 'true' END IS_EXIST + * FROM AUTH_TEACHER_PASSWORD_OPERATION WHERE OPERATION_ID=:operationId AND EXPIRE_DATE > NOW(); + */ + public static final String IS_PASSWORD_CHANGE_ENABLED = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("SELECT CASE WHEN MAX(EXPIRE_DATE) IS NULL THEN 'false' ELSE 'true' END IS_EXIST " + + "FROM AUTH_TEACHER_PASSWORD_OPERATION " + + "WHERE OPERATION_ID=:operationId AND EXPIRE_DATE > NOW()").toString(); + + /** + * SELECT CASE WHEN MAX(TEACHER_ID) IS NULL THEN 'false' ELSE 'true' END IS_EXIST + * FROM AUTH_TEACHER_PASSWORD_OPERATION WHERE TEACHER_ID=:teacherId; + */ + public static final String IS_OPERATION_EXIST = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("SELECT CASE WHEN MAX(TEACHER_ID) IS NULL THEN 'false' ELSE 'true' END IS_EXIST " + + "FROM AUTH_TEACHER_PASSWORD_OPERATION WHERE TEACHER_ID=:teacherId").toString(); + + /** + * SELECT TEACHER_ID FROM AUTH_TEACHER_PASSWORD_OPERATION WHERE OPERATION_ID=:operationId; + */ + public static final String GET_TEACHER_ID = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("SELECT TEACHER_ID FROM AUTH_TEACHER_PASSWORD_OPERATION " + + "WHERE OPERATION_ID=:operationId").toString(); +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/service/TeacherPasswordOperationOutService.java b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/service/TeacherPasswordOperationOutService.java new file mode 100644 index 00000000..a7696a4c --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/service/TeacherPasswordOperationOutService.java @@ -0,0 +1,10 @@ +package com.graduationproject.studentinformationsystem.login.teacher.password.service; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; + +public interface TeacherPasswordOperationOutService { + + String getPasswordChangeUrl(Long teacherId); + + void saveOrUpdatePasswordOperation(Long teacherId, String feUrl) throws SisNotExistException; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/service/TeacherPasswordOperationService.java b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/service/TeacherPasswordOperationService.java new file mode 100644 index 00000000..ebedc251 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/service/TeacherPasswordOperationService.java @@ -0,0 +1,16 @@ +package com.graduationproject.studentinformationsystem.login.teacher.password.service; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.login.teacher.password.model.dto.request.TeacherPasswordChangeRequest; +import com.graduationproject.studentinformationsystem.login.teacher.password.model.dto.request.TeacherPasswordForgotRequest; +import com.graduationproject.studentinformationsystem.login.teacher.password.model.dto.response.TeacherPasswordChangeResponse; +import com.graduationproject.studentinformationsystem.login.teacher.password.model.dto.response.TeacherPasswordForgotResponse; + +public interface TeacherPasswordOperationService { + + TeacherPasswordChangeResponse changePassword(TeacherPasswordChangeRequest passwordChangeRequest) throws SisNotExistException; + + TeacherPasswordForgotResponse forgotPassword(TeacherPasswordForgotRequest passwordForgotRequest) throws SisNotExistException; + + boolean isPasswordChangeEnabled(String operationId) throws SisNotExistException; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/service/impl/TeacherPasswordOperationOutServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/service/impl/TeacherPasswordOperationOutServiceImpl.java new file mode 100644 index 00000000..61a5f641 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/service/impl/TeacherPasswordOperationOutServiceImpl.java @@ -0,0 +1,96 @@ +package com.graduationproject.studentinformationsystem.login.teacher.password.service.impl; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.login.teacher.password.model.dto.converter.TeacherPasswordOperationInfoConverter; +import com.graduationproject.studentinformationsystem.login.teacher.password.model.dto.response.TeacherPasswordOperationResponse; +import com.graduationproject.studentinformationsystem.login.teacher.password.model.entity.TeacherPasswordOperationEntity; +import com.graduationproject.studentinformationsystem.login.teacher.password.repository.TeacherPasswordOperationRepository; +import com.graduationproject.studentinformationsystem.login.teacher.password.service.TeacherPasswordOperationOutService; +import com.graduationproject.studentinformationsystem.university.teacher.service.TeacherOutService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class TeacherPasswordOperationOutServiceImpl implements TeacherPasswordOperationOutService { + + private final TeacherOutService teacherOutService; + + private final TeacherPasswordOperationRepository passwordOperationRepository; + private final TeacherPasswordOperationInfoConverter passwordOperationInfoConverter; + + @Override + public String getPasswordChangeUrl(final Long teacherId) { + + final TeacherPasswordOperationResponse passwordOperationResponse = getPasswordOperation(teacherId); + + return passwordOperationResponse.getPasswordChangeUrl(); + } + + @Override + public void saveOrUpdatePasswordOperation(final Long teacherId, final String feUrl) throws SisNotExistException { + + boolean isOperationExist = isOperationExist(teacherId); + + if (!isOperationExist) { + savePasswordOperation(teacherId, feUrl); + } else { + updatePasswordOperation(teacherId, feUrl); + } + } + + private TeacherPasswordOperationResponse getPasswordOperation(final Long teacherId) { + + final TeacherPasswordOperationEntity passwordOperationEntity = passwordOperationRepository.getPasswordOperation(teacherId); + + return passwordOperationInfoConverter.entityToResponse(passwordOperationEntity); + } + + private void savePasswordOperation(final Long teacherId, final String feUrl) + throws SisNotExistException { + + checkBeforeSaving(teacherId); + + final TeacherPasswordOperationEntity passwordOperationEntity = passwordOperationInfoConverter + .generateEntity(teacherId, feUrl); + + passwordOperationRepository.savePasswordOperation(passwordOperationEntity); + } + + private void updatePasswordOperation(final Long teacherId, final String feUrl) + throws SisNotExistException { + + checkBeforeUpdating(teacherId); + + final TeacherPasswordOperationEntity passwordOperationEntity = passwordOperationInfoConverter + .generateEntity(teacherId, feUrl); + + passwordOperationRepository.updatePasswordOperation(passwordOperationEntity); + } + + public boolean isOperationExist(final Long teacherId) { + return passwordOperationRepository.isOperationExist(teacherId); + } + + + /** + * Checks Before Processing + */ + + private void checkBeforeSaving(final Long teacherId) throws SisNotExistException { + ifTeacherIsNotExistThrowNotExistException(teacherId); + } + + private void checkBeforeUpdating(final Long teacherId) throws SisNotExistException { + ifTeacherIsNotExistThrowNotExistException(teacherId); + } + + + /** + * Throw Exceptions + */ + + private void ifTeacherIsNotExistThrowNotExistException(final Long teacherId) throws SisNotExistException { + teacherOutService.ifTeacherIsNotExistThrowNotExistException(teacherId); + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/service/impl/TeacherPasswordOperationServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/service/impl/TeacherPasswordOperationServiceImpl.java new file mode 100644 index 00000000..31b72861 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/password/service/impl/TeacherPasswordOperationServiceImpl.java @@ -0,0 +1,92 @@ +package com.graduationproject.studentinformationsystem.login.teacher.password.service.impl; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.login.common.service.PasswordOutService; +import com.graduationproject.studentinformationsystem.login.teacher.common.service.TeacherLoginOutService; +import com.graduationproject.studentinformationsystem.login.teacher.password.model.dto.request.TeacherPasswordChangeRequest; +import com.graduationproject.studentinformationsystem.login.teacher.password.model.dto.request.TeacherPasswordForgotRequest; +import com.graduationproject.studentinformationsystem.login.teacher.password.model.dto.response.TeacherPasswordChangeResponse; +import com.graduationproject.studentinformationsystem.login.teacher.password.model.dto.response.TeacherPasswordForgotResponse; +import com.graduationproject.studentinformationsystem.login.teacher.password.repository.TeacherPasswordOperationRepository; +import com.graduationproject.studentinformationsystem.login.teacher.password.service.TeacherPasswordOperationOutService; +import com.graduationproject.studentinformationsystem.login.teacher.password.service.TeacherPasswordOperationService; +import com.graduationproject.studentinformationsystem.university.mail.service.TeacherMailService; +import com.graduationproject.studentinformationsystem.university.teacher.model.dto.response.TeacherInfoDetailResponse; +import com.graduationproject.studentinformationsystem.university.teacher.service.TeacherOutService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class TeacherPasswordOperationServiceImpl implements TeacherPasswordOperationService { + + protected final TeacherLoginOutService teacherLoginOutService; + protected final PasswordOutService passwordOutService; + + private final TeacherOutService teacherOutService; + private final TeacherMailService teacherMailService; + + private final TeacherPasswordOperationOutService passwordOperationOutService; + private final TeacherPasswordOperationRepository passwordOperationRepository; + + @Override + public TeacherPasswordChangeResponse changePassword(final TeacherPasswordChangeRequest passwordChangeRequest) { + + final boolean operationAndPasswordsCheck = operationAndPasswordsCheck(passwordChangeRequest); + + if (operationAndPasswordsCheck) { + final String operationId = passwordChangeRequest.getOperationId(); + final Long teacherId = passwordOperationRepository.getTeacherId(operationId); + final String password = passwordOutService.getEncodedPassword(passwordChangeRequest.getNewPassword()); + + teacherLoginOutService.saveOrUpdatePassword(teacherId, password); + passwordOperationRepository.deletePasswordOperation(operationId); + + return TeacherPasswordChangeResponse.getSuccessResponse(); + } + return TeacherPasswordChangeResponse.getFailResponse(); + } + + @Override + public TeacherPasswordForgotResponse forgotPassword(TeacherPasswordForgotRequest passwordForgotRequest) + throws SisNotExistException { + + final Long teacherId = passwordForgotRequest.getTeacherId(); + ifTeacherIsNotExistThrowNotExistException(teacherId); + + final TeacherInfoDetailResponse infoDetailResponse = teacherOutService.getTeacherInfoDetailResponse(teacherId); + + passwordOperationOutService.saveOrUpdatePasswordOperation(teacherId, passwordForgotRequest.getFeUrl()); + teacherMailService.sendForgotPasswordEmail(infoDetailResponse); + + return TeacherPasswordForgotResponse.builder() + .isForgotPasswordSuccess(true) + .build(); + } + + @Override + public boolean isPasswordChangeEnabled(final String operationId) { + return passwordOperationRepository.isPasswordChangeEnabled(operationId); + } + + + private boolean operationAndPasswordsCheck(TeacherPasswordChangeRequest passwordChangeRequest) { + final String operationId = passwordChangeRequest.getOperationId(); + final String newPassword = passwordChangeRequest.getNewPassword(); + final String newPasswordRepeat = passwordChangeRequest.getNewPasswordRepeat(); + + final boolean isPasswordChangeEnabled = isPasswordChangeEnabled(operationId); + final boolean checkPasswords = newPassword.matches(newPasswordRepeat); + + return isPasswordChangeEnabled && checkPasswords; + } + + + /** + * Throw Exceptions + */ + + private void ifTeacherIsNotExistThrowNotExistException(final Long teacherId) throws SisNotExistException { + teacherOutService.ifTeacherIsNotExistThrowNotExistException(teacherId); + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/service/TeacherLoginService.java b/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/service/TeacherLoginService.java deleted file mode 100644 index 623db1ad..00000000 --- a/src/main/java/com/graduationproject/studentinformationsystem/login/teacher/service/TeacherLoginService.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.graduationproject.studentinformationsystem.login.teacher.service; - -import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; -import com.graduationproject.studentinformationsystem.login.common.model.response.ForgotPasswordResponse; -import com.graduationproject.studentinformationsystem.login.common.model.response.LoginResponse; -import com.graduationproject.studentinformationsystem.login.teacher.model.dto.request.TeacherForgotPasswordRequest; -import com.graduationproject.studentinformationsystem.login.teacher.model.dto.request.TeacherLoginRequest; - -public interface TeacherLoginService { - - LoginResponse login(TeacherLoginRequest loginRequest); - - ForgotPasswordResponse forgotPassword(TeacherForgotPasswordRequest forgotPasswordRequest) throws SisNotExistException; -} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/mail/service/OfficerMailService.java b/src/main/java/com/graduationproject/studentinformationsystem/university/mail/service/OfficerMailService.java index 878b5ef6..eae556b5 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/mail/service/OfficerMailService.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/mail/service/OfficerMailService.java @@ -4,7 +4,7 @@ public interface OfficerMailService { - void sendFirstPasswordEmail(final OfficerInfoDetailResponse infoDetailResponse); + void sendSavedEmail(final OfficerInfoDetailResponse infoDetailResponse); void sendForgotPasswordEmail(final OfficerInfoDetailResponse infoDetailResponse); } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/mail/service/StudentMailService.java b/src/main/java/com/graduationproject/studentinformationsystem/university/mail/service/StudentMailService.java index ee4bfdca..9dd46373 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/mail/service/StudentMailService.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/mail/service/StudentMailService.java @@ -1,10 +1,11 @@ package com.graduationproject.studentinformationsystem.university.mail.service; +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; import com.graduationproject.studentinformationsystem.university.student.model.dto.response.StudentInfoDetailResponse; public interface StudentMailService { - void sendFirstPasswordEmail(StudentInfoDetailResponse infoDetailResponse); + void sendSavedEmail(StudentInfoDetailResponse infoDetailResponse) throws SisNotExistException; - void sendForgotPasswordEmail(StudentInfoDetailResponse infoDetailResponse); + void sendForgotPasswordEmail(StudentInfoDetailResponse infoDetailResponse) throws SisNotExistException; } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/mail/service/TeacherMailService.java b/src/main/java/com/graduationproject/studentinformationsystem/university/mail/service/TeacherMailService.java index 098a1454..3804e1c1 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/mail/service/TeacherMailService.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/mail/service/TeacherMailService.java @@ -1,10 +1,11 @@ package com.graduationproject.studentinformationsystem.university.mail.service; +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; import com.graduationproject.studentinformationsystem.university.teacher.model.dto.response.TeacherInfoDetailResponse; public interface TeacherMailService { - void sendFirstPasswordEmail(TeacherInfoDetailResponse infoDetailResponse); + void sendSavedEmail(TeacherInfoDetailResponse infoDetailResponse) throws SisNotExistException; - void sendForgotPasswordEmail(TeacherInfoDetailResponse infoDetailResponse); + void sendForgotPasswordEmail(TeacherInfoDetailResponse infoDetailResponse) throws SisNotExistException; } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/mail/service/impl/OfficerMailServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/mail/service/impl/OfficerMailServiceImpl.java index 4fd8e5c7..bfb37d9e 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/mail/service/impl/OfficerMailServiceImpl.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/mail/service/impl/OfficerMailServiceImpl.java @@ -1,8 +1,7 @@ package com.graduationproject.studentinformationsystem.university.mail.service.impl; import com.graduationproject.studentinformationsystem.common.util.SisUtil; -import com.graduationproject.studentinformationsystem.login.common.service.PasswordService; -import com.graduationproject.studentinformationsystem.login.officer.repository.OfficerLoginRepository; +import com.graduationproject.studentinformationsystem.login.officer.password.service.OfficerPasswordOperationOutService; import com.graduationproject.studentinformationsystem.university.mail.model.entity.SisMailEntity; import com.graduationproject.studentinformationsystem.university.mail.service.MailService; import com.graduationproject.studentinformationsystem.university.mail.service.OfficerMailService; @@ -22,10 +21,9 @@ @RequiredArgsConstructor public class OfficerMailServiceImpl implements OfficerMailService { - private final MailService mailService; + private final OfficerPasswordOperationOutService passwordOperationOutService; - private final OfficerLoginRepository loginRepository; - private final PasswordService passwordService; + private final MailService mailService; private final ParameterRepository parameterRepository; @@ -33,8 +31,8 @@ public class OfficerMailServiceImpl implements OfficerMailService { private static final String OFFICER_NAME = "officerName"; private static final String OFFICER_NUMBER = "officerNumber"; - private static final String PASSWORD = "password"; private static final String DATE = "date"; + private static final String CHANGE_PASSWORD_URL = "changePasswordUrl"; @PostConstruct void before() { @@ -52,37 +50,47 @@ void before() { } @Override - public void sendFirstPasswordEmail(final OfficerInfoDetailResponse infoDetailResponse) { - Map values = new HashMap<>(); - values.put(OFFICER_NAME, getOfficerName(infoDetailResponse)); - values.put(OFFICER_NUMBER, getOfficerNumber(infoDetailResponse)); - values.put(PASSWORD, getFirstPassword(infoDetailResponse)); - values.put(DATE, SisUtil.getCurrentFormattedDateTime()); + public void sendSavedEmail(final OfficerInfoDetailResponse infoDetailResponse) { + final String personalEmail = infoDetailResponse.getPersonalInfoResponse().getEmail(); + + Map values = getMailValues(infoDetailResponse); mailEntity.setTitle("Personel Hesabınız Başarıyla Oluşturuldu!"); mailEntity.setTemplate(parameterRepository.getOfficerParameterByName("MAIL_TEMPLATE_FIRST_PASSWORD")); - mailEntity.setTo(getOfficerPersonalEmail(infoDetailResponse)); + mailEntity.setTo(personalEmail); mailEntity.setValues(values); mailService.sendMail(mailEntity); - log.info("First Password Email Successfully Sent to " + mailEntity.getTo()); + log.info("Officer First Password Email Successfully Sent to " + mailEntity.getTo()); } @Override public void sendForgotPasswordEmail(final OfficerInfoDetailResponse infoDetailResponse) { - Map values = new HashMap<>(); - values.put(OFFICER_NAME, getOfficerName(infoDetailResponse)); - values.put(OFFICER_NUMBER, getOfficerNumber(infoDetailResponse)); - values.put(PASSWORD, getChangedPassword(infoDetailResponse)); - values.put(DATE, SisUtil.getCurrentFormattedDateTime()); + final String personalEmail = infoDetailResponse.getPersonalInfoResponse().getEmail(); - mailEntity.setTitle("Şifreniz Başarıyla Değiştirildi!"); + Map values = getMailValues(infoDetailResponse); + + mailEntity.setTitle("Şifre Değiştirme İsteğiniz İle İlgili!"); mailEntity.setTemplate(parameterRepository.getOfficerParameterByName("MAIL_TEMPLATE_FORGOT_PASSWORD")); - mailEntity.setTo(getOfficerPersonalEmail(infoDetailResponse)); + mailEntity.setTo(personalEmail); mailEntity.setValues(values); mailService.sendMail(mailEntity); - log.info("Forgot Password Email Successfully Sent to " + mailEntity.getTo()); + log.info("Officer Forgot Password Email Successfully Sent to " + mailEntity.getTo()); + } + + + private Map getMailValues(final OfficerInfoDetailResponse infoDetailResponse) { + final Long officerId = infoDetailResponse.getAcademicInfoResponse().getOfficerId(); + final String name = infoDetailResponse.getPersonalInfoResponse().getName(); + final String surname = infoDetailResponse.getPersonalInfoResponse().getSurname(); + + Map values = new HashMap<>(); + values.put(OFFICER_NAME, getOfficerFullName(name, surname)); + values.put(OFFICER_NUMBER, getOfficerNumber(officerId)); + values.put(DATE, SisUtil.getCurrentFormattedDateTime()); + values.put(CHANGE_PASSWORD_URL, getChangePasswordUrl(officerId)); + return values; } private Properties getProperties() { @@ -94,32 +102,16 @@ private Properties getProperties() { return properties; } - private String getOfficerName(final OfficerInfoDetailResponse infoDetailResponse) { - final String name = infoDetailResponse.getPersonalInfoResponse().getName(); - final String surname = infoDetailResponse.getPersonalInfoResponse().getSurname(); + private String getOfficerFullName(final String name, final String surname) { return name + " " + surname; } - private String getOfficerNumber(final OfficerInfoDetailResponse infoDetailResponse) { - return String.valueOf(infoDetailResponse.getAcademicInfoResponse().getOfficerId()); + private String getOfficerNumber(final Long officerId) { + return String.valueOf(officerId); } - private String getOfficerPersonalEmail(final OfficerInfoDetailResponse infoDetailResponse) { - return infoDetailResponse.getPersonalInfoResponse().getEmail(); - } - - - protected String getFirstPassword(final OfficerInfoDetailResponse infoDetailResponse) { - final Long officerId = infoDetailResponse.getAcademicInfoResponse().getOfficerId(); - final String password = passwordService.generatePassword(); - loginRepository.saveFirstPassword(officerId, password); - return password; - } - protected String getChangedPassword(final OfficerInfoDetailResponse infoDetailResponse) { - final Long officerId = infoDetailResponse.getAcademicInfoResponse().getOfficerId(); - final String password = passwordService.generatePassword(); - loginRepository.updatePassword(officerId, password); - return password; + protected String getChangePasswordUrl(final Long officerId) { + return passwordOperationOutService.getPasswordChangeUrl(officerId); } } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/mail/service/impl/StudentMailServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/mail/service/impl/StudentMailServiceImpl.java index fd1c0c2c..1b27d596 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/mail/service/impl/StudentMailServiceImpl.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/mail/service/impl/StudentMailServiceImpl.java @@ -1,8 +1,8 @@ package com.graduationproject.studentinformationsystem.university.mail.service.impl; import com.graduationproject.studentinformationsystem.common.util.SisUtil; -import com.graduationproject.studentinformationsystem.login.common.service.PasswordService; -import com.graduationproject.studentinformationsystem.login.student.repository.StudentLoginRepository; +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.login.student.password.service.StudentPasswordOperationOutService; import com.graduationproject.studentinformationsystem.university.mail.model.entity.SisMailEntity; import com.graduationproject.studentinformationsystem.university.mail.service.MailService; import com.graduationproject.studentinformationsystem.university.mail.service.StudentMailService; @@ -22,10 +22,9 @@ @RequiredArgsConstructor public class StudentMailServiceImpl implements StudentMailService { - private final MailService mailService; + private final StudentPasswordOperationOutService passwordOperationOutService; - private final StudentLoginRepository loginRepository; - private final PasswordService passwordService; + private final MailService mailService; private final ParameterRepository parameterRepository; @@ -33,8 +32,8 @@ public class StudentMailServiceImpl implements StudentMailService { private static final String STUDENT_NAME = "studentName"; private static final String STUDENT_NUMBER = "studentNumber"; - private static final String PASSWORD = "password"; private static final String DATE = "date"; + private static final String CHANGE_PASSWORD_URL = "changePasswordUrl"; @PostConstruct void before() { @@ -52,40 +51,49 @@ void before() { } @Override - public void sendFirstPasswordEmail(final StudentInfoDetailResponse infoDetailResponse) { - Map values = new HashMap<>(); - values.put(STUDENT_NAME, getStudentName(infoDetailResponse)); - values.put(STUDENT_NUMBER, getStudentNumber(infoDetailResponse)); - values.put(PASSWORD, getFirstPassword(infoDetailResponse)); - values.put(DATE, SisUtil.getCurrentFormattedDateTime()); + public void sendSavedEmail(final StudentInfoDetailResponse infoDetailResponse) throws SisNotExistException { + final String personalEmail = infoDetailResponse.getPersonalInfoResponse().getEmail(); + + Map values = getMailValues(infoDetailResponse); mailEntity.setTitle("Öğrenci Hesabınız Başarıyla Oluşturuldu!"); mailEntity.setTemplate(parameterRepository.getStudentParameterByName("MAIL_TEMPLATE_FIRST_PASSWORD")); - mailEntity.setTo(getStudentPersonalEmail(infoDetailResponse)); + mailEntity.setTo(personalEmail); mailEntity.setValues(values); mailService.sendMail(mailEntity); - log.info("First Password Email Successfully Sent to " + mailEntity.getTo()); + log.info("Student Saved Email Successfully Sent to " + mailEntity.getTo()); } @Override - public void sendForgotPasswordEmail(final StudentInfoDetailResponse infoDetailResponse) { - Map values = new HashMap<>(); - values.put(STUDENT_NAME, getStudentName(infoDetailResponse)); - values.put(STUDENT_NUMBER, getStudentNumber(infoDetailResponse)); - values.put(PASSWORD, getChangedPassword(infoDetailResponse)); - values.put(DATE, SisUtil.getCurrentFormattedDateTime()); + public void sendForgotPasswordEmail(final StudentInfoDetailResponse infoDetailResponse) throws SisNotExistException { + final String personalEmail = infoDetailResponse.getPersonalInfoResponse().getEmail(); + + Map values = getMailValues(infoDetailResponse); - mailEntity.setTitle("Şifreniz Başarıyla Değiştirildi!"); + mailEntity.setTitle("Şifre Değiştirme İsteğiniz İle İlgili!"); mailEntity.setTemplate(parameterRepository.getStudentParameterByName("MAIL_TEMPLATE_FORGOT_PASSWORD")); - mailEntity.setTo(getStudentPersonalEmail(infoDetailResponse)); + mailEntity.setTo(personalEmail); mailEntity.setValues(values); mailService.sendMail(mailEntity); - log.info("Forgot Password Email Successfully Sent to " + mailEntity.getTo()); + log.info("Student Forgot Password Email Successfully Sent to " + mailEntity.getTo()); } + private Map getMailValues(final StudentInfoDetailResponse infoDetailResponse) throws SisNotExistException { + final Long studentId = infoDetailResponse.getAcademicInfoResponse().getStudentId(); + final String name = infoDetailResponse.getPersonalInfoResponse().getName(); + final String surname = infoDetailResponse.getPersonalInfoResponse().getSurname(); + + Map values = new HashMap<>(); + values.put(STUDENT_NAME, getStudentFullName(name, surname)); + values.put(STUDENT_NUMBER, getStudentNumber(studentId)); + values.put(DATE, SisUtil.getCurrentFormattedDateTime()); + values.put(CHANGE_PASSWORD_URL, getChangePasswordUrl(studentId)); + return values; + } + private Properties getProperties() { Properties properties = new Properties(); properties.put("mail.smtp.host", parameterRepository.getStudentParameterByName("MAIL_SMTP_HOST")); @@ -95,32 +103,16 @@ private Properties getProperties() { return properties; } - private String getStudentName(final StudentInfoDetailResponse infoDetailResponse) { - final String name = infoDetailResponse.getPersonalInfoResponse().getName(); - final String surname = infoDetailResponse.getPersonalInfoResponse().getSurname(); + private String getStudentFullName(final String name, final String surname) { return name + " " + surname; } - private String getStudentNumber(final StudentInfoDetailResponse infoDetailResponse) { - return String.valueOf(infoDetailResponse.getAcademicInfoResponse().getStudentId()); + private String getStudentNumber(final Long studentId) { + return String.valueOf(studentId); } - private String getStudentPersonalEmail(final StudentInfoDetailResponse infoDetailResponse) { - return infoDetailResponse.getPersonalInfoResponse().getEmail(); - } - - - protected String getFirstPassword(final StudentInfoDetailResponse infoDetailResponse) { - final Long studentId = infoDetailResponse.getAcademicInfoResponse().getStudentId(); - final String password = passwordService.generatePassword(); - loginRepository.saveFirstPassword(studentId, password); - return password; - } - protected String getChangedPassword(final StudentInfoDetailResponse infoDetailResponse) { - final Long studentId = infoDetailResponse.getAcademicInfoResponse().getStudentId(); - final String password = passwordService.generatePassword(); - loginRepository.updatePassword(studentId, password); - return password; + protected String getChangePasswordUrl(final Long studentId) { + return passwordOperationOutService.getPasswordChangeUrl(studentId); } } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/mail/service/impl/TeacherMailServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/mail/service/impl/TeacherMailServiceImpl.java index e6fc5f58..7c834bae 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/mail/service/impl/TeacherMailServiceImpl.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/mail/service/impl/TeacherMailServiceImpl.java @@ -1,8 +1,8 @@ package com.graduationproject.studentinformationsystem.university.mail.service.impl; import com.graduationproject.studentinformationsystem.common.util.SisUtil; -import com.graduationproject.studentinformationsystem.login.common.service.PasswordService; -import com.graduationproject.studentinformationsystem.login.teacher.repository.TeacherLoginRepository; +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.login.teacher.password.service.TeacherPasswordOperationOutService; import com.graduationproject.studentinformationsystem.university.mail.model.entity.SisMailEntity; import com.graduationproject.studentinformationsystem.university.mail.service.MailService; import com.graduationproject.studentinformationsystem.university.mail.service.TeacherMailService; @@ -22,10 +22,9 @@ @RequiredArgsConstructor public class TeacherMailServiceImpl implements TeacherMailService { - private final MailService mailService; + private final TeacherPasswordOperationOutService passwordOperationOutService; - private final TeacherLoginRepository loginRepository; - private final PasswordService passwordService; + private final MailService mailService; private final ParameterRepository parameterRepository; @@ -33,8 +32,8 @@ public class TeacherMailServiceImpl implements TeacherMailService { private static final String TEACHER_NAME = "teacherName"; private static final String TEACHER_NUMBER = "teacherNumber"; - private static final String PASSWORD = "password"; private static final String DATE = "date"; + private static final String CHANGE_PASSWORD_URL = "changePasswordUrl"; @PostConstruct void before() { @@ -52,37 +51,47 @@ void before() { } @Override - public void sendFirstPasswordEmail(final TeacherInfoDetailResponse infoDetailResponse) { - Map values = new HashMap<>(); - values.put(TEACHER_NAME, getTeacherName(infoDetailResponse)); - values.put(TEACHER_NUMBER, getTeacherNumber(infoDetailResponse)); - values.put(PASSWORD, getFirstPassword(infoDetailResponse)); - values.put(DATE, SisUtil.getCurrentFormattedDateTime()); + public void sendSavedEmail(final TeacherInfoDetailResponse infoDetailResponse) throws SisNotExistException { + final String personalEmail = infoDetailResponse.getPersonalInfoResponse().getEmail(); + + Map values = getMailValues(infoDetailResponse); mailEntity.setTitle("Öğretmen Hesabınız Başarıyla Oluşturuldu!"); mailEntity.setTemplate(parameterRepository.getTeacherParameterByName("MAIL_TEMPLATE_FIRST_PASSWORD")); - mailEntity.setTo(getTeacherPersonalEmail(infoDetailResponse)); + mailEntity.setTo(personalEmail); mailEntity.setValues(values); mailService.sendMail(mailEntity); - log.info("First Password Email Successfully Sent to " + mailEntity.getTo()); + log.info("Teacher Saved Email Successfully Sent to " + mailEntity.getTo()); } @Override - public void sendForgotPasswordEmail(final TeacherInfoDetailResponse infoDetailResponse) { - Map values = new HashMap<>(); - values.put(TEACHER_NAME, getTeacherName(infoDetailResponse)); - values.put(TEACHER_NUMBER, getTeacherNumber(infoDetailResponse)); - values.put(PASSWORD, getChangedPassword(infoDetailResponse)); - values.put(DATE, SisUtil.getCurrentFormattedDateTime()); + public void sendForgotPasswordEmail(final TeacherInfoDetailResponse infoDetailResponse) throws SisNotExistException { + final String personalEmail = infoDetailResponse.getPersonalInfoResponse().getEmail(); - mailEntity.setTitle("Şifreniz Başarıyla Değiştirildi!"); + Map values = getMailValues(infoDetailResponse); + + mailEntity.setTitle("Şifre Değiştirme İsteğiniz İle İlgili!"); mailEntity.setTemplate(parameterRepository.getTeacherParameterByName("MAIL_TEMPLATE_FORGOT_PASSWORD")); - mailEntity.setTo(getTeacherPersonalEmail(infoDetailResponse)); + mailEntity.setTo(personalEmail); mailEntity.setValues(values); mailService.sendMail(mailEntity); - log.info("Forgot Password Email Successfully Sent to " + mailEntity.getTo()); + log.info("Teacher Forgot Password Email Successfully Sent to " + mailEntity.getTo()); + } + + + private Map getMailValues(final TeacherInfoDetailResponse infoDetailResponse) { + final Long teacherId = infoDetailResponse.getAcademicInfoResponse().getTeacherId(); + final String name = infoDetailResponse.getPersonalInfoResponse().getName(); + final String surname = infoDetailResponse.getPersonalInfoResponse().getSurname(); + + Map values = new HashMap<>(); + values.put(TEACHER_NAME, getTeacherFullName(name, surname)); + values.put(TEACHER_NUMBER, getTeacherNumber(teacherId)); + values.put(DATE, SisUtil.getCurrentFormattedDateTime()); + values.put(CHANGE_PASSWORD_URL, getChangePasswordUrl(teacherId)); + return values; } private Properties getProperties() { @@ -94,32 +103,16 @@ private Properties getProperties() { return properties; } - private String getTeacherName(final TeacherInfoDetailResponse infoDetailResponse) { - final String name = infoDetailResponse.getPersonalInfoResponse().getName(); - final String surname = infoDetailResponse.getPersonalInfoResponse().getSurname(); + private String getTeacherFullName(final String name, final String surname) { return name + " " + surname; } - private String getTeacherNumber(final TeacherInfoDetailResponse infoDetailResponse) { - return String.valueOf(infoDetailResponse.getAcademicInfoResponse().getTeacherId()); + private String getTeacherNumber(final Long teacherId) { + return String.valueOf(teacherId); } - private String getTeacherPersonalEmail(final TeacherInfoDetailResponse infoDetailResponse) { - return infoDetailResponse.getPersonalInfoResponse().getEmail(); - } - - - protected String getFirstPassword(final TeacherInfoDetailResponse infoDetailResponse) { - final Long teacherId = infoDetailResponse.getAcademicInfoResponse().getTeacherId(); - final String password = passwordService.generatePassword(); - loginRepository.saveFirstPassword(teacherId, password); - return password; - } - protected String getChangedPassword(final TeacherInfoDetailResponse infoDetailResponse) { - final Long teacherId = infoDetailResponse.getAcademicInfoResponse().getTeacherId(); - final String password = passwordService.generatePassword(); - loginRepository.updatePassword(teacherId, password); - return password; + protected String getChangePasswordUrl(final Long teacherId) { + return passwordOperationOutService.getPasswordChangeUrl(teacherId); } } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/officer/controller/OfficerController.java b/src/main/java/com/graduationproject/studentinformationsystem/university/officer/controller/OfficerController.java index 2449e455..0863e983 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/officer/controller/OfficerController.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/officer/controller/OfficerController.java @@ -54,7 +54,7 @@ public ResponseEntity> getOfficerD @PostMapping(OfficerControllerEndpoint.SAVE) @ApiOperation(value = "Save Officer") public ResponseEntity> saveOfficer( - @Valid @RequestBody final OfficerSaveRequest saveRequest) { + @Valid @RequestBody final OfficerSaveRequest saveRequest) throws SisNotExistException { final OfficerInfoDetailResponse infoDetailResponse = officerService.saveOfficer(saveRequest); return successResponse(infoDetailResponse); diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/officer/service/OfficerOutService.java b/src/main/java/com/graduationproject/studentinformationsystem/university/officer/service/OfficerOutService.java new file mode 100644 index 00000000..d630b4b6 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/officer/service/OfficerOutService.java @@ -0,0 +1,14 @@ +package com.graduationproject.studentinformationsystem.university.officer.service; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.university.officer.model.dto.response.OfficerInfoDetailResponse; +import com.graduationproject.studentinformationsystem.university.officer.model.dto.response.OfficerInfoResponse; + +public interface OfficerOutService { + + OfficerInfoDetailResponse getOfficerInfoDetailResponse(Long officerId) throws SisNotExistException; + + OfficerInfoResponse getOfficerInfoResponse(Long officerId); + + void ifOfficerIsNotExistThrowNotExistException(Long officerId) throws SisNotExistException; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/officer/service/OfficerService.java b/src/main/java/com/graduationproject/studentinformationsystem/university/officer/service/OfficerService.java index 7c6cf89a..019af9ef 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/officer/service/OfficerService.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/officer/service/OfficerService.java @@ -18,7 +18,7 @@ public interface OfficerService { OfficerInfoDetailResponse getOfficerDetailById(Long officerId) throws SisNotExistException; - OfficerInfoDetailResponse saveOfficer(OfficerSaveRequest studentInfoRequest); + OfficerInfoDetailResponse saveOfficer(OfficerSaveRequest studentInfoRequest) throws SisNotExistException; OfficerAcademicInfoResponse updateOfficerAcademicInfo(Long officerId, OfficerAcademicInfoUpdateRequest academicInfoUpdateRequest) diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/officer/service/impl/OfficerOutServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/officer/service/impl/OfficerOutServiceImpl.java new file mode 100644 index 00000000..9d9291ad --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/officer/service/impl/OfficerOutServiceImpl.java @@ -0,0 +1,44 @@ +package com.graduationproject.studentinformationsystem.university.officer.service.impl; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.university.officer.model.dto.converter.OfficerInfoResponseConverter; +import com.graduationproject.studentinformationsystem.university.officer.model.dto.converter.OfficerResponseConverter; +import com.graduationproject.studentinformationsystem.university.officer.model.dto.response.OfficerAcademicInfoResponse; +import com.graduationproject.studentinformationsystem.university.officer.model.dto.response.OfficerInfoDetailResponse; +import com.graduationproject.studentinformationsystem.university.officer.model.dto.response.OfficerInfoResponse; +import com.graduationproject.studentinformationsystem.university.officer.model.dto.response.OfficerPersonalInfoResponse; +import com.graduationproject.studentinformationsystem.university.officer.model.exception.OfficerException; +import com.graduationproject.studentinformationsystem.university.officer.service.OfficerAcademicInfoService; +import com.graduationproject.studentinformationsystem.university.officer.service.OfficerOutService; +import com.graduationproject.studentinformationsystem.university.officer.service.OfficerPersonalInfoService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class OfficerOutServiceImpl implements OfficerOutService { + + private final OfficerAcademicInfoService academicInfoService; + private final OfficerPersonalInfoService personalInfoService; + + @Override + public OfficerInfoDetailResponse getOfficerInfoDetailResponse(final Long officerId) { + final OfficerAcademicInfoResponse academicInfoResponse = academicInfoService.getOfficerAcademicInfoById(officerId); + final OfficerPersonalInfoResponse personalInfoResponse = personalInfoService.getOfficerPersonalInfoById(officerId); + return OfficerInfoResponseConverter.convert(academicInfoResponse, personalInfoResponse); + } + + @Override + public OfficerInfoResponse getOfficerInfoResponse(Long officerId) { + final OfficerAcademicInfoResponse academicInfoResponse = academicInfoService.getOfficerAcademicInfoById(officerId); + final OfficerPersonalInfoResponse personalInfoResponse = personalInfoService.getOfficerPersonalInfoById(officerId); + return OfficerResponseConverter.infoResponsesToResponse(academicInfoResponse, personalInfoResponse); + } + + @Override + public void ifOfficerIsNotExistThrowNotExistException(Long officerId) throws SisNotExistException { + if (!academicInfoService.isOfficerExist(officerId)) { + OfficerException.throwNotExistException(officerId); + } + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/officer/service/impl/OfficerServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/officer/service/impl/OfficerServiceImpl.java index cea66175..61cdd67e 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/officer/service/impl/OfficerServiceImpl.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/officer/service/impl/OfficerServiceImpl.java @@ -3,6 +3,7 @@ import com.graduationproject.studentinformationsystem.common.model.dto.request.SisOperationInfoRequest; import com.graduationproject.studentinformationsystem.common.util.exception.SisAlreadyException; import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.login.officer.password.service.OfficerPasswordOperationOutService; import com.graduationproject.studentinformationsystem.university.mail.service.OfficerMailService; import com.graduationproject.studentinformationsystem.university.officer.model.dto.converter.OfficerInfoResponseConverter; import com.graduationproject.studentinformationsystem.university.officer.model.dto.converter.OfficerResponseConverter; @@ -26,6 +27,8 @@ @RequiredArgsConstructor public class OfficerServiceImpl implements OfficerService { + private final OfficerPasswordOperationOutService passwordOperationOutService; + private final OfficerAcademicInfoService academicInfoService; private final OfficerPersonalInfoService personalInfoService; private final OfficerMailService officerMailService; @@ -44,7 +47,7 @@ public OfficerInfoDetailResponse getOfficerDetailById(final Long officerId) thro } @Override - public OfficerInfoDetailResponse saveOfficer(final OfficerSaveRequest saveRequest) { + public OfficerInfoDetailResponse saveOfficer(final OfficerSaveRequest saveRequest) throws SisNotExistException { checkBeforeSaving(saveRequest); final Long officerId = generateOfficerId(saveRequest.getAcademicInfoRequest().getFacultyId()); @@ -57,7 +60,9 @@ public OfficerInfoDetailResponse saveOfficer(final OfficerSaveRequest saveReques personalInfoService.saveOfficerPersonalInfo(officerId, personalInfoRequest, operationInfoRequest); final OfficerInfoDetailResponse infoDetailResponse = getOfficerInfoResponse(officerId); - officerMailService.sendFirstPasswordEmail(infoDetailResponse); + + passwordOperationOutService.saveOrUpdatePasswordOperation(officerId, saveRequest.getOperationInfoRequest().getFeUrl()); + officerMailService.sendSavedEmail(infoDetailResponse); return infoDetailResponse; } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/student/service/StudentOutService.java b/src/main/java/com/graduationproject/studentinformationsystem/university/student/service/StudentOutService.java index f095e447..2e6048fb 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/student/service/StudentOutService.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/student/service/StudentOutService.java @@ -1,10 +1,13 @@ package com.graduationproject.studentinformationsystem.university.student.service; import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.university.student.model.dto.response.StudentInfoDetailResponse; import com.graduationproject.studentinformationsystem.university.student.model.dto.response.StudentInfoResponse; public interface StudentOutService { + StudentInfoDetailResponse getStudentInfoDetailResponse(Long studentId) throws SisNotExistException; + StudentInfoResponse getStudentInfoResponse(Long studentId); void ifStudentIsNotExistThrowNotExistException(Long studentId) throws SisNotExistException; diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/student/service/impl/StudentOutServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/student/service/impl/StudentOutServiceImpl.java index 90c3e771..d2a9e533 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/student/service/impl/StudentOutServiceImpl.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/student/service/impl/StudentOutServiceImpl.java @@ -1,8 +1,10 @@ package com.graduationproject.studentinformationsystem.university.student.service.impl; import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.university.student.model.dto.converter.StudentInfoResponseConverter; import com.graduationproject.studentinformationsystem.university.student.model.dto.converter.StudentResponseConverter; import com.graduationproject.studentinformationsystem.university.student.model.dto.response.StudentAcademicInfoResponse; +import com.graduationproject.studentinformationsystem.university.student.model.dto.response.StudentInfoDetailResponse; import com.graduationproject.studentinformationsystem.university.student.model.dto.response.StudentInfoResponse; import com.graduationproject.studentinformationsystem.university.student.model.dto.response.StudentPersonalInfoResponse; import com.graduationproject.studentinformationsystem.university.student.model.exception.StudentException; @@ -19,6 +21,13 @@ public class StudentOutServiceImpl implements StudentOutService { private final StudentAcademicInfoService academicInfoService; private final StudentPersonalInfoService personalInfoService; + @Override + public StudentInfoDetailResponse getStudentInfoDetailResponse(final Long studentId) { + final StudentAcademicInfoResponse academicInfoResponse = academicInfoService.getStudentAcademicInfoById(studentId); + final StudentPersonalInfoResponse personalInfoResponse = personalInfoService.getStudentPersonalInfoById(studentId); + return StudentInfoResponseConverter.convert(academicInfoResponse, personalInfoResponse); + } + @Override public StudentInfoResponse getStudentInfoResponse(final Long studentId) { final StudentAcademicInfoResponse academicInfoResponse = academicInfoService.getStudentAcademicInfoById(studentId); diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/student/service/impl/StudentServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/student/service/impl/StudentServiceImpl.java index 225bfa9e..9557dcbe 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/student/service/impl/StudentServiceImpl.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/student/service/impl/StudentServiceImpl.java @@ -3,6 +3,7 @@ import com.graduationproject.studentinformationsystem.common.model.dto.request.SisOperationInfoRequest; import com.graduationproject.studentinformationsystem.common.util.exception.SisAlreadyException; import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.login.student.password.service.StudentPasswordOperationOutService; import com.graduationproject.studentinformationsystem.university.department.service.DepartmentOutService; import com.graduationproject.studentinformationsystem.university.mail.service.StudentMailService; import com.graduationproject.studentinformationsystem.university.student.model.dto.converter.StudentInfoResponseConverter; @@ -28,6 +29,7 @@ public class StudentServiceImpl implements StudentService { private final DepartmentOutService departmentOutService; + private final StudentPasswordOperationOutService passwordOperationOutService; private final StudentAcademicInfoService academicInfoService; private final StudentPersonalInfoService personalInfoService; @@ -43,7 +45,7 @@ public List getAllStudentsByStatus(final StudentStatus stat @Override public StudentInfoDetailResponse getStudentDetailById(final Long studentId) throws SisNotExistException { ifStudentIsNotExistThrowNotExistException(studentId); - return getStudentInfoResponse(studentId); + return getStudentInfoDetailResponse(studentId); } @Override @@ -59,8 +61,10 @@ public StudentInfoDetailResponse saveStudent(final StudentSaveRequest saveReques academicInfoService.saveStudentAcademicInfo(studentId, studentEmail, academicInfoRequest, operationInfoRequest); personalInfoService.saveStudentPersonalInfo(studentId, personalInfoRequest, operationInfoRequest); - final StudentInfoDetailResponse studentInfoDetailResponse = getStudentInfoResponse(studentId); - mailService.sendFirstPasswordEmail(studentInfoDetailResponse); + final StudentInfoDetailResponse studentInfoDetailResponse = getStudentInfoDetailResponse(studentId); + + passwordOperationOutService.saveOrUpdatePasswordOperation(studentId, saveRequest.getOperationInfoRequest().getFeUrl()); + mailService.sendSavedEmail(studentInfoDetailResponse); return studentInfoDetailResponse; } @@ -89,7 +93,7 @@ public StudentInfoResponse deleteStudent(final StudentDeleteRequest deleteReques checkBeforeDeleting(deleteRequest.getStudentId()); academicInfoService.deleteStudentAcademicInfo(deleteRequest); personalInfoService.deleteStudentPersonalInfo(deleteRequest); - return getStudentResponse(deleteRequest.getStudentId()); + return getStudentInfoResponse(deleteRequest.getStudentId()); } @Override @@ -99,7 +103,7 @@ public StudentInfoResponse passivateStudent(final StudentPassivateRequest passiv checkBeforePassivating(passivateRequest.getStudentId()); academicInfoService.passivateStudentAcademicInfo(passivateRequest); personalInfoService.passivateStudentPersonalInfo(passivateRequest); - return getStudentResponse(passivateRequest.getStudentId()); + return getStudentInfoResponse(passivateRequest.getStudentId()); } @Override @@ -109,7 +113,7 @@ public StudentInfoResponse activateStudent(final StudentActivateRequest activate checkBeforeActivating(activateRequest.getStudentId()); academicInfoService.activateStudentAcademicInfo(activateRequest); personalInfoService.activateStudentPersonalInfo(activateRequest); - return getStudentResponse(activateRequest.getStudentId()); + return getStudentInfoResponse(activateRequest.getStudentId()); } @Override @@ -119,7 +123,7 @@ public StudentInfoResponse graduateStudent(final StudentGraduateRequest graduate checkBeforeGraduating(graduateRequest.getStudentId()); academicInfoService.graduateStudentAcademicInfo(graduateRequest); personalInfoService.graduateStudentPersonalInfo(graduateRequest); - return getStudentResponse(graduateRequest.getStudentId()); + return getStudentInfoResponse(graduateRequest.getStudentId()); } @@ -134,13 +138,13 @@ private String generateStudentEmail(final StudentSaveRequest studentInfoRequest) return StudentUtil.generateStudentEmail(name, surname); } - private StudentInfoDetailResponse getStudentInfoResponse(final Long studentId) { + private StudentInfoDetailResponse getStudentInfoDetailResponse(final Long studentId) { final StudentAcademicInfoResponse academicInfoResponse = academicInfoService.getStudentAcademicInfoById(studentId); final StudentPersonalInfoResponse personalInfoResponse = personalInfoService.getStudentPersonalInfoById(studentId); return StudentInfoResponseConverter.convert(academicInfoResponse, personalInfoResponse); } - private StudentInfoResponse getStudentResponse(final Long studentId) { + private StudentInfoResponse getStudentInfoResponse(final Long studentId) { final StudentAcademicInfoResponse academicInfoResponse = academicInfoService.getStudentAcademicInfoById(studentId); final StudentPersonalInfoResponse personalInfoResponse = personalInfoService.getStudentPersonalInfoById(studentId); return StudentResponseConverter.infoResponsesToResponse(academicInfoResponse, personalInfoResponse); diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/controller/TeacherController.java b/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/controller/TeacherController.java index 8f1acf6b..6352e990 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/controller/TeacherController.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/controller/TeacherController.java @@ -54,7 +54,7 @@ public ResponseEntity> getTeacherD @PostMapping(TeacherControllerEndpoint.SAVE) @ApiOperation(value = "Save Teacher") public ResponseEntity> saveTeacher( - @Valid @RequestBody final TeacherSaveRequest saveRequest) { + @Valid @RequestBody final TeacherSaveRequest saveRequest) throws SisNotExistException { final TeacherInfoDetailResponse infoDetailResponse = teacherService.saveTeacher(saveRequest); return successResponse(infoDetailResponse); diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/model/dto/converter/TeacherInfoResponseConverter.java b/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/model/dto/converter/TeacherInfoResponseConverter.java index 25f834ba..c8640caf 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/model/dto/converter/TeacherInfoResponseConverter.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/model/dto/converter/TeacherInfoResponseConverter.java @@ -9,8 +9,8 @@ public class TeacherInfoResponseConverter { private TeacherInfoResponseConverter() { } - public static TeacherInfoDetailResponse convert(TeacherAcademicInfoResponse academicInfoResponse, - TeacherPersonalInfoResponse personalInfoResponse) { + public static TeacherInfoDetailResponse convert(final TeacherAcademicInfoResponse academicInfoResponse, + final TeacherPersonalInfoResponse personalInfoResponse) { return TeacherInfoDetailResponse.builder() .academicInfoResponse(academicInfoResponse) diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/TeacherOutService.java b/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/TeacherOutService.java index 39b9fa86..969a3195 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/TeacherOutService.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/TeacherOutService.java @@ -1,8 +1,14 @@ package com.graduationproject.studentinformationsystem.university.teacher.service; +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.university.teacher.model.dto.response.TeacherInfoDetailResponse; import com.graduationproject.studentinformationsystem.university.teacher.model.dto.response.TeacherInfoResponse; public interface TeacherOutService { + TeacherInfoDetailResponse getTeacherInfoDetailResponse(Long teacherId) throws SisNotExistException; + TeacherInfoResponse getTeacherInfoResponse(Long teacherId); + + void ifTeacherIsNotExistThrowNotExistException(Long teacherId) throws SisNotExistException; } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/TeacherService.java b/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/TeacherService.java index f760d21c..787a33ad 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/TeacherService.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/TeacherService.java @@ -18,7 +18,7 @@ public interface TeacherService { TeacherInfoDetailResponse getTeacherDetailById(Long teacherId) throws SisNotExistException; - TeacherInfoDetailResponse saveTeacher(TeacherSaveRequest studentInfoRequest); + TeacherInfoDetailResponse saveTeacher(TeacherSaveRequest studentInfoRequest) throws SisNotExistException; TeacherAcademicInfoResponse updateTeacherAcademicInfo(Long teacherId, TeacherAcademicInfoUpdateRequest academicInfoUpdateRequest) diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/impl/TeacherOutServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/impl/TeacherOutServiceImpl.java index eda7bb41..fca137d3 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/impl/TeacherOutServiceImpl.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/impl/TeacherOutServiceImpl.java @@ -1,9 +1,13 @@ package com.graduationproject.studentinformationsystem.university.teacher.service.impl; +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.university.teacher.model.dto.converter.TeacherInfoResponseConverter; import com.graduationproject.studentinformationsystem.university.teacher.model.dto.converter.TeacherResponseConverter; import com.graduationproject.studentinformationsystem.university.teacher.model.dto.response.TeacherAcademicInfoResponse; +import com.graduationproject.studentinformationsystem.university.teacher.model.dto.response.TeacherInfoDetailResponse; import com.graduationproject.studentinformationsystem.university.teacher.model.dto.response.TeacherInfoResponse; import com.graduationproject.studentinformationsystem.university.teacher.model.dto.response.TeacherPersonalInfoResponse; +import com.graduationproject.studentinformationsystem.university.teacher.model.exception.TeacherException; import com.graduationproject.studentinformationsystem.university.teacher.service.TeacherAcademicInfoService; import com.graduationproject.studentinformationsystem.university.teacher.service.TeacherOutService; import com.graduationproject.studentinformationsystem.university.teacher.service.TeacherPersonalInfoService; @@ -17,10 +21,24 @@ public class TeacherOutServiceImpl implements TeacherOutService { private final TeacherAcademicInfoService academicInfoService; private final TeacherPersonalInfoService personalInfoService; + @Override + public TeacherInfoDetailResponse getTeacherInfoDetailResponse(final Long teacherId) { + final TeacherAcademicInfoResponse academicInfoResponse = academicInfoService.getTeacherAcademicInfoById(teacherId); + final TeacherPersonalInfoResponse personalInfoResponse = personalInfoService.getTeacherPersonalInfoById(teacherId); + return TeacherInfoResponseConverter.convert(academicInfoResponse, personalInfoResponse); + } + @Override public TeacherInfoResponse getTeacherInfoResponse(Long teacherId) { final TeacherAcademicInfoResponse academicInfoResponse = academicInfoService.getTeacherAcademicInfoById(teacherId); final TeacherPersonalInfoResponse personalInfoResponse = personalInfoService.getTeacherPersonalInfoById(teacherId); return TeacherResponseConverter.infoResponsesToResponse(academicInfoResponse, personalInfoResponse); } + + @Override + public void ifTeacherIsNotExistThrowNotExistException(Long teacherId) throws SisNotExistException { + if (!academicInfoService.isTeacherExist(teacherId)) { + TeacherException.throwNotExistException(teacherId); + } + } } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/impl/TeacherServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/impl/TeacherServiceImpl.java index a29f309f..7e580bc9 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/impl/TeacherServiceImpl.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/teacher/service/impl/TeacherServiceImpl.java @@ -3,6 +3,7 @@ import com.graduationproject.studentinformationsystem.common.model.dto.request.SisOperationInfoRequest; import com.graduationproject.studentinformationsystem.common.util.exception.SisAlreadyException; import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.login.teacher.password.service.TeacherPasswordOperationOutService; import com.graduationproject.studentinformationsystem.university.mail.service.TeacherMailService; import com.graduationproject.studentinformationsystem.university.teacher.model.dto.converter.TeacherInfoResponseConverter; import com.graduationproject.studentinformationsystem.university.teacher.model.dto.converter.TeacherResponseConverter; @@ -26,6 +27,8 @@ @RequiredArgsConstructor public class TeacherServiceImpl implements TeacherService { + private final TeacherPasswordOperationOutService passwordOperationOutService; + private final TeacherAcademicInfoService academicInfoService; private final TeacherPersonalInfoService personalInfoService; private final TeacherMailService teacherMailService; @@ -44,7 +47,7 @@ public TeacherInfoDetailResponse getTeacherDetailById(final Long teacherId) thro } @Override - public TeacherInfoDetailResponse saveTeacher(final TeacherSaveRequest saveRequest) { + public TeacherInfoDetailResponse saveTeacher(final TeacherSaveRequest saveRequest) throws SisNotExistException { checkBeforeSaving(saveRequest); final Long teacherId = generateTeacherId(saveRequest.getAcademicInfoRequest().getDepartmentId()); @@ -57,7 +60,9 @@ public TeacherInfoDetailResponse saveTeacher(final TeacherSaveRequest saveReques personalInfoService.saveTeacherPersonalInfo(teacherId, personalInfoRequest, operationInfoRequest); final TeacherInfoDetailResponse infoDetailResponse = getTeacherInfoResponse(teacherId); - teacherMailService.sendFirstPasswordEmail(infoDetailResponse); + + passwordOperationOutService.saveOrUpdatePasswordOperation(teacherId, saveRequest.getOperationInfoRequest().getFeUrl()); + teacherMailService.sendSavedEmail(infoDetailResponse); return infoDetailResponse; } From 43136eb5d061e7d49a85af1b247a156f6c5b1291 Mon Sep 17 00:00:00 2001 From: Agit Rubar Demir <61833677+agitrubard@users.noreply.github.com> Date: Sun, 6 Mar 2022 12:47:08 +0300 Subject: [PATCH 10/13] Project Version Updated to 1.3.0 (#65) * Project Version Updated to 1.3.0 * Code Has Been Formatted --- pom.xml | 5 +++-- src/main/resources/application.yml | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index c0b87304..67f61285 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ com.graduation-project student-information-system-be - v1.2.0 + v1.3.0 war Student Information System Student Information System for Higher Education @@ -179,7 +179,8 @@ sis-be 17.0.1 - java -Dserver.port=$PORT -Dspring.profiles.active=mysql-live $JAVA_OPTS -jar target/*.war + + java -Dserver.port=$PORT -Dspring.profiles.active=mysql-live $JAVA_OPTS -jar target/*.war diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 54aee3a9..0ae6b3e6 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,6 +1,6 @@ sis: title: Student Information System API - version: v1.2.0 + version: v1.3.0 server: port: 8585 From 29ccf9698f0873b575d963881427265fa920fba9 Mon Sep 17 00:00:00 2001 From: Agit Rubar Demir <61833677+agitrubard@users.noreply.github.com> Date: Thu, 10 Mar 2022 20:37:16 +0300 Subject: [PATCH 11/13] Feature Toggle API | SIS-120 (#66) * FeatureToggleMapping Class Has Been Created * FeatureToggleName Class Has Been Created * FeatureToggleException Class Has Been Created * FeatureToggleEntity Class Has Been Created * Feature Toggle Response Classes Have Been Created * FeatureToggleRequest Class Has Been Created * FeatureToggleInfoConverter Class Has Been Created * FeatureToggle Repository Classes Have Been Created * FeatureToggle Service Classes Have Been Created * FEATURE_TOGGLE_API_TAG Has Been Added to SisSwaggerConfiguration Class * FEATURE_TOGGLE Endpoint Has Been Added to SisControllerEndpoint * FeatureToggle Controller Classes Have Been Created --- .../config/SisSwaggerConfiguration.java | 2 + .../endpoint/SisControllerEndpoint.java | 1 + .../controller/FeatureToggleController.java | 79 +++++++++++ .../FeatureToggleControllerEndpoint.java | 12 ++ .../converter/FeatureToggleInfoConverter.java | 43 ++++++ .../dto/request/FeatureToggleRequest.java | 23 ++++ .../FeatureToggleIsEnabledResponse.java | 11 ++ .../dto/response/FeatureToggleResponse.java | 18 +++ .../model/entity/FeatureToggleEntity.java | 18 +++ .../model/enums/FeatureToggleName.java | 14 ++ .../exception/FeatureToggleException.java | 15 ++ .../model/mapping/FeatureToggleMapping.java | 28 ++++ .../repository/FeatureToggleRepository.java | 21 +++ .../impl/FeatureToggleRepositoryImpl.java | 129 ++++++++++++++++++ .../impl/scripts/FeatureToggleSqlScripts.java | 74 ++++++++++ .../service/FeatureToggleService.java | 22 +++ .../impl/FeatureToggleServiceImpl.java | 94 +++++++++++++ 17 files changed, 604 insertions(+) create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/controller/FeatureToggleController.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/controller/endpoint/FeatureToggleControllerEndpoint.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/model/dto/converter/FeatureToggleInfoConverter.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/model/dto/request/FeatureToggleRequest.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/model/dto/response/FeatureToggleIsEnabledResponse.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/model/dto/response/FeatureToggleResponse.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/model/entity/FeatureToggleEntity.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/model/enums/FeatureToggleName.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/model/exception/FeatureToggleException.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/model/mapping/FeatureToggleMapping.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/repository/FeatureToggleRepository.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/repository/impl/FeatureToggleRepositoryImpl.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/repository/impl/scripts/FeatureToggleSqlScripts.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/service/FeatureToggleService.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/service/impl/FeatureToggleServiceImpl.java diff --git a/src/main/java/com/graduationproject/studentinformationsystem/common/config/SisSwaggerConfiguration.java b/src/main/java/com/graduationproject/studentinformationsystem/common/config/SisSwaggerConfiguration.java index 404c599e..b53ecc41 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/common/config/SisSwaggerConfiguration.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/common/config/SisSwaggerConfiguration.java @@ -24,6 +24,7 @@ public class SisSwaggerConfiguration { public static final String LESSON_API_TAG = "Lesson Controller"; public static final String EXAM_SCHEDULE_FILE_API_TAG = "Exam Schedule File Controller"; public static final String LESSON_SCHEDULE_FILE_API_TAG = "Lesson Schedule File Controller"; + public static final String FEATURE_TOGGLE_API_TAG = "Feature Toggle Controller"; public static final String STUDENT_API_TAG = "Student Controller"; public static final String STUDENT_LESSON_API_TAG = "Student Lesson Controller"; public static final String STUDENT_LESSON_REGISTRATION_API_TAG = "Student Lesson Registration Controller"; @@ -48,6 +49,7 @@ public Docket api() { new Tag(LESSON_API_TAG, "UNIV_LESSON"), new Tag(EXAM_SCHEDULE_FILE_API_TAG, "UNIV_EXAM_SCHEDULE_FILE"), new Tag(LESSON_SCHEDULE_FILE_API_TAG, "UNIV_LESSON_SCHEDULE_FILE"), + new Tag(FEATURE_TOGGLE_API_TAG, "UNIV_FEATURE_TOGGLE"), new Tag(STUDENT_API_TAG, "STUDENT_ACADEMIC_INFO & STUDENT_PERSONAL_INFO"), new Tag(STUDENT_LESSON_API_TAG, "STUDENT_LESSON"), new Tag(STUDENT_LESSON_REGISTRATION_API_TAG, "STUDENT_LESSON_REGISTRATION"), diff --git a/src/main/java/com/graduationproject/studentinformationsystem/common/util/controller/endpoint/SisControllerEndpoint.java b/src/main/java/com/graduationproject/studentinformationsystem/common/util/controller/endpoint/SisControllerEndpoint.java index 768c2205..2ccb7014 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/common/util/controller/endpoint/SisControllerEndpoint.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/common/util/controller/endpoint/SisControllerEndpoint.java @@ -17,6 +17,7 @@ private Path() { public static final String LESSON = "/lesson"; public static final String EXAM_SCHEDULE_FILE = "/exam-schedule-file"; public static final String LESSON_SCHEDULE_FILE = "/lesson-schedule-file"; + public static final String FEATURE_TOGGLE = "/feature-toggle"; public static final String STUDENT = "/student"; public static final String STUDENT_LESSON = STUDENT + LESSON; public static final String STUDENT_LESSON_REGISTRATION = STUDENT_LESSON + REGISTRATION; diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/controller/FeatureToggleController.java b/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/controller/FeatureToggleController.java new file mode 100644 index 00000000..e44b8ec4 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/controller/FeatureToggleController.java @@ -0,0 +1,79 @@ +package com.graduationproject.studentinformationsystem.university.featuretoggle.controller; + +import com.graduationproject.studentinformationsystem.common.util.controller.response.SisBaseApiResponse; +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.university.featuretoggle.controller.endpoint.FeatureToggleControllerEndpoint; +import com.graduationproject.studentinformationsystem.university.featuretoggle.model.dto.request.FeatureToggleRequest; +import com.graduationproject.studentinformationsystem.university.featuretoggle.model.dto.response.FeatureToggleIsEnabledResponse; +import com.graduationproject.studentinformationsystem.university.featuretoggle.model.dto.response.FeatureToggleResponse; +import com.graduationproject.studentinformationsystem.university.featuretoggle.model.enums.FeatureToggleName; +import com.graduationproject.studentinformationsystem.university.featuretoggle.service.FeatureToggleService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.util.List; + +import static com.graduationproject.studentinformationsystem.common.config.SisSwaggerConfiguration.FEATURE_TOGGLE_API_TAG; +import static com.graduationproject.studentinformationsystem.common.util.controller.endpoint.SisControllerEndpoint.Path.FEATURE_TOGGLE; +import static com.graduationproject.studentinformationsystem.common.util.controller.response.SisResponseUtil.successResponse; + +@RestController +@RequestMapping(FEATURE_TOGGLE) +@Api(tags = FEATURE_TOGGLE_API_TAG) +@RequiredArgsConstructor +public class FeatureToggleController { + + private final FeatureToggleService featureToggleService; + + @GetMapping + @ApiOperation(value = "Get All Feature Toggles") + public ResponseEntity>> getAllFeatureToggles() { + + final List featureToggleResponses = featureToggleService.getAllFeatureToggles(); + return successResponse(featureToggleResponses); + } + + @GetMapping(FeatureToggleControllerEndpoint.NAME) + @ApiOperation(value = "Get Feature Toggle By Name") + public ResponseEntity> getFeatureToggleByName( + @PathVariable final FeatureToggleName name) + throws SisNotExistException { + + final FeatureToggleResponse featureToggleResponse = featureToggleService.getFeatureToggleByName(name); + return successResponse(featureToggleResponse); + } + + @GetMapping(FeatureToggleControllerEndpoint.ENABLED_BY_NAME) + @ApiOperation(value = "Is Feature Toggle Enabled") + public ResponseEntity> isFeatureToggleEnabled( + @PathVariable final FeatureToggleName name) + throws SisNotExistException { + + final FeatureToggleIsEnabledResponse featureToggleIsEnabledResponse = featureToggleService.isFeatureToggleEnabled(name); + return successResponse(featureToggleIsEnabledResponse); + } + + @PatchMapping(FeatureToggleControllerEndpoint.ENABLE) + @ApiOperation(value = "Enable Feature Toggle") + public ResponseEntity> enableFeatureToggle( + @Valid @RequestBody final FeatureToggleRequest featureToggleRequest) + throws SisNotExistException { + + final FeatureToggleResponse featureToggleResponse = featureToggleService.enableFeatureToggle(featureToggleRequest); + return successResponse(featureToggleResponse); + } + + @PatchMapping(FeatureToggleControllerEndpoint.DISABLE) + @ApiOperation(value = "Disable Feature Toggle") + public ResponseEntity> disableFeatureToggle( + @Valid @RequestBody final FeatureToggleRequest featureToggleRequest) + throws SisNotExistException { + + final FeatureToggleResponse featureToggleResponse = featureToggleService.disableFeatureToggle(featureToggleRequest); + return successResponse(featureToggleResponse); + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/controller/endpoint/FeatureToggleControllerEndpoint.java b/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/controller/endpoint/FeatureToggleControllerEndpoint.java new file mode 100644 index 00000000..3a7bceac --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/controller/endpoint/FeatureToggleControllerEndpoint.java @@ -0,0 +1,12 @@ +package com.graduationproject.studentinformationsystem.university.featuretoggle.controller.endpoint; + +public class FeatureToggleControllerEndpoint { + + private FeatureToggleControllerEndpoint() { + } + + public static final String NAME = "/{name}"; + public static final String ENABLE = "/enable"; + public static final String DISABLE = "/disable"; + public static final String ENABLED_BY_NAME = "/enabled" + NAME; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/model/dto/converter/FeatureToggleInfoConverter.java b/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/model/dto/converter/FeatureToggleInfoConverter.java new file mode 100644 index 00000000..daace44e --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/model/dto/converter/FeatureToggleInfoConverter.java @@ -0,0 +1,43 @@ +package com.graduationproject.studentinformationsystem.university.featuretoggle.model.dto.converter; + +import com.graduationproject.studentinformationsystem.common.util.SisUtil; +import com.graduationproject.studentinformationsystem.university.featuretoggle.model.dto.request.FeatureToggleRequest; +import com.graduationproject.studentinformationsystem.university.featuretoggle.model.dto.response.FeatureToggleResponse; +import com.graduationproject.studentinformationsystem.university.featuretoggle.model.entity.FeatureToggleEntity; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +@Component +public class FeatureToggleInfoConverter { + + public FeatureToggleEntity generateEntity(final FeatureToggleRequest featureToggleRequest) { + + return FeatureToggleEntity.builder() + .name(featureToggleRequest.getName()) + .modifiedUserId(featureToggleRequest.getOperationInfoRequest().getUserId()) + .modifiedDate(new Date()) + .build(); + } + + public FeatureToggleResponse entityToResponse(final FeatureToggleEntity featureToggleEntity) { + return FeatureToggleResponse.builder() + .id(featureToggleEntity.getId()) + .name(featureToggleEntity.getName()) + .isEnabled(featureToggleEntity.getIsEnabled()) + .date(featureToggleEntity.getDate()) + .createdUserId(featureToggleEntity.getCreatedUserId()) + .createdDate(SisUtil.getFormattedDateTime(featureToggleEntity.getCreatedDate())) + .modifiedUserId(featureToggleEntity.getModifiedUserId()) + .modifiedDate(SisUtil.getFormattedDateTime(featureToggleEntity.getModifiedDate())) + .build(); + } + + public List entitiesToResponses(final List facultyEntities) { + List featureToggleResponses = new ArrayList<>(); + facultyEntities.forEach(facultyEntity -> featureToggleResponses.add(entityToResponse(facultyEntity))); + return featureToggleResponses; + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/model/dto/request/FeatureToggleRequest.java b/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/model/dto/request/FeatureToggleRequest.java new file mode 100644 index 00000000..97709c51 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/model/dto/request/FeatureToggleRequest.java @@ -0,0 +1,23 @@ +package com.graduationproject.studentinformationsystem.university.featuretoggle.model.dto.request; + +import com.graduationproject.studentinformationsystem.common.model.dto.request.SisOperationInfoRequest; +import com.graduationproject.studentinformationsystem.university.featuretoggle.model.enums.FeatureToggleName; +import lombok.Getter; + +import javax.validation.Valid; +import javax.validation.constraints.NotNull; +import java.io.Serial; +import java.io.Serializable; + +@Getter +public class FeatureToggleRequest implements Serializable { + + @Serial + private static final long serialVersionUID = -4460192886349312510L; + + @NotNull + private FeatureToggleName name; + + @Valid + private SisOperationInfoRequest operationInfoRequest; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/model/dto/response/FeatureToggleIsEnabledResponse.java b/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/model/dto/response/FeatureToggleIsEnabledResponse.java new file mode 100644 index 00000000..3c53e259 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/model/dto/response/FeatureToggleIsEnabledResponse.java @@ -0,0 +1,11 @@ +package com.graduationproject.studentinformationsystem.university.featuretoggle.model.dto.response; + +import lombok.Getter; +import lombok.experimental.SuperBuilder; + +@Getter +@SuperBuilder +public class FeatureToggleIsEnabledResponse { + + private Boolean isFeatureToggleEnabled; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/model/dto/response/FeatureToggleResponse.java b/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/model/dto/response/FeatureToggleResponse.java new file mode 100644 index 00000000..72fbbea1 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/model/dto/response/FeatureToggleResponse.java @@ -0,0 +1,18 @@ +package com.graduationproject.studentinformationsystem.university.featuretoggle.model.dto.response; + +import com.graduationproject.studentinformationsystem.common.model.dto.response.SisBaseResponse; +import com.graduationproject.studentinformationsystem.university.featuretoggle.model.enums.FeatureToggleName; +import lombok.Getter; +import lombok.experimental.SuperBuilder; + +import java.util.Date; + +@Getter +@SuperBuilder +public class FeatureToggleResponse extends SisBaseResponse { + + private Long id; + private FeatureToggleName name; + private Boolean isEnabled; + private Date date; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/model/entity/FeatureToggleEntity.java b/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/model/entity/FeatureToggleEntity.java new file mode 100644 index 00000000..17e6cc0d --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/model/entity/FeatureToggleEntity.java @@ -0,0 +1,18 @@ +package com.graduationproject.studentinformationsystem.university.featuretoggle.model.entity; + +import com.graduationproject.studentinformationsystem.common.model.entity.SisBaseEntity; +import com.graduationproject.studentinformationsystem.university.featuretoggle.model.enums.FeatureToggleName; +import lombok.Getter; +import lombok.experimental.SuperBuilder; + +import java.util.Date; + +@Getter +@SuperBuilder +public class FeatureToggleEntity extends SisBaseEntity { + + private Long id; + private FeatureToggleName name; + private Boolean isEnabled; + private Date date; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/model/enums/FeatureToggleName.java b/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/model/enums/FeatureToggleName.java new file mode 100644 index 00000000..96c62146 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/model/enums/FeatureToggleName.java @@ -0,0 +1,14 @@ +package com.graduationproject.studentinformationsystem.university.featuretoggle.model.enums; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum FeatureToggleName { + + LESSON_REGISTRATION_OPERATIONS("Ders Kayıt İşlemleri"), + NOTE_OPERATIONS("Not İşlemleri"); + + private final String tr; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/model/exception/FeatureToggleException.java b/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/model/exception/FeatureToggleException.java new file mode 100644 index 00000000..4e6f0eb6 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/model/exception/FeatureToggleException.java @@ -0,0 +1,15 @@ +package com.graduationproject.studentinformationsystem.university.featuretoggle.model.exception; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisException; +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.university.featuretoggle.model.enums.FeatureToggleName; + +public class FeatureToggleException extends SisException { + + private FeatureToggleException() { + } + + public static void throwNotExistException(final FeatureToggleName name) throws SisNotExistException { + SisException.throwNotExistException("FEATURE TOGGLE IS NOT EXIST! name:" + name); + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/model/mapping/FeatureToggleMapping.java b/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/model/mapping/FeatureToggleMapping.java new file mode 100644 index 00000000..4cee9de6 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/model/mapping/FeatureToggleMapping.java @@ -0,0 +1,28 @@ +package com.graduationproject.studentinformationsystem.university.featuretoggle.model.mapping; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +@Getter +@RequiredArgsConstructor +public enum FeatureToggleMapping { + + ID("ID", "id"), + NAME("NAME", "name"), + IS_ENABLED("IS_ENABLED", "isEnabled"), + DATE("DATE", "date"), + CREATED_DATE("CREATED_DATE", "createdDate"), + CREATED_USER_ID("CREATED_USER_ID", "createdUserId"), + MODIFIED_DATE("MODIFIED_DATE", "modifiedDate"), + MODIFIED_USER_ID("MODIFIED_USER_ID", "modifiedUserId"); + + private final String columnName; + private final String modelName; + + public static final Map COLUMN_MAPPINGS = Stream.of(values()) + .collect(Collectors.toMap(FeatureToggleMapping::getColumnName, FeatureToggleMapping::getModelName)); +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/repository/FeatureToggleRepository.java b/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/repository/FeatureToggleRepository.java new file mode 100644 index 00000000..964a87ed --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/repository/FeatureToggleRepository.java @@ -0,0 +1,21 @@ +package com.graduationproject.studentinformationsystem.university.featuretoggle.repository; + +import com.graduationproject.studentinformationsystem.university.featuretoggle.model.entity.FeatureToggleEntity; +import com.graduationproject.studentinformationsystem.university.featuretoggle.model.enums.FeatureToggleName; + +import java.util.List; + +public interface FeatureToggleRepository { + + List getAllFeatureToggles(); + + FeatureToggleEntity getFeatureToggleByName(FeatureToggleName name); + + void enableFeatureToggle(FeatureToggleEntity featureToggleEntity); + + void disableFeatureToggle(FeatureToggleEntity featureToggleEntity); + + boolean isFeatureToggleExist(FeatureToggleName name); + + boolean isFeatureToggleEnabled(FeatureToggleName name); +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/repository/impl/FeatureToggleRepositoryImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/repository/impl/FeatureToggleRepositoryImpl.java new file mode 100644 index 00000000..87cf7802 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/repository/impl/FeatureToggleRepositoryImpl.java @@ -0,0 +1,129 @@ +package com.graduationproject.studentinformationsystem.university.featuretoggle.repository.impl; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisDatabaseException; +import com.graduationproject.studentinformationsystem.common.util.log.SisErrorLogMessageUtil; +import com.graduationproject.studentinformationsystem.common.util.log.SisInfoLogMessageUtil; +import com.graduationproject.studentinformationsystem.common.util.log.SisWarnLogMessageUtil; +import com.graduationproject.studentinformationsystem.university.featuretoggle.model.entity.FeatureToggleEntity; +import com.graduationproject.studentinformationsystem.university.featuretoggle.model.enums.FeatureToggleName; +import com.graduationproject.studentinformationsystem.university.featuretoggle.repository.FeatureToggleRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; +import org.sql2o.Connection; +import org.sql2o.Query; +import org.sql2o.Sql2o; + +import java.util.List; + +import static com.graduationproject.studentinformationsystem.university.featuretoggle.model.mapping.FeatureToggleMapping.*; +import static com.graduationproject.studentinformationsystem.university.featuretoggle.repository.impl.scripts.FeatureToggleSqlScripts.*; + +@Repository +@RequiredArgsConstructor +public class FeatureToggleRepositoryImpl implements FeatureToggleRepository { + + private static final String FEATURE_TOGGLE = "Feature Toggle"; + private final SisInfoLogMessageUtil info = SisInfoLogMessageUtil.builder().apiName(FEATURE_TOGGLE).build(); + private final SisWarnLogMessageUtil warn = SisWarnLogMessageUtil.builder().apiName(FEATURE_TOGGLE).build(); + private final SisErrorLogMessageUtil error = SisErrorLogMessageUtil.builder().apiName(FEATURE_TOGGLE).build(); + + private final Sql2o sql2o; + + public List getAllFeatureToggles() { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(GET_ALL_FEATURE_TOGGLES)) { + + final List featureToggleEntities = query + .setColumnMappings(COLUMN_MAPPINGS) + .executeAndFetch(FeatureToggleEntity.class); + + info.foundAll(); + return featureToggleEntities; + } catch (Exception exception) { + error.errorWhenGettingAll(); + throw new SisDatabaseException(exception); + } + } + + @Override + public FeatureToggleEntity getFeatureToggleByName(final FeatureToggleName name) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(GET_FEATURE_TOGGLE_BY_NAME)) { + + final FeatureToggleEntity featureToggleEntity = query.addParameter(NAME.getModelName(), name) + .setColumnMappings(COLUMN_MAPPINGS) + .executeAndFetchFirst(FeatureToggleEntity.class); + + info.foundByName(name.toString()); + return featureToggleEntity; + } catch (Exception exception) { + error.errorWhenGettingByName(name.toString()); + throw new SisDatabaseException(exception); + } + } + + @Override + public void enableFeatureToggle(final FeatureToggleEntity featureToggleEntity) { + updateFeatureToggleValue(featureToggleEntity, ENABLE_FEATURE_TOGGLE); + } + + @Override + public void disableFeatureToggle(final FeatureToggleEntity featureToggleEntity) { + updateFeatureToggleValue(featureToggleEntity, DISABLE_FEATURE_TOGGLE); + } + + @Override + public boolean isFeatureToggleExist(final FeatureToggleName name) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(IS_FEATURE_TOGGLE_EXIST_BY_NAME)) { + + final boolean isFeatureToggleExist = query + .addParameter(NAME.getModelName(), name) + .executeScalar(Boolean.class); + + if (isFeatureToggleExist) { + info.foundByName(name.toString()); + return true; + } else { + warn.notFoundByName(name.toString()); + return false; + } + } catch (Exception exception) { + error.errorWhenGettingByName(name.toString()); + throw new SisDatabaseException(exception); + } + } + + @Override + public boolean isFeatureToggleEnabled(final FeatureToggleName name) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(IS_FEATURE_TOGGLE_ENABLED)) { + + final boolean isFeatureToggleEnabled = query + .addParameter(NAME.getModelName(), name) + .executeScalar(Boolean.class); + + if (isFeatureToggleEnabled) { + info.foundByName(name.toString()); + return true; + } else { + warn.notFoundByName(name.toString()); + return false; + } + } catch (Exception exception) { + error.errorWhenGettingByName(name.toString()); + throw new SisDatabaseException(exception); + } + } + + private void updateFeatureToggleValue(final FeatureToggleEntity featureToggleEntity, final String sql) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(sql)) { + + query.addParameter(NAME.getModelName(), featureToggleEntity.getName()) + .addParameter(MODIFIED_USER_ID.getModelName(), featureToggleEntity.getModifiedUserId()) + .addParameter(MODIFIED_DATE.getModelName(), featureToggleEntity.getModifiedDate()) + .executeUpdate(); + + info.updated(); + } catch (Exception exception) { + error.errorWhenUpdating(); + throw new SisDatabaseException(exception); + } + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/repository/impl/scripts/FeatureToggleSqlScripts.java b/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/repository/impl/scripts/FeatureToggleSqlScripts.java new file mode 100644 index 00000000..369283b7 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/repository/impl/scripts/FeatureToggleSqlScripts.java @@ -0,0 +1,74 @@ +package com.graduationproject.studentinformationsystem.university.featuretoggle.repository.impl.scripts; + +import com.graduationproject.studentinformationsystem.common.util.sql.SisSqlUtil; + +import static com.graduationproject.studentinformationsystem.university.featuretoggle.model.mapping.FeatureToggleMapping.NAME; + +public class FeatureToggleSqlScripts { + + private static final StringBuilder sqlBuilder = new StringBuilder(); + + private FeatureToggleSqlScripts() { + } + + /** + * SELECT ID, NAME, IS_ENABLED, DATE, + * CREATED_DATE, CREATED_USER_ID, MODIFIED_DATE, MODIFIED_USER_ID FROM UNIV_FEATURE_TOGGLE; + */ + public static final String GET_ALL_FEATURE_TOGGLES = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("SELECT ID, NAME, IS_ENABLED, DATE, " + + "CREATED_DATE, CREATED_USER_ID, MODIFIED_DATE, MODIFIED_USER_ID " + + "FROM UNIV_FEATURE_TOGGLE ").toString(); + + /** + * SELECT ID, NAME, IS_ENABLED, DATE, + * CREATED_DATE, CREATED_USER_ID, MODIFIED_DATE, MODIFIED_USER_ID FROM UNIV_FEATURE_TOGGLE + * WHERE NAME=:name; + */ + public static final String GET_FEATURE_TOGGLE_BY_NAME = + sqlBuilder.delete(0, sqlBuilder.length()) + .append(GET_ALL_FEATURE_TOGGLES) + .append("WHERE NAME=:name").toString(); + + /** + * UPDATE UNIV_FEATURE_TOGGLE SET IS_ENABLED=1, + * MODIFIED_DATE=:modifiedDate, MODIFIED_USER_ID=:modifiedUserId + * WHERE NAME=:name; + */ + public static final String ENABLE_FEATURE_TOGGLE = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("UPDATE UNIV_FEATURE_TOGGLE SET IS_ENABLED=1, " + + "MODIFIED_DATE=:modifiedDate, MODIFIED_USER_ID=:modifiedUserId " + + "WHERE NAME=:name").toString(); + + /** + * UPDATE UNIV_FEATURE_TOGGLE SET IS_ENABLED=0, + * MODIFIED_DATE=:modifiedDate, MODIFIED_USER_ID=:modifiedUserId + * WHERE NAME=:name; + */ + public static final String DISABLE_FEATURE_TOGGLE = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("UPDATE UNIV_FEATURE_TOGGLE SET IS_ENABLED=0, " + + "MODIFIED_DATE=:modifiedDate, MODIFIED_USER_ID=:modifiedUserId " + + "WHERE NAME=:name").toString(); + + /** + * SELECT CASE WHEN MAX(NAME) IS NULL THEN 'false' ELSE 'true' END IS_EXIST + * FROM UNIV_FEATURE_TOGGLE WHERE NAME=:name; + */ + public static final String IS_FEATURE_TOGGLE_EXIST_BY_NAME = SisSqlUtil + .isExistByColumnName("UNIV_FEATURE_TOGGLE", + NAME.getColumnName(), + NAME.getModelName()); + + /** + * SELECT CASE WHEN MAX(NAME) IS NULL THEN 'false' ELSE 'true' END IS_EXIST + * FROM UNIV_FEATURE_TOGGLE WHERE NAME=:name AND IS_ENABLED=1 AND DATE < NOW(); + */ + public static final String IS_FEATURE_TOGGLE_ENABLED = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("SELECT CASE WHEN MAX(NAME) IS NULL " + + "THEN 'false' ELSE 'true' END IS_EXIST FROM UNIV_FEATURE_TOGGLE " + + "WHERE NAME=:name AND IS_ENABLED='1' AND DATE < NOW()").toString(); +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/service/FeatureToggleService.java b/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/service/FeatureToggleService.java new file mode 100644 index 00000000..2a0a940a --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/service/FeatureToggleService.java @@ -0,0 +1,22 @@ +package com.graduationproject.studentinformationsystem.university.featuretoggle.service; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.university.featuretoggle.model.dto.request.FeatureToggleRequest; +import com.graduationproject.studentinformationsystem.university.featuretoggle.model.dto.response.FeatureToggleIsEnabledResponse; +import com.graduationproject.studentinformationsystem.university.featuretoggle.model.dto.response.FeatureToggleResponse; +import com.graduationproject.studentinformationsystem.university.featuretoggle.model.enums.FeatureToggleName; + +import java.util.List; + +public interface FeatureToggleService { + + List getAllFeatureToggles(); + + FeatureToggleResponse getFeatureToggleByName(FeatureToggleName name) throws SisNotExistException; + + FeatureToggleResponse enableFeatureToggle(FeatureToggleRequest featureToggleRequest) throws SisNotExistException; + + FeatureToggleResponse disableFeatureToggle(FeatureToggleRequest featureToggleRequest) throws SisNotExistException; + + FeatureToggleIsEnabledResponse isFeatureToggleEnabled(FeatureToggleName name) throws SisNotExistException; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/service/impl/FeatureToggleServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/service/impl/FeatureToggleServiceImpl.java new file mode 100644 index 00000000..013ba528 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/featuretoggle/service/impl/FeatureToggleServiceImpl.java @@ -0,0 +1,94 @@ +package com.graduationproject.studentinformationsystem.university.featuretoggle.service.impl; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.university.featuretoggle.model.dto.converter.FeatureToggleInfoConverter; +import com.graduationproject.studentinformationsystem.university.featuretoggle.model.dto.request.FeatureToggleRequest; +import com.graduationproject.studentinformationsystem.university.featuretoggle.model.dto.response.FeatureToggleIsEnabledResponse; +import com.graduationproject.studentinformationsystem.university.featuretoggle.model.dto.response.FeatureToggleResponse; +import com.graduationproject.studentinformationsystem.university.featuretoggle.model.entity.FeatureToggleEntity; +import com.graduationproject.studentinformationsystem.university.featuretoggle.model.enums.FeatureToggleName; +import com.graduationproject.studentinformationsystem.university.featuretoggle.model.exception.FeatureToggleException; +import com.graduationproject.studentinformationsystem.university.featuretoggle.repository.FeatureToggleRepository; +import com.graduationproject.studentinformationsystem.university.featuretoggle.service.FeatureToggleService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +@RequiredArgsConstructor +public class FeatureToggleServiceImpl implements FeatureToggleService { + + private final FeatureToggleRepository featureToggleRepository; + private final FeatureToggleInfoConverter featureToggleInfoConverter; + + @Override + public List getAllFeatureToggles() { + final List featureToggleEntities = featureToggleRepository.getAllFeatureToggles(); + return featureToggleInfoConverter.entitiesToResponses(featureToggleEntities); + } + + @Override + public FeatureToggleResponse getFeatureToggleByName(final FeatureToggleName name) throws SisNotExistException { + + checkBeforeProcessing(name); + + final FeatureToggleEntity featureToggleEntity = featureToggleRepository.getFeatureToggleByName(name); + return featureToggleInfoConverter.entityToResponse(featureToggleEntity); + } + + @Override + public FeatureToggleResponse enableFeatureToggle(final FeatureToggleRequest featureToggleRequest) throws SisNotExistException { + + checkBeforeProcessing(featureToggleRequest.getName()); + + final FeatureToggleEntity featureToggleEntity = featureToggleInfoConverter.generateEntity(featureToggleRequest); + featureToggleRepository.enableFeatureToggle(featureToggleEntity); + + return getFeatureToggleByName(featureToggleRequest.getName()); + } + + @Override + public FeatureToggleResponse disableFeatureToggle(final FeatureToggleRequest featureToggleRequest) throws SisNotExistException { + + checkBeforeProcessing(featureToggleRequest.getName()); + + final FeatureToggleEntity featureToggleEntity = featureToggleInfoConverter.generateEntity(featureToggleRequest); + featureToggleRepository.disableFeatureToggle(featureToggleEntity); + + return getFeatureToggleByName(featureToggleRequest.getName()); + } + + @Override + public FeatureToggleIsEnabledResponse isFeatureToggleEnabled(final FeatureToggleName name) throws SisNotExistException { + + ifFeatureToggleIsNotExistThrowNotExistException(name); + + final boolean isFeatureToggleEnabled = featureToggleRepository.isFeatureToggleEnabled(name); + if (isFeatureToggleEnabled) { + return FeatureToggleIsEnabledResponse.builder() + .isFeatureToggleEnabled(true).build(); + } + return FeatureToggleIsEnabledResponse.builder() + .isFeatureToggleEnabled(false).build(); + } + + + /** + * Checks Before Processing + */ + + private void checkBeforeProcessing(final FeatureToggleName name) throws SisNotExistException { + ifFeatureToggleIsNotExistThrowNotExistException(name); + } + + /** + * Throw Exceptions + */ + + private void ifFeatureToggleIsNotExistThrowNotExistException(final FeatureToggleName name) throws SisNotExistException { + if (!featureToggleRepository.isFeatureToggleExist(name)) { + FeatureToggleException.throwNotExistException(name); + } + } +} From 9fa3256f2a48e3a1dceed5edda62e91f2568a391 Mon Sep 17 00:00:00 2001 From: Agit Rubar Demir <61833677+agitrubard@users.noreply.github.com> Date: Fri, 11 Mar 2022 00:08:50 +0300 Subject: [PATCH 12/13] Student Regis API Update | SIS-122 (#67) * failResponse Method Has Been Added to SisResponseUtil * isStudentLessonRegistrationWaiting and isStudentLessonRegistrationApproved Methods Have Been Added to StudentLessonRegistrationService * isStudentLessonRegistrationWaiting and isStudentLessonRegistrationApproved Methods Have Been Added to StudentLessonRegistrationController --- .../controller/response/SisResponseUtil.java | 24 ++++++++++----- .../StudentLessonRegistrationController.java | 30 +++++++++++++++++++ ...tLessonRegistrationControllerEndpoint.java | 2 ++ .../StudentLessonRegistrationService.java | 4 +++ .../StudentLessonRegistrationServiceImpl.java | 10 +++++++ 5 files changed, 62 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/graduationproject/studentinformationsystem/common/util/controller/response/SisResponseUtil.java b/src/main/java/com/graduationproject/studentinformationsystem/common/util/controller/response/SisResponseUtil.java index aeb47a56..0aaf68df 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/common/util/controller/response/SisResponseUtil.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/common/util/controller/response/SisResponseUtil.java @@ -18,14 +18,6 @@ public static ResponseEntity successResponse() { .isSuccess(true).build(), HttpStatus.OK); } - public static ResponseEntity unauthorizedResponse() { - return new ResponseEntity<>( - SisApiResponse.builder() - .requestTime(LocalDateTime.now()) - .httpStatus(HttpStatus.UNAUTHORIZED) - .isSuccess(false).build(), HttpStatus.UNAUTHORIZED); - } - public static ResponseEntity> successResponse(final T response) { return new ResponseEntity<>( SisBaseApiResponse.builder() @@ -34,4 +26,20 @@ public static ResponseEntity> successResponse(final T .isSuccess(true) .response(response).build(), HttpStatus.OK); } + + public static ResponseEntity failResponse() { + return new ResponseEntity<>( + SisApiResponse.builder() + .requestTime(LocalDateTime.now()) + .httpStatus(HttpStatus.NOT_FOUND) + .isSuccess(false).build(), HttpStatus.NOT_FOUND); + } + + public static ResponseEntity unauthorizedResponse() { + return new ResponseEntity<>( + SisApiResponse.builder() + .requestTime(LocalDateTime.now()) + .httpStatus(HttpStatus.UNAUTHORIZED) + .isSuccess(false).build(), HttpStatus.UNAUTHORIZED); + } } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/controller/StudentLessonRegistrationController.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/controller/StudentLessonRegistrationController.java index ebb2e954..d2d42ef5 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/controller/StudentLessonRegistrationController.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/controller/StudentLessonRegistrationController.java @@ -1,5 +1,6 @@ package com.graduationproject.studentinformationsystem.university.lesson.student.registration.controller; +import com.graduationproject.studentinformationsystem.common.util.controller.response.SisApiResponse; import com.graduationproject.studentinformationsystem.common.util.controller.response.SisBaseApiResponse; import com.graduationproject.studentinformationsystem.common.util.exception.SisAlreadyException; import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; @@ -22,6 +23,7 @@ import static com.graduationproject.studentinformationsystem.common.config.SisSwaggerConfiguration.STUDENT_LESSON_REGISTRATION_API_TAG; import static com.graduationproject.studentinformationsystem.common.util.controller.endpoint.SisControllerEndpoint.Path.STUDENT_LESSON_REGISTRATION; +import static com.graduationproject.studentinformationsystem.common.util.controller.response.SisResponseUtil.failResponse; import static com.graduationproject.studentinformationsystem.common.util.controller.response.SisResponseUtil.successResponse; @RestController @@ -52,6 +54,34 @@ public ResponseEntity isStudentLessonRegistrationWaiting( + @PathVariable final String registrationId) { + + final boolean isStudentLessonRegistrationExist = studentLessonRegistrationService.isStudentLessonRegistrationWaiting(registrationId); + + if (isStudentLessonRegistrationExist) { + return successResponse(); + } else { + return failResponse(); + } + } + + @GetMapping(StudentLessonRegistrationControllerEndpoint.APPROVED_BY_REGISTRATION_ID) + @ApiOperation(value = "Is Student Lesson Registration Approved") + public ResponseEntity isStudentLessonRegistrationApproved( + @PathVariable final String registrationId) { + + final boolean isStudentLessonRegistrationExist = studentLessonRegistrationService.isStudentLessonRegistrationApproved(registrationId); + + if (isStudentLessonRegistrationExist) { + return successResponse(); + } else { + return failResponse(); + } + } + @PostMapping(StudentLessonRegistrationControllerEndpoint.SAVE) @ApiOperation(value = "Save Student Lesson Registration") public ResponseEntity> saveStudentLessonRegistration( diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/controller/endpoint/StudentLessonRegistrationControllerEndpoint.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/controller/endpoint/StudentLessonRegistrationControllerEndpoint.java index ffa6ff7d..c023025d 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/controller/endpoint/StudentLessonRegistrationControllerEndpoint.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/controller/endpoint/StudentLessonRegistrationControllerEndpoint.java @@ -11,4 +11,6 @@ private StudentLessonRegistrationControllerEndpoint() { public static final String SAVE = "/save"; public static final String APPROVE = "/approve"; public static final String REJECT = "/reject"; + public static final String WAITING_BY_REGISTRATION_ID = "/waiting" + REGISTRATION_ID; + public static final String APPROVED_BY_REGISTRATION_ID = "/approved" + REGISTRATION_ID; } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/service/StudentLessonRegistrationService.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/service/StudentLessonRegistrationService.java index 51bb103e..943fe67b 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/service/StudentLessonRegistrationService.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/service/StudentLessonRegistrationService.java @@ -26,4 +26,8 @@ StudentLessonRegistrationDetailResponse approveStudentLessonRegistration(Student StudentLessonRegistrationDetailResponse rejectStudentLessonRegistration(StudentLessonRegistrationRejectRequest rejectRequest) throws SisAlreadyException, SisNotExistException; + + boolean isStudentLessonRegistrationWaiting(String registrationId); + + boolean isStudentLessonRegistrationApproved(String registrationId); } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/service/impl/StudentLessonRegistrationServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/service/impl/StudentLessonRegistrationServiceImpl.java index d0314846..2540f150 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/service/impl/StudentLessonRegistrationServiceImpl.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/service/impl/StudentLessonRegistrationServiceImpl.java @@ -107,6 +107,16 @@ public StudentLessonRegistrationDetailResponse rejectStudentLessonRegistration(f return getStudentLessonRegistrationDetailByRegistrationId(registrationId); } + @Override + public boolean isStudentLessonRegistrationWaiting(final String registrationId) { + return studentLessonRegistrationRepository.isStudentLessonRegistrationWaiting(registrationId); + } + + @Override + public boolean isStudentLessonRegistrationApproved(final String registrationId) { + return studentLessonRegistrationRepository.isStudentLessonRegistrationApproved(registrationId); + } + /** * Checks Before Processing From 139f17f579dc447cbd906d3fbdb08f9fbae8f6e2 Mon Sep 17 00:00:00 2001 From: Agit Rubar Demir <61833677+agitrubard@users.noreply.github.com> Date: Sun, 20 Mar 2022 13:38:34 +0300 Subject: [PATCH 13/13] Student Lesson Note API | SIS-118 (#68) * errorWhenGettingAllByStudentId and errorWhenGettingAllByStudentId Methods Have Been Added to SisErrorLogMessageUtil * foundAllByLessonId and foundAllByStudentId Methods Have Been Added to SisInfoLogMessageUtil * notFoundAllByStudentId and notFoundAllByLessonId Methods Have Been Added to SisWarnLogMessageUtil * getTeacherIdByLessonId Method Has Been Added to TeacherLessonRepository * StudentLessonNoteMapping Class Has Been Created * StudentLessonNoteException Class Has Been Created * StudentLessonNoteUtil Class Has Been Created * StudentLessonNoteStatus Enum Class Has Been Created * StudentLesson Note Entity Classes Have Been Created * StudentLesson Note Request Classes Have Been Created * StudentLessonNoteResponse Class Has Been Created * StudentLessonNoteInfoConverter Class Has Been Created * TeacherLessonOutService Class Has Been Created for getTeacherIdByLessonId Method * STUDENT_LESSON_NOTE_API_TAG Has Been Added to SisSwaggerConfiguration Class * STUDENT_LESSON_NOTE Endpoint Has Been Added to SisControllerEndpoint Class * StudentLessonNote Repository Classes Have Been Created * StudentLessonNote Service Classes Have Been Created * StudentLessonNote Out Service Classes Have Been Created * StudentLessonNoteControllerEndpoint Class Has Been Created * StudentLessonNoteController Class Has Been Created * StudentLessonNoteOutService Has Been Integrated to StudentLessonRegistrationService/approveStudentLessonRegistration Method --- .../config/SisSwaggerConfiguration.java | 2 + .../endpoint/SisControllerEndpoint.java | 2 + .../util/log/SisErrorLogMessageUtil.java | 8 + .../util/log/SisInfoLogMessageUtil.java | 8 + .../util/log/SisWarnLogMessageUtil.java | 8 + .../StudentLessonRegistrationServiceImpl.java | 9 + .../repository/TeacherLessonRepository.java | 2 + .../impl/TeacherLessonRepositoryImpl.java | 14 ++ .../impl/scripts/TeacherLessonSqlScripts.java | 7 + .../service/TeacherLessonOutService.java | 6 + .../impl/TeacherLessonOutServiceImpl.java | 18 ++ .../StudentLessonNoteController.java | 82 +++++++ .../StudentLessonNoteControllerEndpoint.java | 17 ++ .../StudentLessonNoteInfoConverter.java | 125 +++++++++++ .../StudentLessonFinalNoteUpdateRequest.java | 29 +++ ...StudentLessonMidtermNoteUpdateRequest.java | 29 +++ .../request/StudentLessonNoteSaveRequest.java | 36 +++ .../StudentLessonResitNoteUpdateRequest.java | 29 +++ .../response/StudentLessonNoteResponse.java | 25 +++ .../StudentLessonFinalNoteUpdateEntity.java | 19 ++ .../StudentLessonMidtermNoteUpdateEntity.java | 16 ++ .../model/entity/StudentLessonNoteEntity.java | 21 ++ .../entity/StudentLessonNoteSaveEntity.java | 20 ++ .../StudentLessonResitNoteUpdateEntity.java | 19 ++ .../model/enums/StudentLessonNoteStatus.java | 15 ++ .../exception/StudentLessonNoteException.java | 16 ++ .../mapping/StudentLessonNoteMapping.java | 33 +++ .../StudentLessonNoteRepository.java | 26 +++ .../impl/StudentLessonNoteRepositoryImpl.java | 205 ++++++++++++++++++ .../scripts/StudentLessonNoteSqlScripts.java | 113 ++++++++++ .../service/StudentLessonNoteOutService.java | 13 ++ .../service/StudentLessonNoteService.java | 22 ++ .../impl/StudentLessonNoteOutServiceImpl.java | 45 ++++ .../impl/StudentLessonNoteServiceImpl.java | 174 +++++++++++++++ .../note/util/StudentLessonNoteUtil.java | 14 ++ 35 files changed, 1227 insertions(+) create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/service/TeacherLessonOutService.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/service/impl/TeacherLessonOutServiceImpl.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/note/controller/StudentLessonNoteController.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/note/controller/endpoint/StudentLessonNoteControllerEndpoint.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/note/model/dto/converter/StudentLessonNoteInfoConverter.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/note/model/dto/request/StudentLessonFinalNoteUpdateRequest.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/note/model/dto/request/StudentLessonMidtermNoteUpdateRequest.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/note/model/dto/request/StudentLessonNoteSaveRequest.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/note/model/dto/request/StudentLessonResitNoteUpdateRequest.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/note/model/dto/response/StudentLessonNoteResponse.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/note/model/entity/StudentLessonFinalNoteUpdateEntity.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/note/model/entity/StudentLessonMidtermNoteUpdateEntity.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/note/model/entity/StudentLessonNoteEntity.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/note/model/entity/StudentLessonNoteSaveEntity.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/note/model/entity/StudentLessonResitNoteUpdateEntity.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/note/model/enums/StudentLessonNoteStatus.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/note/model/exception/StudentLessonNoteException.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/note/model/mapping/StudentLessonNoteMapping.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/note/repository/StudentLessonNoteRepository.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/note/repository/impl/StudentLessonNoteRepositoryImpl.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/note/repository/impl/scripts/StudentLessonNoteSqlScripts.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/note/service/StudentLessonNoteOutService.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/note/service/StudentLessonNoteService.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/note/service/impl/StudentLessonNoteOutServiceImpl.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/note/service/impl/StudentLessonNoteServiceImpl.java create mode 100644 src/main/java/com/graduationproject/studentinformationsystem/university/note/util/StudentLessonNoteUtil.java diff --git a/src/main/java/com/graduationproject/studentinformationsystem/common/config/SisSwaggerConfiguration.java b/src/main/java/com/graduationproject/studentinformationsystem/common/config/SisSwaggerConfiguration.java index b53ecc41..3ef7a6ce 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/common/config/SisSwaggerConfiguration.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/common/config/SisSwaggerConfiguration.java @@ -28,6 +28,7 @@ public class SisSwaggerConfiguration { public static final String STUDENT_API_TAG = "Student Controller"; public static final String STUDENT_LESSON_API_TAG = "Student Lesson Controller"; public static final String STUDENT_LESSON_REGISTRATION_API_TAG = "Student Lesson Registration Controller"; + public static final String STUDENT_LESSON_NOTE_API_TAG = "Student Lesson Note Controller"; public static final String TEACHER_API_TAG = "Teacher Controller"; public static final String TEACHER_LESSON_API_TAG = "Teacher Lesson Controller"; public static final String OFFICER_API_TAG = "Officer Controller"; @@ -53,6 +54,7 @@ public Docket api() { new Tag(STUDENT_API_TAG, "STUDENT_ACADEMIC_INFO & STUDENT_PERSONAL_INFO"), new Tag(STUDENT_LESSON_API_TAG, "STUDENT_LESSON"), new Tag(STUDENT_LESSON_REGISTRATION_API_TAG, "STUDENT_LESSON_REGISTRATION"), + new Tag(STUDENT_LESSON_NOTE_API_TAG, "STUDENT_LESSON_NOTE"), new Tag(TEACHER_API_TAG, "TEACHER_ACADEMIC_INFO & TEACHER_PERSONAL_INFO"), new Tag(TEACHER_LESSON_API_TAG, "TEACHER_LESSON"), new Tag(OFFICER_API_TAG, "OFFICER_ACADEMIC_INFO & OFFICER_PERSONAL_INFO"), diff --git a/src/main/java/com/graduationproject/studentinformationsystem/common/util/controller/endpoint/SisControllerEndpoint.java b/src/main/java/com/graduationproject/studentinformationsystem/common/util/controller/endpoint/SisControllerEndpoint.java index 2ccb7014..e9f14c4a 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/common/util/controller/endpoint/SisControllerEndpoint.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/common/util/controller/endpoint/SisControllerEndpoint.java @@ -11,6 +11,7 @@ private Path() { private static final String REGISTRATION = "/registration"; private static final String PASSWORD_OPERATION = "/password-operation"; + private static final String NOTE = "/note"; public static final String FACULTY = "/faculty"; public static final String DEPARTMENT = "/department"; @@ -21,6 +22,7 @@ private Path() { public static final String STUDENT = "/student"; public static final String STUDENT_LESSON = STUDENT + LESSON; public static final String STUDENT_LESSON_REGISTRATION = STUDENT_LESSON + REGISTRATION; + public static final String STUDENT_LESSON_NOTE = STUDENT + LESSON + NOTE; public static final String TEACHER = "/teacher"; public static final String TEACHER_LESSON = TEACHER + LESSON; public static final String OFFICER = "/officer"; diff --git a/src/main/java/com/graduationproject/studentinformationsystem/common/util/log/SisErrorLogMessageUtil.java b/src/main/java/com/graduationproject/studentinformationsystem/common/util/log/SisErrorLogMessageUtil.java index 413c0344..1e754cdc 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/common/util/log/SisErrorLogMessageUtil.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/common/util/log/SisErrorLogMessageUtil.java @@ -48,6 +48,14 @@ public void errorWhenGettingAllByStatus(final String status) { log.error("Error When Getting {}s by Status! status:{}", apiName, status); } + public void errorWhenGettingAllByStudentId(final Long studentId) { + log.error("Error When Getting {}s by Student ID! studentId:{}", apiName, studentId); + } + + public void errorWhenGettingAllByLessonId(final Long lessonId) { + log.error("Error When Getting {}s by Lesson ID! lessonId:{}", apiName, lessonId); + } + public void errorWhenGettingAllIdsByDepartmentId(final Long departmentId) { log.error("Error When Getting {} IDs by Department ID! departmentId:{}", apiName, departmentId); } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/common/util/log/SisInfoLogMessageUtil.java b/src/main/java/com/graduationproject/studentinformationsystem/common/util/log/SisInfoLogMessageUtil.java index 4aa007b5..8cf9cc36 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/common/util/log/SisInfoLogMessageUtil.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/common/util/log/SisInfoLogMessageUtil.java @@ -44,6 +44,14 @@ public void foundAllIds() { log.info("{} IDs Found!", apiName); } + public void foundAllByLessonId(final Long lessonId) { + log.info("{}s Found by Lesson ID! lessonId:{}", apiName, lessonId); + } + + public void foundAllByStudentId(final Long studentId) { + log.info("{}s Found by Student ID! studentId:{}", apiName, studentId); + } + public void foundAllByStatus(final String status) { log.info("{}s Found by Status! status:{}", apiName, status); } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/common/util/log/SisWarnLogMessageUtil.java b/src/main/java/com/graduationproject/studentinformationsystem/common/util/log/SisWarnLogMessageUtil.java index d07f3bd8..055d3912 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/common/util/log/SisWarnLogMessageUtil.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/common/util/log/SisWarnLogMessageUtil.java @@ -32,6 +32,14 @@ public void notFoundByIdAndStatus(final Long id, final String status) { log.warn("{} Not Found by ID! id:{} status:{}", apiName, id, status); } + public void notFoundAllByStudentId(final Long lessonId) { + log.warn("{}s Not Found By Student ID! lessonId:{}", apiName, lessonId); + } + + public void notFoundAllByLessonId(final Long lessonId) { + log.warn("{}s Not Found By Lesson ID! lessonId:{}", apiName, lessonId); + } + public void notFoundAllIds() { log.warn("{} IDs Not Found!", apiName); } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/service/impl/StudentLessonRegistrationServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/service/impl/StudentLessonRegistrationServiceImpl.java index 2540f150..db82c827 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/service/impl/StudentLessonRegistrationServiceImpl.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/student/registration/service/impl/StudentLessonRegistrationServiceImpl.java @@ -1,7 +1,9 @@ package com.graduationproject.studentinformationsystem.university.lesson.student.registration.service.impl; +import com.graduationproject.studentinformationsystem.common.model.dto.request.SisOperationInfoRequest; import com.graduationproject.studentinformationsystem.common.util.exception.SisAlreadyException; import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.university.lesson.common.model.dto.response.LessonResponse; import com.graduationproject.studentinformationsystem.university.lesson.common.service.LessonOutService; import com.graduationproject.studentinformationsystem.university.lesson.student.common.service.StudentLessonOutService; import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.dto.converter.StudentLessonRegistrationInfoConverter; @@ -15,6 +17,7 @@ import com.graduationproject.studentinformationsystem.university.lesson.student.registration.model.exception.StudentLessonRegistrationException; import com.graduationproject.studentinformationsystem.university.lesson.student.registration.repository.StudentLessonRegistrationRepository; import com.graduationproject.studentinformationsystem.university.lesson.student.registration.service.StudentLessonRegistrationService; +import com.graduationproject.studentinformationsystem.university.note.service.StudentLessonNoteOutService; import com.graduationproject.studentinformationsystem.university.student.service.StudentOutService; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -28,6 +31,7 @@ public class StudentLessonRegistrationServiceImpl implements StudentLessonRegist private final StudentOutService studentOutService; private final LessonOutService lessonOutService; private final StudentLessonOutService studentLessonOutService; + private final StudentLessonNoteOutService studentLessonNoteOutService; private final StudentLessonRegistrationRepository studentLessonRegistrationRepository; private final StudentLessonRegistrationInfoConverter studentLessonRegistrationInfoConverter; @@ -87,6 +91,11 @@ public StudentLessonRegistrationDetailResponse approveStudentLessonRegistration( if (StudentLessonRegistrationStatus.APPROVED.equals(registrationDetailResponse.getStatus())) { studentLessonOutService.saveStudentLessons(registrationDetailResponse); + + final Long studentId = registrationDetailResponse.getStudentInfoResponse().getStudentId(); + final List lessonResponses = registrationDetailResponse.getLessonResponses(); + final SisOperationInfoRequest operationInfoRequest = approveRequest.getOperationInfoRequest(); + studentLessonNoteOutService.saveStudentLessonsNotesRegistrations(studentId, lessonResponses, operationInfoRequest); } return registrationDetailResponse; diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/repository/TeacherLessonRepository.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/repository/TeacherLessonRepository.java index 79b5b658..3f12e4c2 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/repository/TeacherLessonRepository.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/repository/TeacherLessonRepository.java @@ -19,4 +19,6 @@ public interface TeacherLessonRepository { void deleteTeacherLesson(TeacherLessonDeleteEntity deleteLessonEntity); boolean isTeacherLessonExist(Long teacherId, Long lessonId); + + Long getTeacherIdByLessonId(Long lessonId); } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/repository/impl/TeacherLessonRepositoryImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/repository/impl/TeacherLessonRepositoryImpl.java index d34e7055..57f0e0ab 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/repository/impl/TeacherLessonRepositoryImpl.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/repository/impl/TeacherLessonRepositoryImpl.java @@ -137,4 +137,18 @@ public boolean isTeacherLessonExist(final Long teacherId, final Long lessonId) { throw new SisDatabaseException(exception); } } + + @Override + public Long getTeacherIdByLessonId(Long lessonId) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(GET_TEACHER_ID_BY_LESSON_ID)) { + + return query.addParameter(LESSON_ID.getModelName(), lessonId) + .setColumnMappings(COLUMN_MAPPINGS) + .executeScalar(Long.class); + + } catch (Exception exception) { + error.errorWhenGetting(); + throw new SisDatabaseException(exception); + } + } } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/repository/impl/scripts/TeacherLessonSqlScripts.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/repository/impl/scripts/TeacherLessonSqlScripts.java index 44faced6..d396a684 100644 --- a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/repository/impl/scripts/TeacherLessonSqlScripts.java +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/repository/impl/scripts/TeacherLessonSqlScripts.java @@ -63,4 +63,11 @@ private TeacherLessonSqlScripts() { TEACHER_ID.getModelName(), LESSON_ID.getColumnName(), LESSON_ID.getModelName()); + + /** + * SELECT TEACHER_ID FROM TEACHER_LESSON WHERE LESSON_ID=:lessonId; + */ + public static final String GET_TEACHER_ID_BY_LESSON_ID = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("SELECT TEACHER_ID FROM TEACHER_LESSON WHERE LESSON_ID=:lessonId").toString(); } diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/service/TeacherLessonOutService.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/service/TeacherLessonOutService.java new file mode 100644 index 00000000..5495f99a --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/service/TeacherLessonOutService.java @@ -0,0 +1,6 @@ +package com.graduationproject.studentinformationsystem.university.lesson.teacher.service; + +public interface TeacherLessonOutService { + + Long getTeacherIdByLessonId(Long lessonId); +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/service/impl/TeacherLessonOutServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/service/impl/TeacherLessonOutServiceImpl.java new file mode 100644 index 00000000..29d9ff0b --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/lesson/teacher/service/impl/TeacherLessonOutServiceImpl.java @@ -0,0 +1,18 @@ +package com.graduationproject.studentinformationsystem.university.lesson.teacher.service.impl; + +import com.graduationproject.studentinformationsystem.university.lesson.teacher.repository.TeacherLessonRepository; +import com.graduationproject.studentinformationsystem.university.lesson.teacher.service.TeacherLessonOutService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class TeacherLessonOutServiceImpl implements TeacherLessonOutService { + + private final TeacherLessonRepository teacherLessonRepository; + + @Override + public Long getTeacherIdByLessonId(Long lessonId) { + return teacherLessonRepository.getTeacherIdByLessonId(lessonId); + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/note/controller/StudentLessonNoteController.java b/src/main/java/com/graduationproject/studentinformationsystem/university/note/controller/StudentLessonNoteController.java new file mode 100644 index 00000000..8cca0cf2 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/note/controller/StudentLessonNoteController.java @@ -0,0 +1,82 @@ +package com.graduationproject.studentinformationsystem.university.note.controller; + +import com.graduationproject.studentinformationsystem.common.util.controller.response.SisBaseApiResponse; +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.university.note.controller.endpoint.StudentLessonNoteControllerEndpoint; +import com.graduationproject.studentinformationsystem.university.note.model.dto.request.StudentLessonFinalNoteUpdateRequest; +import com.graduationproject.studentinformationsystem.university.note.model.dto.request.StudentLessonMidtermNoteUpdateRequest; +import com.graduationproject.studentinformationsystem.university.note.model.dto.request.StudentLessonResitNoteUpdateRequest; +import com.graduationproject.studentinformationsystem.university.note.model.dto.response.StudentLessonNoteResponse; +import com.graduationproject.studentinformationsystem.university.note.service.StudentLessonNoteService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.util.List; + +import static com.graduationproject.studentinformationsystem.common.config.SisSwaggerConfiguration.STUDENT_LESSON_NOTE_API_TAG; +import static com.graduationproject.studentinformationsystem.common.util.controller.endpoint.SisControllerEndpoint.Path.STUDENT_LESSON_NOTE; +import static com.graduationproject.studentinformationsystem.common.util.controller.response.SisResponseUtil.successResponse; + +@RestController +@RequestMapping(STUDENT_LESSON_NOTE) +@Api(tags = STUDENT_LESSON_NOTE_API_TAG) +@RequiredArgsConstructor +public class StudentLessonNoteController { + + + private final StudentLessonNoteService studentLessonNoteService; + + @GetMapping(StudentLessonNoteControllerEndpoint.GET_ALL_BY_LESSON_ID) + @ApiOperation(value = "Get All Students Lessons Notes By Lesson ID") + public ResponseEntity>> getAllStudentsLessonsNotesByLessonId( + @PathVariable final Long lessonId) + throws SisNotExistException { + + final List noteResponses = studentLessonNoteService.getAllStudentsLessonsNotesByLessonId(lessonId); + return successResponse(noteResponses); + } + + @GetMapping(StudentLessonNoteControllerEndpoint.GET_ALL_BY_STUDENT_ID) + @ApiOperation(value = "Get All Student Lessons Notes By Student ID") + public ResponseEntity>> getAllStudentLessonsNotesByStudentId( + @PathVariable final Long studentId) + throws SisNotExistException { + + final List noteResponses = studentLessonNoteService.getAllStudentLessonsNotesByStudentId(studentId); + return successResponse(noteResponses); + } + + @PutMapping(StudentLessonNoteControllerEndpoint.MIDTERM) + @ApiOperation(value = "Update Student Lesson Midterm Note") + public ResponseEntity> updateStudentLessonMidtermNote( + @RequestBody @Valid final StudentLessonMidtermNoteUpdateRequest updateRequest) + throws SisNotExistException { + + final StudentLessonNoteResponse noteResponse = studentLessonNoteService.updateStudentLessonMidtermNote(updateRequest); + return successResponse(noteResponse); + } + + @PutMapping(StudentLessonNoteControllerEndpoint.FINAL) + @ApiOperation(value = "Update Student Lesson Final Note") + public ResponseEntity> updateStudentLessonFinalNote( + @RequestBody @Valid final StudentLessonFinalNoteUpdateRequest updateRequest) + throws SisNotExistException { + + final StudentLessonNoteResponse noteResponse = studentLessonNoteService.updateStudentLessonFinalNote(updateRequest); + return successResponse(noteResponse); + } + + @PutMapping(StudentLessonNoteControllerEndpoint.RESIT) + @ApiOperation(value = "Update Student Lesson Resit Note") + public ResponseEntity> updateStudentLessonResitNote( + @RequestBody final StudentLessonResitNoteUpdateRequest updateRequest) + throws SisNotExistException { + + final StudentLessonNoteResponse noteResponse = studentLessonNoteService.updateStudentLessonResitNote(updateRequest); + return successResponse(noteResponse); + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/note/controller/endpoint/StudentLessonNoteControllerEndpoint.java b/src/main/java/com/graduationproject/studentinformationsystem/university/note/controller/endpoint/StudentLessonNoteControllerEndpoint.java new file mode 100644 index 00000000..2d618e3e --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/note/controller/endpoint/StudentLessonNoteControllerEndpoint.java @@ -0,0 +1,17 @@ +package com.graduationproject.studentinformationsystem.university.note.controller.endpoint; + +public class StudentLessonNoteControllerEndpoint { + + private StudentLessonNoteControllerEndpoint() { + } + + private static final String ID = "/{id}"; + private static final String STUDENT_ID = "/{studentId}"; + private static final String LESSON_ID = "/{lessonId}"; + // public static final String GET_BY_ID = "/get" + ID; + public static final String GET_ALL_BY_STUDENT_ID = "/get/student" + STUDENT_ID; + public static final String GET_ALL_BY_LESSON_ID = "/get/lesson" + LESSON_ID; + public static final String MIDTERM = "/midterm"; + public static final String FINAL = "/final"; + public static final String RESIT = "/resit"; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/dto/converter/StudentLessonNoteInfoConverter.java b/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/dto/converter/StudentLessonNoteInfoConverter.java new file mode 100644 index 00000000..8044da08 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/dto/converter/StudentLessonNoteInfoConverter.java @@ -0,0 +1,125 @@ +package com.graduationproject.studentinformationsystem.university.note.model.dto.converter; + +import com.graduationproject.studentinformationsystem.common.model.dto.request.SisOperationInfoRequest; +import com.graduationproject.studentinformationsystem.common.util.SisUtil; +import com.graduationproject.studentinformationsystem.university.lesson.common.model.dto.response.LessonResponse; +import com.graduationproject.studentinformationsystem.university.lesson.common.service.LessonOutService; +import com.graduationproject.studentinformationsystem.university.note.model.dto.request.StudentLessonFinalNoteUpdateRequest; +import com.graduationproject.studentinformationsystem.university.note.model.dto.request.StudentLessonMidtermNoteUpdateRequest; +import com.graduationproject.studentinformationsystem.university.note.model.dto.request.StudentLessonNoteSaveRequest; +import com.graduationproject.studentinformationsystem.university.note.model.dto.request.StudentLessonResitNoteUpdateRequest; +import com.graduationproject.studentinformationsystem.university.note.model.dto.response.StudentLessonNoteResponse; +import com.graduationproject.studentinformationsystem.university.note.model.entity.*; +import com.graduationproject.studentinformationsystem.university.note.model.enums.StudentLessonNoteStatus; +import com.graduationproject.studentinformationsystem.university.note.util.StudentLessonNoteUtil; +import com.graduationproject.studentinformationsystem.university.student.model.dto.response.StudentInfoResponse; +import com.graduationproject.studentinformationsystem.university.student.service.StudentOutService; +import com.graduationproject.studentinformationsystem.university.teacher.model.dto.response.TeacherInfoResponse; +import com.graduationproject.studentinformationsystem.university.teacher.service.TeacherOutService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +@Component +@RequiredArgsConstructor +public class StudentLessonNoteInfoConverter { + + private final TeacherOutService teacherOutService; + private final StudentOutService studentOutService; + private final LessonOutService lessonOutService; + + public StudentLessonNoteSaveEntity generateSaveEntity(final StudentLessonNoteSaveRequest saveRequest) { + + final SisOperationInfoRequest operationInfoRequest = saveRequest.getOperationInfoRequest(); + + return StudentLessonNoteSaveEntity.builder() + .id(SisUtil.generateRandomUUID()) + .teacherId(saveRequest.getTeacherId()) + .studentId(saveRequest.getStudentId()) + .lessonId(saveRequest.getLessonId()) + .status(StudentLessonNoteStatus.UNFINALISED) + .createdUserId(operationInfoRequest.getUserId()) + .createdDate(new Date()) + .build(); + } + + public StudentLessonMidtermNoteUpdateEntity generateMidtermNoteUpdateEntity(final StudentLessonMidtermNoteUpdateRequest updateRequest) { + + final SisOperationInfoRequest operationInfoRequest = updateRequest.getOperationInfoRequest(); + + return StudentLessonMidtermNoteUpdateEntity.builder() + .id(updateRequest.getId()) + .midtermNote(updateRequest.getMidtermNote()) + .modifiedUserId(operationInfoRequest.getUserId()) + .modifiedDate(new Date()) + .build(); + } + + public StudentLessonFinalNoteUpdateEntity generateFinalNoteUpdateEntity(final Double meanOfNote, + final StudentLessonNoteStatus status, + final StudentLessonFinalNoteUpdateRequest updateRequest) { + + final SisOperationInfoRequest operationInfoRequest = updateRequest.getOperationInfoRequest(); + + return StudentLessonFinalNoteUpdateEntity.builder() + .id(updateRequest.getId()) + .finalNote(updateRequest.getFinalNote()) + .meanOfNote(meanOfNote) + .status(status) + .modifiedUserId(operationInfoRequest.getUserId()) + .modifiedDate(new Date()) + .build(); + } + + public StudentLessonResitNoteUpdateEntity generateResitNoteUpdateEntity(final Double meanOfNote, + final StudentLessonNoteStatus status, + final StudentLessonResitNoteUpdateRequest updateRequest) { + + final SisOperationInfoRequest operationInfoRequest = updateRequest.getOperationInfoRequest(); + + return StudentLessonResitNoteUpdateEntity.builder() + .id(updateRequest.getId()) + .resitNote(updateRequest.getResitNote()) + .meanOfNote(meanOfNote) + .status(status) + .modifiedUserId(operationInfoRequest.getUserId()) + .modifiedDate(new Date()) + .build(); + } + + public StudentLessonNoteResponse entityToResponse(final StudentLessonNoteEntity noteEntity) { + + final Long teacherId = noteEntity.getTeacherId(); + final TeacherInfoResponse teacherResponse = teacherOutService.getTeacherInfoResponse(teacherId); + + final Long studentId = noteEntity.getStudentId(); + final StudentInfoResponse studentResponse = studentOutService.getStudentInfoResponse(studentId); + + final Long lessonId = noteEntity.getLessonId(); + final LessonResponse lessonResponse = lessonOutService.getLessonResponse(lessonId); + + return StudentLessonNoteResponse.builder() + .id(noteEntity.getId()) + .teacherResponse(teacherResponse) + .studentResponse(studentResponse) + .lessonResponse(lessonResponse) + .midtermNote(noteEntity.getMidtermNote()) + .finalNote(noteEntity.getFinalNote()) + .resitNote(noteEntity.getResitNote()) + .meanOfNote(StudentLessonNoteUtil.getMeanOfNoteWith2NumberAfterDot(noteEntity.getMeanOfNote())) + .status(noteEntity.getStatus()) + .createdDate(SisUtil.getFormattedDateTime(noteEntity.getCreatedDate())) + .createdUserId(noteEntity.getCreatedUserId()) + .modifiedDate(SisUtil.getFormattedDateTime(noteEntity.getModifiedDate())) + .modifiedUserId(noteEntity.getModifiedUserId()).build(); + } + + public List entitiesToResponses(final List noteEntities) { + List noteResponses = new ArrayList<>(); + noteEntities.forEach(noteEntity -> noteResponses.add(entityToResponse(noteEntity))); + return noteResponses; + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/dto/request/StudentLessonFinalNoteUpdateRequest.java b/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/dto/request/StudentLessonFinalNoteUpdateRequest.java new file mode 100644 index 00000000..1d2b5c2e --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/dto/request/StudentLessonFinalNoteUpdateRequest.java @@ -0,0 +1,29 @@ +package com.graduationproject.studentinformationsystem.university.note.model.dto.request; + +import com.graduationproject.studentinformationsystem.common.model.dto.request.SisOperationInfoRequest; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +import javax.validation.Valid; +import javax.validation.constraints.NotNull; +import java.io.Serial; +import java.io.Serializable; + +@Getter +@SuperBuilder +@NoArgsConstructor +public class StudentLessonFinalNoteUpdateRequest implements Serializable { + + @Serial + private static final long serialVersionUID = -1731196715166066519L; + + @NotNull + private String id; + + @NotNull + private Double finalNote; + + @Valid + private SisOperationInfoRequest operationInfoRequest; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/dto/request/StudentLessonMidtermNoteUpdateRequest.java b/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/dto/request/StudentLessonMidtermNoteUpdateRequest.java new file mode 100644 index 00000000..7fbcb329 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/dto/request/StudentLessonMidtermNoteUpdateRequest.java @@ -0,0 +1,29 @@ +package com.graduationproject.studentinformationsystem.university.note.model.dto.request; + +import com.graduationproject.studentinformationsystem.common.model.dto.request.SisOperationInfoRequest; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +import javax.validation.Valid; +import javax.validation.constraints.NotNull; +import java.io.Serial; +import java.io.Serializable; + +@Getter +@SuperBuilder +@NoArgsConstructor +public class StudentLessonMidtermNoteUpdateRequest implements Serializable { + + @Serial + private static final long serialVersionUID = 7596735869510130790L; + + @NotNull + private String id; + + @NotNull + private Double midtermNote; + + @Valid + private SisOperationInfoRequest operationInfoRequest; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/dto/request/StudentLessonNoteSaveRequest.java b/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/dto/request/StudentLessonNoteSaveRequest.java new file mode 100644 index 00000000..ada0d149 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/dto/request/StudentLessonNoteSaveRequest.java @@ -0,0 +1,36 @@ +package com.graduationproject.studentinformationsystem.university.note.model.dto.request; + +import com.graduationproject.studentinformationsystem.common.model.dto.request.SisOperationInfoRequest; +import com.graduationproject.studentinformationsystem.common.util.validation.id.LessonID; +import com.graduationproject.studentinformationsystem.common.util.validation.id.StudentID; +import com.graduationproject.studentinformationsystem.common.util.validation.id.TeacherID; +import lombok.Getter; +import lombok.experimental.SuperBuilder; + +import javax.validation.Valid; +import javax.validation.constraints.NotNull; +import java.io.Serial; +import java.io.Serializable; + +@Getter +@SuperBuilder +public class StudentLessonNoteSaveRequest implements Serializable { + + @Serial + private static final long serialVersionUID = -7246638446202788931L; + + @NotNull + @TeacherID + private Long teacherId; + + @NotNull + @StudentID + private Long studentId; + + @NotNull + @LessonID + private Long lessonId; + + @Valid + private SisOperationInfoRequest operationInfoRequest; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/dto/request/StudentLessonResitNoteUpdateRequest.java b/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/dto/request/StudentLessonResitNoteUpdateRequest.java new file mode 100644 index 00000000..8da009f1 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/dto/request/StudentLessonResitNoteUpdateRequest.java @@ -0,0 +1,29 @@ +package com.graduationproject.studentinformationsystem.university.note.model.dto.request; + +import com.graduationproject.studentinformationsystem.common.model.dto.request.SisOperationInfoRequest; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.experimental.SuperBuilder; + +import javax.validation.Valid; +import javax.validation.constraints.NotNull; +import java.io.Serial; +import java.io.Serializable; + +@Getter +@SuperBuilder +@NoArgsConstructor +public class StudentLessonResitNoteUpdateRequest implements Serializable { + + @Serial + private static final long serialVersionUID = -6303107915064579379L; + + @NotNull + private String id; + + @NotNull + private Double resitNote; + + @Valid + private SisOperationInfoRequest operationInfoRequest; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/dto/response/StudentLessonNoteResponse.java b/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/dto/response/StudentLessonNoteResponse.java new file mode 100644 index 00000000..35a0b505 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/dto/response/StudentLessonNoteResponse.java @@ -0,0 +1,25 @@ +package com.graduationproject.studentinformationsystem.university.note.model.dto.response; + +import com.graduationproject.studentinformationsystem.common.model.dto.response.SisBaseResponse; +import com.graduationproject.studentinformationsystem.university.lesson.common.model.dto.response.LessonResponse; +import com.graduationproject.studentinformationsystem.university.note.model.enums.StudentLessonNoteStatus; +import com.graduationproject.studentinformationsystem.university.student.model.dto.response.StudentInfoResponse; +import com.graduationproject.studentinformationsystem.university.teacher.model.dto.response.TeacherInfoResponse; +import lombok.Getter; +import lombok.experimental.SuperBuilder; + +@Getter +@SuperBuilder +public class StudentLessonNoteResponse extends SisBaseResponse { + + private String id; + private Double midtermNote; + private Double finalNote; + private Double resitNote; + private Double meanOfNote; + private StudentLessonNoteStatus status; + + private TeacherInfoResponse teacherResponse; + private StudentInfoResponse studentResponse; + private LessonResponse lessonResponse; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/entity/StudentLessonFinalNoteUpdateEntity.java b/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/entity/StudentLessonFinalNoteUpdateEntity.java new file mode 100644 index 00000000..0d05cf52 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/entity/StudentLessonFinalNoteUpdateEntity.java @@ -0,0 +1,19 @@ +package com.graduationproject.studentinformationsystem.university.note.model.entity; + +import com.graduationproject.studentinformationsystem.university.note.model.enums.StudentLessonNoteStatus; +import lombok.Builder; +import lombok.Getter; + +import java.util.Date; + +@Getter +@Builder +public class StudentLessonFinalNoteUpdateEntity { + + private String id; + private Double finalNote; + private Double meanOfNote; + private StudentLessonNoteStatus status; + private Long modifiedUserId; + private Date modifiedDate; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/entity/StudentLessonMidtermNoteUpdateEntity.java b/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/entity/StudentLessonMidtermNoteUpdateEntity.java new file mode 100644 index 00000000..38228f60 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/entity/StudentLessonMidtermNoteUpdateEntity.java @@ -0,0 +1,16 @@ +package com.graduationproject.studentinformationsystem.university.note.model.entity; + +import lombok.Builder; +import lombok.Getter; + +import java.util.Date; + +@Getter +@Builder +public class StudentLessonMidtermNoteUpdateEntity { + + private String id; + private Double midtermNote; + private Long modifiedUserId; + private Date modifiedDate; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/entity/StudentLessonNoteEntity.java b/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/entity/StudentLessonNoteEntity.java new file mode 100644 index 00000000..0366b5b8 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/entity/StudentLessonNoteEntity.java @@ -0,0 +1,21 @@ +package com.graduationproject.studentinformationsystem.university.note.model.entity; + +import com.graduationproject.studentinformationsystem.common.model.entity.SisBaseEntity; +import com.graduationproject.studentinformationsystem.university.note.model.enums.StudentLessonNoteStatus; +import lombok.Getter; +import lombok.experimental.SuperBuilder; + +@Getter +@SuperBuilder +public class StudentLessonNoteEntity extends SisBaseEntity { + + private String id; + private Long teacherId; + private Long studentId; + private Long lessonId; + private Double midtermNote; + private Double finalNote; + private Double resitNote; + private Double meanOfNote; + private StudentLessonNoteStatus status; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/entity/StudentLessonNoteSaveEntity.java b/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/entity/StudentLessonNoteSaveEntity.java new file mode 100644 index 00000000..6e3e0f8d --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/entity/StudentLessonNoteSaveEntity.java @@ -0,0 +1,20 @@ +package com.graduationproject.studentinformationsystem.university.note.model.entity; + +import com.graduationproject.studentinformationsystem.university.note.model.enums.StudentLessonNoteStatus; +import lombok.Builder; +import lombok.Getter; + +import java.util.Date; + +@Getter +@Builder +public class StudentLessonNoteSaveEntity { + + private String id; + private Long teacherId; + private Long studentId; + private Long lessonId; + private StudentLessonNoteStatus status; + private Long createdUserId; + private Date createdDate; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/entity/StudentLessonResitNoteUpdateEntity.java b/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/entity/StudentLessonResitNoteUpdateEntity.java new file mode 100644 index 00000000..30146ba3 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/entity/StudentLessonResitNoteUpdateEntity.java @@ -0,0 +1,19 @@ +package com.graduationproject.studentinformationsystem.university.note.model.entity; + +import com.graduationproject.studentinformationsystem.university.note.model.enums.StudentLessonNoteStatus; +import lombok.Builder; +import lombok.Getter; + +import java.util.Date; + +@Getter +@Builder +public class StudentLessonResitNoteUpdateEntity { + + private String id; + private Double resitNote; + private Double meanOfNote; + private StudentLessonNoteStatus status; + private Long modifiedUserId; + private Date modifiedDate; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/enums/StudentLessonNoteStatus.java b/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/enums/StudentLessonNoteStatus.java new file mode 100644 index 00000000..78e30e4a --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/enums/StudentLessonNoteStatus.java @@ -0,0 +1,15 @@ +package com.graduationproject.studentinformationsystem.university.note.model.enums; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +@Getter +@RequiredArgsConstructor +public enum StudentLessonNoteStatus { + + UNFINALISED("Sonuçlandırılmadı"), + PASSED("Geçti"), + FAILED("Kaldı"); + + private final String tr; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/exception/StudentLessonNoteException.java b/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/exception/StudentLessonNoteException.java new file mode 100644 index 00000000..9dc5ac7d --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/exception/StudentLessonNoteException.java @@ -0,0 +1,16 @@ +package com.graduationproject.studentinformationsystem.university.note.model.exception; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisException; +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class StudentLessonNoteException extends SisException { + + private StudentLessonNoteException() { + } + + public static void throwNotExistException(final String id) throws SisNotExistException { + SisException.throwNotExistException("STUDENT LESSON NOTES ARE NOT EXIST! id:" + id); + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/mapping/StudentLessonNoteMapping.java b/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/mapping/StudentLessonNoteMapping.java new file mode 100644 index 00000000..235b681f --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/note/model/mapping/StudentLessonNoteMapping.java @@ -0,0 +1,33 @@ +package com.graduationproject.studentinformationsystem.university.note.model.mapping; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +@Getter +@RequiredArgsConstructor +public enum StudentLessonNoteMapping { + + ID("ID", "id"), + TEACHER_ID("TEACHER_ID", "teacherId"), + STUDENT_ID("STUDENT_ID", "studentId"), + LESSON_ID("LESSON_ID", "lessonId"), + MIDTERM_NOTE("MIDTERM_NOTE", "midtermNote"), + FINAL_NOTE("FINAL_NOTE", "finalNote"), + RESIT_NOTE("RESIT_NOTE", "resitNote"), + MEAN_OF_NOTE("MEAN_OF_NOTE", "meanOfNote"), + STATUS("STATUS", "status"), + CREATED_DATE("CREATED_DATE", "createdDate"), + CREATED_USER_ID("CREATED_USER_ID", "createdUserId"), + MODIFIED_DATE("MODIFIED_DATE", "modifiedDate"), + MODIFIED_USER_ID("MODIFIED_USER_ID", "modifiedUserId"); + + private final String columnName; + private final String modelName; + + public static final Map COLUMN_MAPPINGS = Stream.of(values()) + .collect(Collectors.toMap(StudentLessonNoteMapping::getColumnName, StudentLessonNoteMapping::getModelName)); +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/note/repository/StudentLessonNoteRepository.java b/src/main/java/com/graduationproject/studentinformationsystem/university/note/repository/StudentLessonNoteRepository.java new file mode 100644 index 00000000..2943e42a --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/note/repository/StudentLessonNoteRepository.java @@ -0,0 +1,26 @@ +package com.graduationproject.studentinformationsystem.university.note.repository; + +import com.graduationproject.studentinformationsystem.university.note.model.entity.*; + +import java.util.List; + +public interface StudentLessonNoteRepository { + + List getAllStudentsLessonsNotesByLessonId(Long lessonId); + + List getAllStudentLessonsNotesByStudentId(Long studentId); + + StudentLessonNoteEntity getStudentLessonNotesById(String id); + + void saveStudentLessonNote(StudentLessonNoteSaveEntity saveEntity); + + void updateStudentLessonMidtermNote(StudentLessonMidtermNoteUpdateEntity updateEntity); + + void updateStudentLessonFinalNote(StudentLessonFinalNoteUpdateEntity updateEntity); + + void updateStudentLessonResitNote(StudentLessonResitNoteUpdateEntity updateEntity); + + Double getMidtermNoteById(String id); + + boolean isStudentLessonNotesExist(String id); +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/note/repository/impl/StudentLessonNoteRepositoryImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/note/repository/impl/StudentLessonNoteRepositoryImpl.java new file mode 100644 index 00000000..5277c566 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/note/repository/impl/StudentLessonNoteRepositoryImpl.java @@ -0,0 +1,205 @@ +package com.graduationproject.studentinformationsystem.university.note.repository.impl; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisDatabaseException; +import com.graduationproject.studentinformationsystem.common.util.log.SisErrorLogMessageUtil; +import com.graduationproject.studentinformationsystem.common.util.log.SisInfoLogMessageUtil; +import com.graduationproject.studentinformationsystem.common.util.log.SisWarnLogMessageUtil; +import com.graduationproject.studentinformationsystem.university.note.model.entity.*; +import com.graduationproject.studentinformationsystem.university.note.repository.StudentLessonNoteRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; +import org.sql2o.Connection; +import org.sql2o.Query; +import org.sql2o.Sql2o; + +import java.util.List; + +import static com.graduationproject.studentinformationsystem.university.note.model.mapping.StudentLessonNoteMapping.*; +import static com.graduationproject.studentinformationsystem.university.note.repository.impl.scripts.StudentLessonNoteSqlScripts.*; + +@Repository +@RequiredArgsConstructor +public class StudentLessonNoteRepositoryImpl implements StudentLessonNoteRepository { + + private static final String STUDENT_LESSON_NOTE = "Student Lesson Note"; + private final SisInfoLogMessageUtil info = SisInfoLogMessageUtil.builder().apiName(STUDENT_LESSON_NOTE).build(); + private final SisWarnLogMessageUtil warn = SisWarnLogMessageUtil.builder().apiName(STUDENT_LESSON_NOTE).build(); + private final SisErrorLogMessageUtil error = SisErrorLogMessageUtil.builder().apiName(STUDENT_LESSON_NOTE).build(); + + private final Sql2o sql2o; + + @Override + public List getAllStudentsLessonsNotesByLessonId(final Long lessonId) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(GET_ALL_STUDENTS_LESSON_NOTES_BY_LESSON_ID)) { + + final List noteEntities = query + .addParameter(LESSON_ID.getModelName(), lessonId) + .setColumnMappings(COLUMN_MAPPINGS) + .executeAndFetch(StudentLessonNoteEntity.class); + + if (!noteEntities.isEmpty()) { + info.foundAllByLessonId(lessonId); + } else { + warn.notFoundAllByLessonId(lessonId); + } + return noteEntities; + } catch (Exception exception) { + error.errorWhenGettingAllByLessonId(lessonId); + throw new SisDatabaseException(exception); + } + } + + @Override + public List getAllStudentLessonsNotesByStudentId(final Long studentId) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(GET_ALL_STUDENT_LESSONS_NOTES_BY_STUDENT_ID)) { + + final List noteEntities = query + .addParameter(STUDENT_ID.getModelName(), studentId) + .setColumnMappings(COLUMN_MAPPINGS) + .executeAndFetch(StudentLessonNoteEntity.class); + + if (!noteEntities.isEmpty()) { + info.foundAllByStudentId(studentId); + } else { + warn.notFoundAllByStudentId(studentId); + } + return noteEntities; + } catch (Exception exception) { + error.errorWhenGettingAllByStudentId(studentId); + throw new SisDatabaseException(exception); + } + } + + @Override + public StudentLessonNoteEntity getStudentLessonNotesById(final String id) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(GET_STUDENT_LESSON_NOTES_BY_ID)) { + + final StudentLessonNoteEntity noteEntity = query + .addParameter(ID.getModelName(), id) + .setColumnMappings(COLUMN_MAPPINGS) + .executeAndFetchFirst(StudentLessonNoteEntity.class); + + if (noteEntity != null) { + info.foundById(id); + } else { + warn.notFoundById(id); + } + return noteEntity; + } catch (Exception exception) { + error.errorWhenGettingById(id); + throw new SisDatabaseException(exception); + } + } + + @Override + public void saveStudentLessonNote(final StudentLessonNoteSaveEntity saveEntity) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(SAVE_STUDENT_LESSON_NOTE)) { + + query.addParameter(ID.getModelName(), saveEntity.getId()) + .addParameter(TEACHER_ID.getModelName(), saveEntity.getTeacherId()) + .addParameter(STUDENT_ID.getModelName(), saveEntity.getStudentId()) + .addParameter(LESSON_ID.getModelName(), saveEntity.getLessonId()) + .addParameter(STATUS.getModelName(), saveEntity.getStatus()) + .addParameter(CREATED_DATE.getModelName(), saveEntity.getCreatedDate()) + .addParameter(CREATED_USER_ID.getModelName(), saveEntity.getCreatedUserId()) + .executeUpdate(); + + } catch (Exception exception) { + error.errorWhenSaving(); + throw new SisDatabaseException(exception); + } + } + + @Override + public void updateStudentLessonMidtermNote(final StudentLessonMidtermNoteUpdateEntity updateEntity) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(UPDATE_STUDENT_LESSON_MIDTERM_NOTE)) { + + query.addParameter(ID.getModelName(), updateEntity.getId()) + .addParameter(MIDTERM_NOTE.getModelName(), updateEntity.getMidtermNote()) + .addParameter(MODIFIED_DATE.getModelName(), updateEntity.getModifiedDate()) + .addParameter(MODIFIED_USER_ID.getModelName(), updateEntity.getModifiedUserId()) + .executeUpdate(); + + } catch (Exception exception) { + error.errorWhenUpdating(); + throw new SisDatabaseException(exception); + } + } + + @Override + public void updateStudentLessonFinalNote(final StudentLessonFinalNoteUpdateEntity updateEntity) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(UPDATE_STUDENT_LESSON_FINAL_AND_MEAN_OF_NOTES)) { + + query.addParameter(ID.getModelName(), updateEntity.getId()) + .addParameter(FINAL_NOTE.getModelName(), updateEntity.getFinalNote()) + .addParameter(MEAN_OF_NOTE.getModelName(), updateEntity.getMeanOfNote()) + .addParameter(STATUS.getModelName(), updateEntity.getStatus()) + .addParameter(MODIFIED_DATE.getModelName(), updateEntity.getModifiedDate()) + .addParameter(MODIFIED_USER_ID.getModelName(), updateEntity.getModifiedUserId()) + .executeUpdate(); + + } catch (Exception exception) { + error.errorWhenUpdating(); + throw new SisDatabaseException(exception); + } + } + + @Override + public void updateStudentLessonResitNote(final StudentLessonResitNoteUpdateEntity updateEntity) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(UPDATE_STUDENT_LESSON_RESIT_AND_MEAN_OF_NOTES)) { + + query.addParameter(ID.getModelName(), updateEntity.getId()) + .addParameter(RESIT_NOTE.getModelName(), updateEntity.getResitNote()) + .addParameter(MEAN_OF_NOTE.getModelName(), updateEntity.getMeanOfNote()) + .addParameter(STATUS.getModelName(), updateEntity.getStatus()) + .addParameter(MODIFIED_DATE.getModelName(), updateEntity.getModifiedDate()) + .addParameter(MODIFIED_USER_ID.getModelName(), updateEntity.getModifiedUserId()) + .executeUpdate(); + + } catch (Exception exception) { + error.errorWhenUpdating(); + throw new SisDatabaseException(exception); + } + } + + @Override + public Double getMidtermNoteById(final String id) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(GET_MIDTERM_NOTE_BY_ID)) { + + final Double midtermNote = query + .addParameter(ID.getModelName(), id) + .setColumnMappings(COLUMN_MAPPINGS) + .executeScalar(Double.class); + + if (midtermNote != null) { + info.foundById(id); + } else { + warn.notFoundById(id); + } + return midtermNote; + } catch (Exception exception) { + error.errorWhenGettingById(id); + throw new SisDatabaseException(exception); + } + } + + @Override + public boolean isStudentLessonNotesExist(final String id) { + try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(IS_STUDENT_LESSON_NOTES_EXIST_BY_ID)) { + + final boolean isStudentLessonNotesExist = query.addParameter(ID.getModelName(), id) + .executeAndFetchFirst(Boolean.class); + + if (isStudentLessonNotesExist) { + info.foundById(id); + return true; + } else { + warn.notFoundById(id); + return false; + } + } catch (Exception exception) { + error.errorWhenGettingById(id); + throw new SisDatabaseException(exception); + } + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/note/repository/impl/scripts/StudentLessonNoteSqlScripts.java b/src/main/java/com/graduationproject/studentinformationsystem/university/note/repository/impl/scripts/StudentLessonNoteSqlScripts.java new file mode 100644 index 00000000..98f4708b --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/note/repository/impl/scripts/StudentLessonNoteSqlScripts.java @@ -0,0 +1,113 @@ +package com.graduationproject.studentinformationsystem.university.note.repository.impl.scripts; + +import com.graduationproject.studentinformationsystem.common.util.sql.SisSqlUtil; + +import static com.graduationproject.studentinformationsystem.university.note.model.mapping.StudentLessonNoteMapping.ID; + +public class StudentLessonNoteSqlScripts { + + private static final StringBuilder sqlBuilder = new StringBuilder(); + + private StudentLessonNoteSqlScripts() { + } + + /** + * SELECT ID, TEACHER_ID, STUDENT_ID, LESSON_ID, MIDTERM_NOTE, FINAL_NOTE, RESIT_NOTE, MEAN_OF_NOTE, STATUS, + * CREATED_DATE, CREATED_USER_ID, MODIFIED_DATE, MODIFIED_USER_ID FROM STUDENT_LESSON_NOTE; + */ + private static final String GET_ALL_STUDENTS_LESSONS_NOTES = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("SELECT ID, TEACHER_ID, STUDENT_ID, LESSON_ID, MIDTERM_NOTE, FINAL_NOTE, " + + "RESIT_NOTE, MEAN_OF_NOTE, STATUS, " + + "CREATED_DATE, CREATED_USER_ID, MODIFIED_DATE, MODIFIED_USER_ID " + + "FROM STUDENT_LESSON_NOTE ").toString(); + + /** + * SELECT ID, TEACHER_ID, STUDENT_ID, LESSON_ID, MIDTERM_NOTE, FINAL_NOTE, RESIT_NOTE, MEAN_OF_NOTE, STATUS, + * CREATED_DATE, CREATED_USER_ID, MODIFIED_DATE, MODIFIED_USER_ID FROM STUDENT_LESSON_NOTE + * WHERE LESSON_ID=:lessonId; + */ + public static final String GET_ALL_STUDENTS_LESSON_NOTES_BY_LESSON_ID = + sqlBuilder.delete(0, sqlBuilder.length()) + .append(GET_ALL_STUDENTS_LESSONS_NOTES) + .append("WHERE LESSON_ID=:lessonId").toString(); + + /** + * SELECT ID, TEACHER_ID, STUDENT_ID, LESSON_ID, MIDTERM_NOTE, FINAL_NOTE, RESIT_NOTE, MEAN_OF_NOTE, STATUS, + * CREATED_DATE, CREATED_USER_ID, MODIFIED_DATE, MODIFIED_USER_ID FROM STUDENT_LESSON_NOTE + * WHERE STUDENT_ID=:studentId; + */ + public static final String GET_ALL_STUDENT_LESSONS_NOTES_BY_STUDENT_ID = + sqlBuilder.delete(0, sqlBuilder.length()) + .append(GET_ALL_STUDENTS_LESSONS_NOTES) + .append("WHERE STUDENT_ID=:studentId").toString(); + + /** + * SELECT ID, TEACHER_ID, STUDENT_ID, LESSON_ID, MIDTERM_NOTE, FINAL_NOTE, RESIT_NOTE, MEAN_OF_NOTE, STATUS, + * CREATED_DATE, CREATED_USER_ID, MODIFIED_DATE, MODIFIED_USER_ID FROM STUDENT_LESSON_NOTE + * WHERE LESSON_ID=:lessonId; + */ + public static final String GET_STUDENT_LESSON_NOTES_BY_ID = + sqlBuilder.delete(0, sqlBuilder.length()) + .append(GET_ALL_STUDENTS_LESSONS_NOTES) + .append("WHERE ID=:id").toString(); + + /** + * INSERT INTO STUDENT_LESSON_NOTE (ID, TEACHER_ID, STUDENT_ID, LESSON_ID, STATUS, CREATED_DATE, CREATED_USER_ID) + * VALUES (:id, :teacherId, :studentId, :lessonId, :status, :createdDate, :createdUserId); + */ + public static final String SAVE_STUDENT_LESSON_NOTE = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("INSERT INTO STUDENT_LESSON_NOTE (ID, TEACHER_ID, STUDENT_ID, LESSON_ID, STATUS, " + + "CREATED_DATE, CREATED_USER_ID) VALUES (:id, :teacherId, :studentId, :lessonId, :status, " + + ":createdDate, :createdUserId)").toString(); + + /** + * UPDATE STUDENT_LESSON_NOTE SET MIDTERM_NOTE=:midtermNote, + * MODIFIED_DATE=:modifiedDate, MODIFIED_USER_ID=:modifiedUserId + * WHERE ID=:id; + */ + public static final String UPDATE_STUDENT_LESSON_MIDTERM_NOTE = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("UPDATE STUDENT_LESSON_NOTE SET MIDTERM_NOTE=:midtermNote, " + + "MODIFIED_DATE=:modifiedDate, MODIFIED_USER_ID=:modifiedUserId " + + "WHERE ID=:id").toString(); + + /** + * UPDATE STUDENT_LESSON_NOTE SET FINAL_NOTE=:finalNote, MEAN_OF_NOTE=:meanOfNote, STATUS=:status, + * MODIFIED_DATE=:modifiedDate, MODIFIED_USER_ID=:modifiedUserId + * WHERE ID=:id; + */ + public static final String UPDATE_STUDENT_LESSON_FINAL_AND_MEAN_OF_NOTES = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("UPDATE STUDENT_LESSON_NOTE SET FINAL_NOTE=:finalNote, MEAN_OF_NOTE=:meanOfNote, " + + "STATUS=:status, MODIFIED_DATE=:modifiedDate, MODIFIED_USER_ID=:modifiedUserId " + + "WHERE ID=:id").toString(); + + /** + * UPDATE STUDENT_LESSON_NOTE SET RESIT_NOTE=:resitNote, MEAN_OF_NOTE=:meanOfNote, STATUS=:status, + * MODIFIED_DATE=:modifiedDate, MODIFIED_USER_ID=:modifiedUserId + * WHERE ID=:id; + */ + public static final String UPDATE_STUDENT_LESSON_RESIT_AND_MEAN_OF_NOTES = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("UPDATE STUDENT_LESSON_NOTE SET RESIT_NOTE=:resitNote, MEAN_OF_NOTE=:meanOfNote, " + + "STATUS=:status, MODIFIED_DATE=:modifiedDate, MODIFIED_USER_ID=:modifiedUserId " + + "WHERE ID=:id").toString(); + + /** + * SELECT CASE WHEN MAX(ID) IS NULL THEN 'false' ELSE 'true' END IS_EXIST + * FROM STUDENT_LESSON_NOTE WHERE ID=:id; + */ + public static final String IS_STUDENT_LESSON_NOTES_EXIST_BY_ID = SisSqlUtil + .isExistByColumnName("STUDENT_LESSON_NOTE", + ID.getColumnName(), + ID.getModelName()); + + /** + * SELECT MIDTERM_NOTE FROM STUDENT_LESSON_NOTE WHERE ID=:id; + */ + public static final String GET_MIDTERM_NOTE_BY_ID = + sqlBuilder.delete(0, sqlBuilder.length()) + .append("SELECT MIDTERM_NOTE FROM STUDENT_LESSON_NOTE WHERE ID=:id").toString(); +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/note/service/StudentLessonNoteOutService.java b/src/main/java/com/graduationproject/studentinformationsystem/university/note/service/StudentLessonNoteOutService.java new file mode 100644 index 00000000..323a3db3 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/note/service/StudentLessonNoteOutService.java @@ -0,0 +1,13 @@ +package com.graduationproject.studentinformationsystem.university.note.service; + +import com.graduationproject.studentinformationsystem.common.model.dto.request.SisOperationInfoRequest; +import com.graduationproject.studentinformationsystem.university.lesson.common.model.dto.response.LessonResponse; + +import java.util.List; + +public interface StudentLessonNoteOutService { + + void saveStudentLessonsNotesRegistrations(Long studentId, + List lessonResponses, + SisOperationInfoRequest operationInfoRequest); +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/note/service/StudentLessonNoteService.java b/src/main/java/com/graduationproject/studentinformationsystem/university/note/service/StudentLessonNoteService.java new file mode 100644 index 00000000..86440378 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/note/service/StudentLessonNoteService.java @@ -0,0 +1,22 @@ +package com.graduationproject.studentinformationsystem.university.note.service; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.university.note.model.dto.request.StudentLessonFinalNoteUpdateRequest; +import com.graduationproject.studentinformationsystem.university.note.model.dto.request.StudentLessonMidtermNoteUpdateRequest; +import com.graduationproject.studentinformationsystem.university.note.model.dto.request.StudentLessonResitNoteUpdateRequest; +import com.graduationproject.studentinformationsystem.university.note.model.dto.response.StudentLessonNoteResponse; + +import java.util.List; + +public interface StudentLessonNoteService { + + List getAllStudentsLessonsNotesByLessonId(Long lessonId) throws SisNotExistException; + + List getAllStudentLessonsNotesByStudentId(Long studentId) throws SisNotExistException; + + StudentLessonNoteResponse updateStudentLessonMidtermNote(StudentLessonMidtermNoteUpdateRequest updateRequest) throws SisNotExistException; + + StudentLessonNoteResponse updateStudentLessonFinalNote(StudentLessonFinalNoteUpdateRequest updateRequest) throws SisNotExistException; + + StudentLessonNoteResponse updateStudentLessonResitNote(StudentLessonResitNoteUpdateRequest updateRequest) throws SisNotExistException; +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/note/service/impl/StudentLessonNoteOutServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/note/service/impl/StudentLessonNoteOutServiceImpl.java new file mode 100644 index 00000000..216054f1 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/note/service/impl/StudentLessonNoteOutServiceImpl.java @@ -0,0 +1,45 @@ +package com.graduationproject.studentinformationsystem.university.note.service.impl; + +import com.graduationproject.studentinformationsystem.common.model.dto.request.SisOperationInfoRequest; +import com.graduationproject.studentinformationsystem.university.lesson.common.model.dto.response.LessonResponse; +import com.graduationproject.studentinformationsystem.university.lesson.teacher.service.TeacherLessonOutService; +import com.graduationproject.studentinformationsystem.university.note.model.dto.converter.StudentLessonNoteInfoConverter; +import com.graduationproject.studentinformationsystem.university.note.model.dto.request.StudentLessonNoteSaveRequest; +import com.graduationproject.studentinformationsystem.university.note.model.entity.StudentLessonNoteSaveEntity; +import com.graduationproject.studentinformationsystem.university.note.repository.StudentLessonNoteRepository; +import com.graduationproject.studentinformationsystem.university.note.service.StudentLessonNoteOutService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +@RequiredArgsConstructor +public class StudentLessonNoteOutServiceImpl implements StudentLessonNoteOutService { + + private final TeacherLessonOutService teacherLessonOutService; + + private final StudentLessonNoteRepository lessonNoteRepository; + private final StudentLessonNoteInfoConverter lessonNoteInfoConverter; + + @Override + public void saveStudentLessonsNotesRegistrations(final Long studentId, + final List lessonResponses, + final SisOperationInfoRequest operationInfoRequest) { + + for (LessonResponse lessonResponse : lessonResponses) { + final Long lessonId = lessonResponse.getLessonId(); + final Long teacherId = teacherLessonOutService.getTeacherIdByLessonId(lessonId); + + StudentLessonNoteSaveRequest saveRequest = StudentLessonNoteSaveRequest.builder() + .teacherId(teacherId) + .studentId(studentId) + .lessonId(lessonId) + .operationInfoRequest(operationInfoRequest) + .build(); + + final StudentLessonNoteSaveEntity saveEntity = lessonNoteInfoConverter.generateSaveEntity(saveRequest); + lessonNoteRepository.saveStudentLessonNote(saveEntity); + } + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/note/service/impl/StudentLessonNoteServiceImpl.java b/src/main/java/com/graduationproject/studentinformationsystem/university/note/service/impl/StudentLessonNoteServiceImpl.java new file mode 100644 index 00000000..a36bf889 --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/note/service/impl/StudentLessonNoteServiceImpl.java @@ -0,0 +1,174 @@ +package com.graduationproject.studentinformationsystem.university.note.service.impl; + +import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException; +import com.graduationproject.studentinformationsystem.university.lesson.common.service.LessonOutService; +import com.graduationproject.studentinformationsystem.university.note.model.dto.converter.StudentLessonNoteInfoConverter; +import com.graduationproject.studentinformationsystem.university.note.model.dto.request.StudentLessonFinalNoteUpdateRequest; +import com.graduationproject.studentinformationsystem.university.note.model.dto.request.StudentLessonMidtermNoteUpdateRequest; +import com.graduationproject.studentinformationsystem.university.note.model.dto.request.StudentLessonResitNoteUpdateRequest; +import com.graduationproject.studentinformationsystem.university.note.model.dto.response.StudentLessonNoteResponse; +import com.graduationproject.studentinformationsystem.university.note.model.entity.StudentLessonFinalNoteUpdateEntity; +import com.graduationproject.studentinformationsystem.university.note.model.entity.StudentLessonMidtermNoteUpdateEntity; +import com.graduationproject.studentinformationsystem.university.note.model.entity.StudentLessonNoteEntity; +import com.graduationproject.studentinformationsystem.university.note.model.entity.StudentLessonResitNoteUpdateEntity; +import com.graduationproject.studentinformationsystem.university.note.model.enums.StudentLessonNoteStatus; +import com.graduationproject.studentinformationsystem.university.note.model.exception.StudentLessonNoteException; +import com.graduationproject.studentinformationsystem.university.note.repository.StudentLessonNoteRepository; +import com.graduationproject.studentinformationsystem.university.note.service.StudentLessonNoteService; +import com.graduationproject.studentinformationsystem.university.student.service.StudentOutService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +@RequiredArgsConstructor +public class StudentLessonNoteServiceImpl implements StudentLessonNoteService { + + private final LessonOutService lessonOutService; + private final StudentOutService studentOutService; + + private final StudentLessonNoteRepository lessonNoteRepository; + private final StudentLessonNoteInfoConverter lessonNoteInfoConverter; + + @Override + public List getAllStudentsLessonsNotesByLessonId(final Long lessonId) + throws SisNotExistException { + + ifLessonIsNotExistThrowNotExistException(lessonId); + + final List entities = lessonNoteRepository.getAllStudentsLessonsNotesByLessonId(lessonId); + return lessonNoteInfoConverter.entitiesToResponses(entities); + } + + @Override + public List getAllStudentLessonsNotesByStudentId(final Long studentId) + throws SisNotExistException { + + ifStudentIsNotExistThrowNotExistException(studentId); + + final List entities = lessonNoteRepository.getAllStudentLessonsNotesByStudentId(studentId); + return lessonNoteInfoConverter.entitiesToResponses(entities); + } + + @Override + public StudentLessonNoteResponse updateStudentLessonMidtermNote(final StudentLessonMidtermNoteUpdateRequest updateRequest) + throws SisNotExistException { + + final String id = updateRequest.getId(); + + ifStudentLessonNotesAreNotExistThrowNotExistException(id); + + final StudentLessonMidtermNoteUpdateEntity noteUpdateEntity = lessonNoteInfoConverter + .generateMidtermNoteUpdateEntity(updateRequest); + + lessonNoteRepository.updateStudentLessonMidtermNote(noteUpdateEntity); + + return getStudentLessonNoteById(id); + } + + @Override + public StudentLessonNoteResponse updateStudentLessonFinalNote(final StudentLessonFinalNoteUpdateRequest updateRequest) + throws SisNotExistException { + + final String id = updateRequest.getId(); + + ifStudentLessonNotesAreNotExistThrowNotExistException(id); + + final Double midtermNote = lessonNoteRepository.getMidtermNoteById(id); + + Double meanOfNote; + StudentLessonNoteStatus status; + + final Double finalNote = updateRequest.getFinalNote(); + if (finalNote >= 50.0) { + + meanOfNote = calculateMeanOfNoteWithFinalNote(midtermNote, finalNote); + + if (meanOfNote >= 60.0) { + status = StudentLessonNoteStatus.PASSED; + } else { + status = StudentLessonNoteStatus.UNFINALISED; + } + } else { + meanOfNote = calculateMeanOfNoteWithFinalNote(midtermNote, finalNote); + status = StudentLessonNoteStatus.UNFINALISED; + } + + final StudentLessonFinalNoteUpdateEntity noteUpdateEntity = lessonNoteInfoConverter + .generateFinalNoteUpdateEntity(meanOfNote, status, updateRequest); + + lessonNoteRepository.updateStudentLessonFinalNote(noteUpdateEntity); + + return getStudentLessonNoteById(id); + } + + @Override + public StudentLessonNoteResponse updateStudentLessonResitNote(final StudentLessonResitNoteUpdateRequest updateRequest) + throws SisNotExistException { + + final String id = updateRequest.getId(); + + ifStudentLessonNotesAreNotExistThrowNotExistException(id); + + final Double midtermNote = lessonNoteRepository.getMidtermNoteById(id); + + Double meanOfNote; + StudentLessonNoteStatus status; + + final Double resitNote = updateRequest.getResitNote(); + if (resitNote >= 50.0) { + + meanOfNote = calculateMeanOfNoteWithResitNote(midtermNote, resitNote); + + if (meanOfNote >= 60.0) { + status = StudentLessonNoteStatus.PASSED; + } else { + status = StudentLessonNoteStatus.FAILED; + } + } else { + meanOfNote = calculateMeanOfNoteWithResitNote(midtermNote, resitNote); + status = StudentLessonNoteStatus.FAILED; + } + + final StudentLessonResitNoteUpdateEntity noteUpdateEntity = lessonNoteInfoConverter + .generateResitNoteUpdateEntity(meanOfNote, status, updateRequest); + + lessonNoteRepository.updateStudentLessonResitNote(noteUpdateEntity); + + return getStudentLessonNoteById(id); + } + + + private StudentLessonNoteResponse getStudentLessonNoteById(final String id) { + final StudentLessonNoteEntity entity = lessonNoteRepository.getStudentLessonNotesById(id); + return lessonNoteInfoConverter.entityToResponse(entity); + } + + protected final Double calculateMeanOfNoteWithFinalNote(final Double midtermNote, Double finalNote) { + return midtermNote * 0.4 + finalNote * 0.6; + } + + protected final Double calculateMeanOfNoteWithResitNote(final Double midtermNote, Double finalNote) { + return midtermNote * 0.4 + finalNote * 0.6; + } + + + /** + * Throw Exceptions + */ + + private void ifLessonIsNotExistThrowNotExistException(final Long lessonId) throws SisNotExistException { + lessonOutService.ifLessonIsNotExistThrowNotExistException(lessonId); + } + + private void ifStudentIsNotExistThrowNotExistException(final Long studentId) throws SisNotExistException { + studentOutService.ifStudentIsNotExistThrowNotExistException(studentId); + } + + private void ifStudentLessonNotesAreNotExistThrowNotExistException(final String id) throws SisNotExistException { + if (!lessonNoteRepository.isStudentLessonNotesExist(id)) { + StudentLessonNoteException.throwNotExistException(id); + } + } +} diff --git a/src/main/java/com/graduationproject/studentinformationsystem/university/note/util/StudentLessonNoteUtil.java b/src/main/java/com/graduationproject/studentinformationsystem/university/note/util/StudentLessonNoteUtil.java new file mode 100644 index 00000000..d2f1a1cd --- /dev/null +++ b/src/main/java/com/graduationproject/studentinformationsystem/university/note/util/StudentLessonNoteUtil.java @@ -0,0 +1,14 @@ +package com.graduationproject.studentinformationsystem.university.note.util; + +public class StudentLessonNoteUtil { + + private StudentLessonNoteUtil() { + } + + public static Double getMeanOfNoteWith2NumberAfterDot(final Double meanOfNote) { + if (meanOfNote != null) { + return Math.floor(meanOfNote * 100) / 100; + } + return null; + } +}