Skip to content

Commit

Permalink
[hotfix] 학생 등록 오류 수정
Browse files Browse the repository at this point in the history
서브 클래스 여러 개 입력시, 500 에러 해결
  • Loading branch information
baekjaehyuk committed Jan 14, 2025
1 parent bc2a64f commit bc70353
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<ClassStudent, Long> {

Page<ClassStudent> findBySubClass_MainClass_IdAndSubClass_Id(Long mainClassId, Long subClassId,
Pageable pageable);
Pageable pageable);

@Modifying
@Query("DELETE FROM ClassStudent cs WHERE cs.student.id = :studentId")
Expand All @@ -26,16 +27,16 @@ Page<ClassStudent> findBySubClass_MainClass_IdAndSubClass_Id(Long mainClassId, L
@Query("SELECT s FROM ClassStudent s WHERE s.subClass.id = :subClassId")
List<ClassStudent> findAllBySubClassId(@Param("subClassId") Long subClassId);

ClassStudent findByStudent(Student student);
List<ClassStudent> findByStudent(Student student);

List<ClassStudent> 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<FindClassStudent> findStudentIdsByMainClassIdAndSubClassId(
@Param("mainClassId") Long mainClassId,
@Param("subClassId") Long subClassId);
@Param("mainClassId") Long mainClassId,
@Param("subClassId") Long subClassId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ClassStudent> 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<Long> studentIds) {
studentIds.stream()
Expand Down Expand Up @@ -155,26 +178,4 @@ private void updateSubClasses(Student student, List<Long> 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);
}
}
}
}

0 comments on commit bc70353

Please sign in to comment.