diff --git a/src/main/java/classfit/example/classfit/auth/security/filter/CustomLoginFilter.java b/src/main/java/classfit/example/classfit/auth/security/filter/CustomLoginFilter.java index 42c41e3d..c52a4ea9 100644 --- a/src/main/java/classfit/example/classfit/auth/security/filter/CustomLoginFilter.java +++ b/src/main/java/classfit/example/classfit/auth/security/filter/CustomLoginFilter.java @@ -52,7 +52,7 @@ protected void successfulAuthentication(HttpServletRequest req, HttpServletRespo CustomAuthenticationToken customAuth = (CustomAuthenticationToken) authResult; String role = customAuth.getAuthorities().iterator().next().getAuthority(); - String accessToken = jwtUtil.createJwt(ACCESS_TOKEN_CATEGORY, customAuth.getEmail(), role, 1000 * 60 * 5L); + String accessToken = jwtUtil.createJwt(ACCESS_TOKEN_CATEGORY, customAuth.getEmail(), role, 1000 * 60 * 60 * 24 * 5L); String refreshToken = jwtUtil.createJwt(REFRESH_TOKEN_CATEGORY, customAuth.getEmail(), role, 1000 * 60 * 60 * 24 * 7L); redisUtil.setDataExpire(REFRESH_TOKEN_CATEGORY + ":" + customAuth.getEmail(), refreshToken, 60 * 60 * 24 * 7L); diff --git a/src/main/java/classfit/example/classfit/classStudent/repository/ClassStudentRepository.java b/src/main/java/classfit/example/classfit/classStudent/repository/ClassStudentRepository.java index a807721e..d8674318 100644 --- a/src/main/java/classfit/example/classfit/classStudent/repository/ClassStudentRepository.java +++ b/src/main/java/classfit/example/classfit/classStudent/repository/ClassStudentRepository.java @@ -4,7 +4,6 @@ import classfit.example.classfit.classStudent.domain.ClassStudent; import classfit.example.classfit.scoreReport.dto.response.FindClassStudent; import classfit.example.classfit.student.domain.Student; -import java.util.List; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; @@ -13,11 +12,13 @@ import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface ClassStudentRepository extends JpaRepository { Page findBySubClass_MainClass_IdAndSubClass_Id(Long mainClassId, Long subClassId, - Pageable pageable); + Pageable pageable); @Modifying @Query("DELETE FROM ClassStudent cs WHERE cs.student.id = :studentId") @@ -26,16 +27,16 @@ Page findBySubClass_MainClass_IdAndSubClass_Id(Long mainClassId, L @Query("SELECT s FROM ClassStudent s WHERE s.subClass.id = :subClassId") List findAllBySubClassId(@Param("subClassId") Long subClassId); - ClassStudent findByStudent(Student student); + List findByStudent(Student student); List findBySubClass(SubClass subClass); @Query("SELECT new classfit.example.classfit.scoreReport.dto.response.FindClassStudent(cs.student.id, cs.student.name) " + - "FROM ClassStudent cs " + - "WHERE cs.subClass.id = :subClassId " + - "AND cs.subClass.mainClass.id = :mainClassId") + "FROM ClassStudent cs " + + "WHERE cs.subClass.id = :subClassId " + + "AND cs.subClass.mainClass.id = :mainClassId") List findStudentIdsByMainClassIdAndSubClassId( - @Param("mainClassId") Long mainClassId, - @Param("subClassId") Long subClassId); + @Param("mainClassId") Long mainClassId, + @Param("subClassId") Long subClassId); } diff --git a/src/main/java/classfit/example/classfit/student/service/StudentService.java b/src/main/java/classfit/example/classfit/student/service/StudentService.java index 4758abf2..46fd2be9 100644 --- a/src/main/java/classfit/example/classfit/student/service/StudentService.java +++ b/src/main/java/classfit/example/classfit/student/service/StudentService.java @@ -57,6 +57,29 @@ public StudentResponse registerStudent(StudentRequest request) { return StudentResponse.from(student); } + private void createAttendanceForThreeWeeks(Student student) { + LocalDate currentDate = LocalDate.now(); + LocalDate weekStart = currentDate.with(DayOfWeek.MONDAY); + List classStudents = classStudentRepository.findByStudent(student); + + classStudents.forEach(classStudent -> { + for (int i = 0; i < 3; i++) { + LocalDate weekDate = weekStart.plusWeeks(i); + for (int j = 0; j < 7; j++) { + LocalDate attendanceDate = weekDate.plusDays(j); + Attendance attendance = Attendance.builder() + .date(attendanceDate) + .week(j) + .status(AttendanceStatus.PRESENT) + .student(student) + .classStudent(classStudent) + .build(); + attendanceRepository.save(attendance); + } + } + }); + } + @Transactional public void deleteStudent(List studentIds) { studentIds.stream() @@ -155,26 +178,4 @@ private void updateSubClasses(Student student, List subClassList) { classStudentRepository.save(classStudent); }); } - - private void createAttendanceForThreeWeeks(Student student) { - LocalDate currentDate = LocalDate.now(); - LocalDate weekStart = currentDate.with(DayOfWeek.MONDAY); - ClassStudent classStudent = classStudentRepository.findByStudent(student); - - // 3주간의 출결 생성 (현재 주 + 향후 2주) - for (int i = 0; i < 3; i++) { - LocalDate weekDate = weekStart.plusWeeks(i); - for (int j = 0; j < 7; j++) { - LocalDate attendanceDate = weekDate.plusDays(j); - Attendance attendance = Attendance.builder() - .date(attendanceDate) - .week(j) - .status(AttendanceStatus.PRESENT) - .student(student) - .classStudent(classStudent) - .build(); - attendanceRepository.save(attendance); - } - } - } } \ No newline at end of file