From abfea56a14d0bc36f071d73c9eaefa3571822218 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=ED=98=B8?= Date: Tue, 23 Dec 2025 09:31:13 +0900 Subject: [PATCH 1/2] =?UTF-8?q?refactor:=20=ED=95=99=EC=83=9D=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=84=B1=EB=8A=A5=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/absence/service/AbsenceService.kt | 8 +- .../domain/approval/entity/ApprovalEntity.kt | 2 +- .../approval/service/ApprovalService.kt | 6 +- .../attendance/entity/AttendanceEntity.kt | 2 +- .../domain/auth/controller/AuthController.kt | 2 +- .../domain/auth/controller/DAuthController.kt | 2 +- .../domain/auth/controller/docs/AuthDocs.kt | 2 +- .../domain/auth/controller/docs/DAuthDocs.kt | 2 +- .../b/beep/domain/auth/service/AuthService.kt | 4 +- .../b/beep/domain/memo/service/MemoService.kt | 4 +- .../domain/scheduling/AttendanceScheduler.kt | 1 - .../controller/ShiftManagementController.kt | 2 +- .../controller/dto/response/ShiftResponse.kt | 2 +- .../b/beep/domain/shift/entity/ShiftEntity.kt | 4 +- .../shift/service/ShiftManagementService.kt | 4 +- .../GetNotAttendedStudentController.kt | 4 +- .../controller/GetStudentController.kt | 4 +- .../docs/GetNotAttendedStudentDocs.kt | 2 +- .../student/controller/docs/GetStudentDocs.kt | 2 +- .../student/controller/dto/StudentQueryDto.kt | 14 +++ .../dto/response/StudentResponse.kt | 53 ++++++-- .../repository/StudentQueryRepository.kt | 117 ++++++++++++++++-- .../service/GetNotAttendedStudentService.kt | 34 ++--- .../student/service/GetStudentService.kt | 27 ++-- .../service/StudentManagementService.kt | 6 +- .../domain/user/controller/UserController.kt | 4 +- .../controller/dto/response/UserResponse.kt | 2 +- .../b/beep/domain/user/entity/UserEntity.kt | 2 +- .../user/repository/FixedRoomRepository.kt | 4 +- .../domain/user/repository/UserRepository.kt | 2 +- .../domain/user/service/FixedRoomService.kt | 4 +- .../domain/user/service/StudentInfoService.kt | 10 +- .../b/beep/domain/user/service/UserService.kt | 6 +- .../b/beep/global/security/ContextHolder.kt | 4 +- .../beep/global/security/jwt/JwtExtractor.kt | 4 +- .../b/beep/global/security/jwt/JwtProvider.kt | 2 +- .../security/jwt/filter/JwtExceptionFilter.kt | 2 +- 37 files changed, 234 insertions(+), 122 deletions(-) create mode 100644 src/main/kotlin/com/b/beep/domain/student/controller/dto/StudentQueryDto.kt diff --git a/src/main/kotlin/com/b/beep/domain/absence/service/AbsenceService.kt b/src/main/kotlin/com/b/beep/domain/absence/service/AbsenceService.kt index 68c3cc3b..1768e53a 100644 --- a/src/main/kotlin/com/b/beep/domain/absence/service/AbsenceService.kt +++ b/src/main/kotlin/com/b/beep/domain/absence/service/AbsenceService.kt @@ -1,14 +1,14 @@ package com.b.beep.domain.absence.service -import com.b.beep.domain.absence.entity.AbsenceEntity -import com.b.beep.domain.absence.error.AbsenceError import com.b.beep.domain.absence.controller.dto.request.CreateAbsenceRequest import com.b.beep.domain.absence.controller.dto.request.UpdateAbsenceRequest +import com.b.beep.domain.absence.entity.AbsenceEntity +import com.b.beep.domain.absence.error.AbsenceError import com.b.beep.domain.absence.repository.AbsenceRepository -import com.b.beep.domain.user.repository.StudentInfoRepository -import com.b.beep.global.exception.CustomException import com.b.beep.domain.user.domain.UserError import com.b.beep.domain.user.entity.UserEntity +import com.b.beep.domain.user.repository.StudentInfoRepository +import com.b.beep.global.exception.CustomException import org.springframework.data.repository.findByIdOrNull import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional diff --git a/src/main/kotlin/com/b/beep/domain/approval/entity/ApprovalEntity.kt b/src/main/kotlin/com/b/beep/domain/approval/entity/ApprovalEntity.kt index c9e32d7b..e91e3a21 100644 --- a/src/main/kotlin/com/b/beep/domain/approval/entity/ApprovalEntity.kt +++ b/src/main/kotlin/com/b/beep/domain/approval/entity/ApprovalEntity.kt @@ -1,8 +1,8 @@ package com.b.beep.domain.approval.entity +import com.b.beep.domain.attendance.domain.enums.Room import com.b.beep.domain.user.entity.UserEntity import com.b.beep.global.common.entity.BaseEntity -import com.b.beep.domain.attendance.domain.enums.Room import jakarta.persistence.* import java.time.LocalDate diff --git a/src/main/kotlin/com/b/beep/domain/approval/service/ApprovalService.kt b/src/main/kotlin/com/b/beep/domain/approval/service/ApprovalService.kt index ef1012f2..16af3d55 100644 --- a/src/main/kotlin/com/b/beep/domain/approval/service/ApprovalService.kt +++ b/src/main/kotlin/com/b/beep/domain/approval/service/ApprovalService.kt @@ -1,13 +1,13 @@ package com.b.beep.domain.approval.service -import com.b.beep.global.security.ContextHolder import com.b.beep.domain.approval.controller.dto.request.ApproveRequest -import com.b.beep.domain.approval.repository.ApprovalRepository -import com.b.beep.global.exception.CustomException import com.b.beep.domain.approval.entity.ApprovalEntity import com.b.beep.domain.approval.error.ApprovalError +import com.b.beep.domain.approval.repository.ApprovalRepository import com.b.beep.domain.attendance.domain.PeriodResolver import com.b.beep.domain.attendance.domain.enums.Room +import com.b.beep.global.exception.CustomException +import com.b.beep.global.security.ContextHolder import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional import java.time.LocalDate diff --git a/src/main/kotlin/com/b/beep/domain/attendance/entity/AttendanceEntity.kt b/src/main/kotlin/com/b/beep/domain/attendance/entity/AttendanceEntity.kt index 1a5d2712..8a52562d 100644 --- a/src/main/kotlin/com/b/beep/domain/attendance/entity/AttendanceEntity.kt +++ b/src/main/kotlin/com/b/beep/domain/attendance/entity/AttendanceEntity.kt @@ -1,8 +1,8 @@ package com.b.beep.domain.attendance.entity -import com.b.beep.domain.user.entity.UserEntity import com.b.beep.domain.attendance.domain.enums.AttendanceType import com.b.beep.domain.attendance.domain.enums.Room +import com.b.beep.domain.user.entity.UserEntity import jakarta.persistence.* import java.time.LocalDate diff --git a/src/main/kotlin/com/b/beep/domain/auth/controller/AuthController.kt b/src/main/kotlin/com/b/beep/domain/auth/controller/AuthController.kt index 72a3d833..6784f6d0 100644 --- a/src/main/kotlin/com/b/beep/domain/auth/controller/AuthController.kt +++ b/src/main/kotlin/com/b/beep/domain/auth/controller/AuthController.kt @@ -3,8 +3,8 @@ package com.b.beep.domain.auth.controller import com.b.beep.domain.auth.controller.docs.AuthDocs import com.b.beep.domain.auth.controller.dto.request.RefreshTokenRequest import com.b.beep.domain.auth.service.AuthService -import com.b.beep.global.security.jwt.dto.response.TokenResponse import com.b.beep.global.common.dto.response.BaseResponse +import com.b.beep.global.security.jwt.dto.response.TokenResponse import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.RequestBody diff --git a/src/main/kotlin/com/b/beep/domain/auth/controller/DAuthController.kt b/src/main/kotlin/com/b/beep/domain/auth/controller/DAuthController.kt index a213f44c..6e66a617 100644 --- a/src/main/kotlin/com/b/beep/domain/auth/controller/DAuthController.kt +++ b/src/main/kotlin/com/b/beep/domain/auth/controller/DAuthController.kt @@ -3,8 +3,8 @@ package com.b.beep.domain.auth.controller import com.b.beep.domain.auth.controller.docs.DAuthDocs import com.b.beep.domain.auth.controller.dto.request.LoginRequest import com.b.beep.domain.auth.service.AuthService -import com.b.beep.global.security.jwt.dto.response.TokenResponse import com.b.beep.global.common.dto.response.BaseResponse +import com.b.beep.global.security.jwt.dto.response.TokenResponse import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.RequestBody diff --git a/src/main/kotlin/com/b/beep/domain/auth/controller/docs/AuthDocs.kt b/src/main/kotlin/com/b/beep/domain/auth/controller/docs/AuthDocs.kt index a5a710bf..c323fb5e 100644 --- a/src/main/kotlin/com/b/beep/domain/auth/controller/docs/AuthDocs.kt +++ b/src/main/kotlin/com/b/beep/domain/auth/controller/docs/AuthDocs.kt @@ -1,8 +1,8 @@ package com.b.beep.domain.auth.controller.docs import com.b.beep.domain.auth.controller.dto.request.RefreshTokenRequest -import com.b.beep.global.security.jwt.dto.response.TokenResponse import com.b.beep.global.common.dto.response.BaseResponse +import com.b.beep.global.security.jwt.dto.response.TokenResponse import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.tags.Tag import org.springframework.http.ResponseEntity diff --git a/src/main/kotlin/com/b/beep/domain/auth/controller/docs/DAuthDocs.kt b/src/main/kotlin/com/b/beep/domain/auth/controller/docs/DAuthDocs.kt index b8c0157e..1ac9363f 100644 --- a/src/main/kotlin/com/b/beep/domain/auth/controller/docs/DAuthDocs.kt +++ b/src/main/kotlin/com/b/beep/domain/auth/controller/docs/DAuthDocs.kt @@ -1,8 +1,8 @@ package com.b.beep.domain.auth.controller.docs import com.b.beep.domain.auth.controller.dto.request.LoginRequest -import com.b.beep.global.security.jwt.dto.response.TokenResponse import com.b.beep.global.common.dto.response.BaseResponse +import com.b.beep.global.security.jwt.dto.response.TokenResponse import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.tags.Tag import org.springframework.http.ResponseEntity diff --git a/src/main/kotlin/com/b/beep/domain/auth/service/AuthService.kt b/src/main/kotlin/com/b/beep/domain/auth/service/AuthService.kt index 9e57edd0..9b46b2ea 100644 --- a/src/main/kotlin/com/b/beep/domain/auth/service/AuthService.kt +++ b/src/main/kotlin/com/b/beep/domain/auth/service/AuthService.kt @@ -2,13 +2,13 @@ package com.b.beep.domain.auth.service import com.b.beep.domain.auth.controller.dto.request.LoginRequest import com.b.beep.domain.auth.repository.RefreshTokenRepository -import com.b.beep.domain.user.service.StudentInfoService import com.b.beep.domain.user.domain.UserRole +import com.b.beep.domain.user.service.StudentInfoService +import com.b.beep.global.exception.CustomException import com.b.beep.global.security.jwt.JwtExtractor import com.b.beep.global.security.jwt.JwtProvider import com.b.beep.global.security.jwt.dto.response.TokenResponse import com.b.beep.global.security.jwt.error.JwtError -import com.b.beep.global.exception.CustomException import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional diff --git a/src/main/kotlin/com/b/beep/domain/memo/service/MemoService.kt b/src/main/kotlin/com/b/beep/domain/memo/service/MemoService.kt index a649c992..fe7aac28 100644 --- a/src/main/kotlin/com/b/beep/domain/memo/service/MemoService.kt +++ b/src/main/kotlin/com/b/beep/domain/memo/service/MemoService.kt @@ -1,10 +1,10 @@ package com.b.beep.domain.memo.service -import com.b.beep.domain.memo.entity.MemoEntity -import com.b.beep.domain.memo.repository.MemoRepository import com.b.beep.domain.memo.controller.dto.request.CreateMemoRequest import com.b.beep.domain.memo.controller.dto.request.UpdateMemoRequest import com.b.beep.domain.memo.domain.error.MemoError +import com.b.beep.domain.memo.entity.MemoEntity +import com.b.beep.domain.memo.repository.MemoRepository import com.b.beep.global.exception.CustomException import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional diff --git a/src/main/kotlin/com/b/beep/domain/scheduling/AttendanceScheduler.kt b/src/main/kotlin/com/b/beep/domain/scheduling/AttendanceScheduler.kt index 903ab150..a198ba98 100644 --- a/src/main/kotlin/com/b/beep/domain/scheduling/AttendanceScheduler.kt +++ b/src/main/kotlin/com/b/beep/domain/scheduling/AttendanceScheduler.kt @@ -16,7 +16,6 @@ import org.springframework.scheduling.annotation.Scheduled import org.springframework.stereotype.Component import org.springframework.transaction.annotation.Transactional import java.time.LocalDate -import java.time.LocalDateTime @Component class AttendanceScheduler( diff --git a/src/main/kotlin/com/b/beep/domain/shift/controller/ShiftManagementController.kt b/src/main/kotlin/com/b/beep/domain/shift/controller/ShiftManagementController.kt index fe2659c2..88a15219 100644 --- a/src/main/kotlin/com/b/beep/domain/shift/controller/ShiftManagementController.kt +++ b/src/main/kotlin/com/b/beep/domain/shift/controller/ShiftManagementController.kt @@ -2,8 +2,8 @@ package com.b.beep.domain.shift.controller import com.b.beep.domain.shift.controller.docs.ShiftManagementDocs import com.b.beep.domain.shift.controller.dto.response.ShiftResponse -import com.b.beep.domain.shift.service.ShiftManagementService import com.b.beep.domain.shift.domain.enums.ShiftStatus +import com.b.beep.domain.shift.service.ShiftManagementService import com.b.beep.domain.user.service.UserService import org.springframework.web.bind.annotation.* diff --git a/src/main/kotlin/com/b/beep/domain/shift/controller/dto/response/ShiftResponse.kt b/src/main/kotlin/com/b/beep/domain/shift/controller/dto/response/ShiftResponse.kt index bc79d0a6..505908d4 100644 --- a/src/main/kotlin/com/b/beep/domain/shift/controller/dto/response/ShiftResponse.kt +++ b/src/main/kotlin/com/b/beep/domain/shift/controller/dto/response/ShiftResponse.kt @@ -1,8 +1,8 @@ package com.b.beep.domain.shift.controller.dto.response import com.b.beep.domain.attendance.domain.enums.Room -import com.b.beep.domain.shift.entity.ShiftEntity import com.b.beep.domain.shift.domain.enums.ShiftStatus +import com.b.beep.domain.shift.entity.ShiftEntity import com.b.beep.domain.user.controller.dto.response.UserResponse import com.b.beep.domain.user.entity.StudentInfoEntity import java.time.LocalDate diff --git a/src/main/kotlin/com/b/beep/domain/shift/entity/ShiftEntity.kt b/src/main/kotlin/com/b/beep/domain/shift/entity/ShiftEntity.kt index dc419937..e75582c6 100644 --- a/src/main/kotlin/com/b/beep/domain/shift/entity/ShiftEntity.kt +++ b/src/main/kotlin/com/b/beep/domain/shift/entity/ShiftEntity.kt @@ -1,9 +1,9 @@ package com.b.beep.domain.shift.entity -import com.b.beep.domain.user.entity.UserEntity -import com.b.beep.global.common.entity.BaseEntity import com.b.beep.domain.attendance.domain.enums.Room import com.b.beep.domain.shift.domain.enums.ShiftStatus +import com.b.beep.domain.user.entity.UserEntity +import com.b.beep.global.common.entity.BaseEntity import jakarta.persistence.* import java.time.LocalDate diff --git a/src/main/kotlin/com/b/beep/domain/shift/service/ShiftManagementService.kt b/src/main/kotlin/com/b/beep/domain/shift/service/ShiftManagementService.kt index 6f27e917..f30117a6 100644 --- a/src/main/kotlin/com/b/beep/domain/shift/service/ShiftManagementService.kt +++ b/src/main/kotlin/com/b/beep/domain/shift/service/ShiftManagementService.kt @@ -4,10 +4,10 @@ import com.b.beep.domain.attendance.domain.enums.AttendanceType import com.b.beep.domain.attendance.domain.enums.Room import com.b.beep.domain.attendance.domain.error.AttendanceError import com.b.beep.domain.attendance.repository.AttendanceRepository -import com.b.beep.domain.shift.entity.ShiftEntity -import com.b.beep.domain.shift.repository.ShiftRepository import com.b.beep.domain.shift.domain.enums.ShiftStatus import com.b.beep.domain.shift.domain.error.ShiftError +import com.b.beep.domain.shift.entity.ShiftEntity +import com.b.beep.domain.shift.repository.ShiftRepository import com.b.beep.domain.user.entity.UserEntity import com.b.beep.global.exception.CustomException import org.springframework.data.repository.findByIdOrNull diff --git a/src/main/kotlin/com/b/beep/domain/student/controller/GetNotAttendedStudentController.kt b/src/main/kotlin/com/b/beep/domain/student/controller/GetNotAttendedStudentController.kt index 0458b841..93a8928b 100644 --- a/src/main/kotlin/com/b/beep/domain/student/controller/GetNotAttendedStudentController.kt +++ b/src/main/kotlin/com/b/beep/domain/student/controller/GetNotAttendedStudentController.kt @@ -1,10 +1,10 @@ package com.b.beep.domain.student.controller +import com.b.beep.domain.attendance.domain.enums.AttendanceType +import com.b.beep.domain.attendance.domain.enums.Room import com.b.beep.domain.student.controller.docs.GetNotAttendedStudentDocs import com.b.beep.domain.student.controller.dto.response.StudentResponse import com.b.beep.domain.student.service.GetNotAttendedStudentService -import com.b.beep.domain.attendance.domain.enums.AttendanceType -import com.b.beep.domain.attendance.domain.enums.Room import org.springframework.http.HttpStatus import org.springframework.web.bind.annotation.* diff --git a/src/main/kotlin/com/b/beep/domain/student/controller/GetStudentController.kt b/src/main/kotlin/com/b/beep/domain/student/controller/GetStudentController.kt index 38d8b4ee..de2d4169 100644 --- a/src/main/kotlin/com/b/beep/domain/student/controller/GetStudentController.kt +++ b/src/main/kotlin/com/b/beep/domain/student/controller/GetStudentController.kt @@ -1,10 +1,10 @@ package com.b.beep.domain.student.controller +import com.b.beep.domain.attendance.domain.enums.AttendanceType +import com.b.beep.domain.attendance.domain.enums.Room import com.b.beep.domain.student.controller.docs.GetStudentDocs import com.b.beep.domain.student.controller.dto.response.StudentResponse import com.b.beep.domain.student.service.GetStudentService -import com.b.beep.domain.attendance.domain.enums.AttendanceType -import com.b.beep.domain.attendance.domain.enums.Room import org.springframework.http.HttpStatus import org.springframework.web.bind.annotation.* diff --git a/src/main/kotlin/com/b/beep/domain/student/controller/docs/GetNotAttendedStudentDocs.kt b/src/main/kotlin/com/b/beep/domain/student/controller/docs/GetNotAttendedStudentDocs.kt index 2419d0ee..69e97bb2 100644 --- a/src/main/kotlin/com/b/beep/domain/student/controller/docs/GetNotAttendedStudentDocs.kt +++ b/src/main/kotlin/com/b/beep/domain/student/controller/docs/GetNotAttendedStudentDocs.kt @@ -1,8 +1,8 @@ package com.b.beep.domain.student.controller.docs -import com.b.beep.domain.student.controller.dto.response.StudentResponse import com.b.beep.domain.attendance.domain.enums.AttendanceType import com.b.beep.domain.attendance.domain.enums.Room +import com.b.beep.domain.student.controller.dto.response.StudentResponse import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.tags.Tag diff --git a/src/main/kotlin/com/b/beep/domain/student/controller/docs/GetStudentDocs.kt b/src/main/kotlin/com/b/beep/domain/student/controller/docs/GetStudentDocs.kt index f402aa0f..80f60b35 100644 --- a/src/main/kotlin/com/b/beep/domain/student/controller/docs/GetStudentDocs.kt +++ b/src/main/kotlin/com/b/beep/domain/student/controller/docs/GetStudentDocs.kt @@ -1,8 +1,8 @@ package com.b.beep.domain.student.controller.docs -import com.b.beep.domain.student.controller.dto.response.StudentResponse import com.b.beep.domain.attendance.domain.enums.AttendanceType import com.b.beep.domain.attendance.domain.enums.Room +import com.b.beep.domain.student.controller.dto.response.StudentResponse import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.tags.Tag diff --git a/src/main/kotlin/com/b/beep/domain/student/controller/dto/StudentQueryDto.kt b/src/main/kotlin/com/b/beep/domain/student/controller/dto/StudentQueryDto.kt new file mode 100644 index 00000000..487a261f --- /dev/null +++ b/src/main/kotlin/com/b/beep/domain/student/controller/dto/StudentQueryDto.kt @@ -0,0 +1,14 @@ +package com.b.beep.domain.student.controller.dto + +import com.b.beep.domain.attendance.entity.AttendanceEntity +import com.b.beep.domain.user.entity.FixedRoomEntity +import com.b.beep.domain.user.entity.StudentInfoEntity +import com.b.beep.domain.user.entity.UserEntity +import com.querydsl.core.annotations.QueryProjection + +data class StudentQueryDto @QueryProjection constructor( + val user: UserEntity, + val studentInfo: StudentInfoEntity, + val fixedRooms: List?, + val attendances: List? +) \ No newline at end of file diff --git a/src/main/kotlin/com/b/beep/domain/student/controller/dto/response/StudentResponse.kt b/src/main/kotlin/com/b/beep/domain/student/controller/dto/response/StudentResponse.kt index 2bed835e..f9a3fb1a 100644 --- a/src/main/kotlin/com/b/beep/domain/student/controller/dto/response/StudentResponse.kt +++ b/src/main/kotlin/com/b/beep/domain/student/controller/dto/response/StudentResponse.kt @@ -1,11 +1,8 @@ package com.b.beep.domain.student.controller.dto.response -import com.b.beep.domain.user.controller.dto.response.FixedRoomResponse import com.b.beep.domain.attendance.domain.enums.AttendanceType -import com.b.beep.domain.user.entity.UserEntity -import com.b.beep.domain.user.entity.StudentInfoEntity -import com.b.beep.domain.user.entity.FixedRoomEntity -import com.b.beep.domain.attendance.entity.AttendanceEntity +import com.b.beep.domain.student.controller.dto.StudentQueryDto +import com.b.beep.domain.user.controller.dto.response.FixedRoomResponse data class StudentResponse( val username: String, @@ -15,18 +12,48 @@ data class StudentResponse( ) { companion object { fun of( - user: UserEntity, - studentInfo: StudentInfoEntity, - fixedRooms: List?, - attendances: List + studentQueryDto: StudentQueryDto ): StudentResponse { return StudentResponse( - username = user.username, - studentId = String.format("%d%d%02d", studentInfo.grade, studentInfo.cls, studentInfo.num), - fixedRooms = fixedRooms?.map { FixedRoomResponse.of(it) }, - statuses = attendances.map { StatusResponse(it.period, it.type) } + username = studentQueryDto.user.username, + studentId = String.format("%d%d%02d", studentQueryDto.studentInfo.grade, studentQueryDto.studentInfo.cls, studentQueryDto.studentInfo.num), + fixedRooms = studentQueryDto.fixedRooms.orEmpty().mapNotNull { room -> + room?.let { FixedRoomResponse.of(it) } + }, + statuses = studentQueryDto.attendances.orEmpty().map { attendance -> + attendance.let { StatusResponse(it.period, it.type) } + } ) } + + private fun ofFixedRoomNull( + studentQueryDto: StudentQueryDto + ): StudentResponse { + return StudentResponse( + username = studentQueryDto.user.username, + studentId = String.format("%d%d%02d", studentQueryDto.studentInfo.grade, studentQueryDto.studentInfo.cls, studentQueryDto.studentInfo.num), + fixedRooms = null, + statuses = studentQueryDto.attendances.orEmpty().map { attendance -> + attendance.let { StatusResponse(it.period, it.type) } + } + ) + } + + fun ofStudentQueryDtoList( + studentQueryDtos: List + ): List { + return studentQueryDtos.map { dto -> + of(dto) + } + } + + fun ofStudentQueryDtoListFixedRoomsNull( + studentQueryDtos: List + ): List { + return studentQueryDtos.map { dto -> + ofFixedRoomNull(dto) + } + } } } diff --git a/src/main/kotlin/com/b/beep/domain/student/repository/StudentQueryRepository.kt b/src/main/kotlin/com/b/beep/domain/student/repository/StudentQueryRepository.kt index c10ba1c3..b54a51a7 100644 --- a/src/main/kotlin/com/b/beep/domain/student/repository/StudentQueryRepository.kt +++ b/src/main/kotlin/com/b/beep/domain/student/repository/StudentQueryRepository.kt @@ -1,14 +1,20 @@ package com.b.beep.domain.student.repository -import com.b.beep.domain.user.entity.QFixedRoomEntity -import com.b.beep.domain.user.entity.QStudentInfoEntity -import com.b.beep.domain.user.entity.QUserEntity -import com.b.beep.domain.user.entity.UserEntity import com.b.beep.domain.attendance.domain.enums.AttendanceType import com.b.beep.domain.attendance.domain.enums.Room +import com.b.beep.domain.attendance.entity.QAttendanceEntity.attendanceEntity +import com.b.beep.domain.student.controller.dto.QStudentQueryDto +import com.b.beep.domain.student.controller.dto.StudentQueryDto import com.b.beep.domain.user.domain.UserRole +import com.b.beep.domain.user.entity.QFixedRoomEntity.fixedRoomEntity +import com.b.beep.domain.user.entity.QStudentInfoEntity.studentInfoEntity +import com.b.beep.domain.user.entity.QUserEntity.userEntity +import com.b.beep.domain.user.entity.UserEntity +import com.querydsl.core.group.GroupBy.groupBy +import com.querydsl.core.group.GroupBy.list import com.querydsl.jpa.impl.JPAQueryFactory import org.springframework.stereotype.Repository +import java.time.LocalDate @Repository class StudentQueryRepository( @@ -19,8 +25,6 @@ class StudentQueryRepository( cls: Int, status: AttendanceType? = null, ): List { - val userEntity = QUserEntity.userEntity - val studentInfoEntity = QStudentInfoEntity.studentInfoEntity return queryFactory .selectFrom(userEntity) @@ -34,14 +38,12 @@ class StudentQueryRepository( ) .fetch() } - + fun findAllByStatusAndRoomAndType( room: Room, type: AttendanceType, status: AttendanceType? = null, ): List { - val userEntity = QUserEntity.userEntity - val fixedRoomEntity = QFixedRoomEntity.fixedRoomEntity return queryFactory .selectFrom(userEntity) @@ -55,4 +57,101 @@ class StudentQueryRepository( ) .fetch() } + + fun findAllInfoByStatusAndRoomAndType( + room: Room, + type: AttendanceType, + status: AttendanceType? = null + ): List { + return queryFactory + .from(userEntity) + .innerJoin(studentInfoEntity).on(studentInfoEntity.user.eq(userEntity)) + .innerJoin(fixedRoomEntity).on( + fixedRoomEntity.user.eq(userEntity), + fixedRoomEntity.room.eq(room), + fixedRoomEntity.type.eq(type) + ) + .leftJoin(attendanceEntity).on( + attendanceEntity.user.eq(userEntity), + attendanceEntity.date.eq(LocalDate.now()) + ) + .where( + status?.let { userEntity.currentStatus.eq(it) }, + userEntity.role.eq(UserRole.STUDENT) + ) + .transform( + groupBy(userEntity.id).list( + QStudentQueryDto( + userEntity, + studentInfoEntity, + list(fixedRoomEntity), + list(attendanceEntity) + ) + ) + ) + } + + fun findAllInfoByStatusAndGradeAndCls( + grade: Int, + cls: Int, + status: AttendanceType? = null + ): List { + return queryFactory + .from(userEntity) + .innerJoin(studentInfoEntity).on(studentInfoEntity.user.eq(userEntity)) + .leftJoin(fixedRoomEntity).on(fixedRoomEntity.user.eq(userEntity)) + .leftJoin(attendanceEntity).on( + attendanceEntity.user.eq(userEntity), + attendanceEntity.date.eq(LocalDate.now()) + ) + .where( + studentInfoEntity.grade.eq(grade), + studentInfoEntity.cls.eq(cls), + status?.let { userEntity.currentStatus.eq(it) }, + userEntity.role.eq(UserRole.STUDENT) + ) + .transform( + groupBy(userEntity.id).list( + QStudentQueryDto( + userEntity, + studentInfoEntity, + list(fixedRoomEntity), + list(attendanceEntity) + ) + ) + ) + } + + fun findAllInfoByRoomTypeStatusAndRole( + fixedRoomType: AttendanceType, + status: AttendanceType, + role: UserRole + ): List { + return queryFactory + .from(userEntity) + .innerJoin(studentInfoEntity).on(studentInfoEntity.user.eq(userEntity)) + .innerJoin(fixedRoomEntity).on( + fixedRoomEntity.user.eq(userEntity), + fixedRoomEntity.type.eq(fixedRoomType) + ) + .leftJoin(attendanceEntity).on( + attendanceEntity.user.eq(userEntity), + attendanceEntity.date.eq(LocalDate.now()) + ) + .where( + userEntity.currentStatus.eq(status), + userEntity.role.eq(role) + ) + .transform( + groupBy(userEntity.id).list( + QStudentQueryDto( + userEntity, + studentInfoEntity, + list(fixedRoomEntity), + list(attendanceEntity) + ) + ) + ) + } + } diff --git a/src/main/kotlin/com/b/beep/domain/student/service/GetNotAttendedStudentService.kt b/src/main/kotlin/com/b/beep/domain/student/service/GetNotAttendedStudentService.kt index 0980ccde..93448ac0 100644 --- a/src/main/kotlin/com/b/beep/domain/student/service/GetNotAttendedStudentService.kt +++ b/src/main/kotlin/com/b/beep/domain/student/service/GetNotAttendedStudentService.kt @@ -4,16 +4,15 @@ import com.b.beep.domain.attendance.domain.enums.AttendanceType import com.b.beep.domain.attendance.domain.enums.Room import com.b.beep.domain.attendance.repository.AttendanceRepository import com.b.beep.domain.student.controller.dto.response.StudentResponse +import com.b.beep.domain.student.controller.dto.response.StudentResponse.Companion.ofStudentQueryDtoList +import com.b.beep.domain.student.controller.dto.response.StudentResponse.Companion.ofStudentQueryDtoListFixedRoomsNull import com.b.beep.domain.student.repository.StudentQueryRepository -import com.b.beep.domain.user.domain.UserError import com.b.beep.domain.user.domain.UserRole import com.b.beep.domain.user.repository.FixedRoomRepository import com.b.beep.domain.user.repository.StudentInfoRepository import com.b.beep.domain.user.repository.UserRepository -import com.b.beep.global.exception.CustomException import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional -import java.time.LocalDate @Service @Transactional(readOnly = true) @@ -25,34 +24,17 @@ class GetNotAttendedStudentService( private val attendanceRepository: AttendanceRepository ) { fun getAll(type: AttendanceType): List { - val users = userRepository.findAllByCurrentStatusAndRole(AttendanceType.NOT_ATTEND, UserRole.STUDENT) - return users.map { user -> - val studentInfo = studentInfoRepository.findByUser(user) - ?: throw CustomException(UserError.STUDENT_INFO_NOT_FOUND) - val fixedRooms = fixedRoomRepository.findAllByUserAndType(user, type) - val attendances = attendanceRepository.findByUserAndDate(user, LocalDate.now()) - StudentResponse.of(user, studentInfo, fixedRooms, attendances) - } + val studentQueryDtos = studentQueryRepository.findAllInfoByRoomTypeStatusAndRole(type, AttendanceType.NOT_ATTEND, UserRole.STUDENT) + return ofStudentQueryDtoList(studentQueryDtos) } fun getAllByRoomAndType(room: Room, type: AttendanceType): List { - val users = studentQueryRepository.findAllByStatusAndRoomAndType(room, type, AttendanceType.NOT_ATTEND) - return users.map { user -> - val studentInfo = studentInfoRepository.findByUser(user) - ?: throw CustomException(UserError.STUDENT_INFO_NOT_FOUND) - val fixedRooms = fixedRoomRepository.findAllByUserAndType(user, type) - val attendances = attendanceRepository.findByUserAndDate(user, LocalDate.now()) - StudentResponse.of(user, studentInfo, fixedRooms, attendances) - } + val studentQueryDtos = studentQueryRepository.findAllInfoByStatusAndRoomAndType(room, type, AttendanceType.NOT_ATTEND) + return ofStudentQueryDtoList(studentQueryDtos) } fun getAllByGradeAndCls(grade: Int, cls: Int): List { - val users = studentQueryRepository.findAllByStatusAndGradeAndCls(grade, cls, AttendanceType.NOT_ATTEND) - return users.map { user -> - val studentInfo = studentInfoRepository.findByUser(user) - ?: throw CustomException(UserError.STUDENT_INFO_NOT_FOUND) - val attendances = attendanceRepository.findByUserAndDate(user, LocalDate.now()) - StudentResponse.of(user, studentInfo, null, attendances) - } + val studentQueryDtos = studentQueryRepository.findAllInfoByStatusAndGradeAndCls(grade, cls) + return ofStudentQueryDtoListFixedRoomsNull(studentQueryDtos) } } diff --git a/src/main/kotlin/com/b/beep/domain/student/service/GetStudentService.kt b/src/main/kotlin/com/b/beep/domain/student/service/GetStudentService.kt index 0e7f84cc..fd1b2390 100644 --- a/src/main/kotlin/com/b/beep/domain/student/service/GetStudentService.kt +++ b/src/main/kotlin/com/b/beep/domain/student/service/GetStudentService.kt @@ -4,15 +4,14 @@ import com.b.beep.domain.attendance.domain.enums.AttendanceType import com.b.beep.domain.attendance.domain.enums.Room import com.b.beep.domain.attendance.repository.AttendanceRepository import com.b.beep.domain.student.controller.dto.response.StudentResponse +import com.b.beep.domain.student.controller.dto.response.StudentResponse.Companion.ofStudentQueryDtoList +import com.b.beep.domain.student.controller.dto.response.StudentResponse.Companion.ofStudentQueryDtoListFixedRoomsNull import com.b.beep.domain.student.repository.StudentQueryRepository -import com.b.beep.domain.user.domain.UserError import com.b.beep.domain.user.repository.FixedRoomRepository import com.b.beep.domain.user.repository.StudentInfoRepository import com.b.beep.domain.user.repository.UserRepository -import com.b.beep.global.exception.CustomException import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional -import java.time.LocalDate @Service @Transactional(readOnly = true) @@ -24,23 +23,15 @@ class GetStudentService( private val attendanceRepository: AttendanceRepository ) { fun getAllByRoomAndType(room: Room, type: AttendanceType): List { - val users = studentQueryRepository.findAllByStatusAndRoomAndType(room, type) - return users.map { user -> - val studentInfo = studentInfoRepository.findByUser(user) - ?: throw CustomException(UserError.STUDENT_INFO_NOT_FOUND) - val fixedRooms = fixedRoomRepository.findAllByUserAndType(user, type) - val attendances = attendanceRepository.findByUserAndDate(user, LocalDate.now()) - StudentResponse.of(user, studentInfo, fixedRooms, attendances) - } + val studentQueryDtos = studentQueryRepository.findAllInfoByStatusAndRoomAndType(room, type) + return ofStudentQueryDtoList(studentQueryDtos) } fun getAllByGradeAndCls(grade: Int, cls: Int): List { - val users = studentQueryRepository.findAllByStatusAndGradeAndCls(grade, cls) - return users.map { user -> - val studentInfo = studentInfoRepository.findByUser(user) - ?: throw CustomException(UserError.STUDENT_INFO_NOT_FOUND) - val attendances = attendanceRepository.findByUserAndDate(user, LocalDate.now()) - StudentResponse.of(user, studentInfo, null, attendances) - } + val studentQueryDtos = studentQueryRepository.findAllInfoByStatusAndGradeAndCls(grade, cls) + return ofStudentQueryDtoListFixedRoomsNull(studentQueryDtos) } + + // fixedRooms가 null이여야 한다면 + // ofStudentQueryDtoListFixedRoomsNull를 사용해보자 } diff --git a/src/main/kotlin/com/b/beep/domain/student/service/StudentManagementService.kt b/src/main/kotlin/com/b/beep/domain/student/service/StudentManagementService.kt index b4c68aba..35be510b 100644 --- a/src/main/kotlin/com/b/beep/domain/student/service/StudentManagementService.kt +++ b/src/main/kotlin/com/b/beep/domain/student/service/StudentManagementService.kt @@ -1,12 +1,12 @@ package com.b.beep.domain.student.service +import com.b.beep.domain.attendance.domain.PeriodResolver +import com.b.beep.domain.attendance.domain.enums.AttendanceType import com.b.beep.domain.attendance.entity.AttendanceEntity import com.b.beep.domain.attendance.repository.AttendanceRepository +import com.b.beep.domain.user.domain.UserError import com.b.beep.domain.user.repository.StudentInfoRepository import com.b.beep.domain.user.repository.UserRepository -import com.b.beep.domain.attendance.domain.enums.AttendanceType -import com.b.beep.domain.attendance.domain.PeriodResolver -import com.b.beep.domain.user.domain.UserError import com.b.beep.global.exception.CustomException import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional diff --git a/src/main/kotlin/com/b/beep/domain/user/controller/UserController.kt b/src/main/kotlin/com/b/beep/domain/user/controller/UserController.kt index ba9eddd6..56e271ea 100644 --- a/src/main/kotlin/com/b/beep/domain/user/controller/UserController.kt +++ b/src/main/kotlin/com/b/beep/domain/user/controller/UserController.kt @@ -1,11 +1,11 @@ package com.b.beep.domain.user.controller import com.b.beep.domain.user.controller.docs.UserDocs -import com.b.beep.domain.user.controller.dto.response.UserResponse import com.b.beep.domain.user.controller.dto.response.StudentInfoResponse +import com.b.beep.domain.user.controller.dto.response.UserResponse +import com.b.beep.domain.user.domain.UserRole import com.b.beep.domain.user.service.UserService import com.b.beep.global.common.dto.response.BaseResponse -import com.b.beep.domain.user.domain.UserRole import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.RequestMapping diff --git a/src/main/kotlin/com/b/beep/domain/user/controller/dto/response/UserResponse.kt b/src/main/kotlin/com/b/beep/domain/user/controller/dto/response/UserResponse.kt index a1873585..1b12f225 100644 --- a/src/main/kotlin/com/b/beep/domain/user/controller/dto/response/UserResponse.kt +++ b/src/main/kotlin/com/b/beep/domain/user/controller/dto/response/UserResponse.kt @@ -1,9 +1,9 @@ package com.b.beep.domain.user.controller.dto.response import com.b.beep.domain.attendance.domain.enums.AttendanceType +import com.b.beep.domain.user.domain.UserRole import com.b.beep.domain.user.entity.StudentInfoEntity import com.b.beep.domain.user.entity.UserEntity -import com.b.beep.domain.user.domain.UserRole data class UserResponse( val id: Long? = null, diff --git a/src/main/kotlin/com/b/beep/domain/user/entity/UserEntity.kt b/src/main/kotlin/com/b/beep/domain/user/entity/UserEntity.kt index d113ab46..3ab252ad 100644 --- a/src/main/kotlin/com/b/beep/domain/user/entity/UserEntity.kt +++ b/src/main/kotlin/com/b/beep/domain/user/entity/UserEntity.kt @@ -1,8 +1,8 @@ package com.b.beep.domain.user.entity -import com.b.beep.global.common.entity.BaseEntity import com.b.beep.domain.attendance.domain.enums.AttendanceType import com.b.beep.domain.user.domain.UserRole +import com.b.beep.global.common.entity.BaseEntity import jakarta.persistence.* @Entity diff --git a/src/main/kotlin/com/b/beep/domain/user/repository/FixedRoomRepository.kt b/src/main/kotlin/com/b/beep/domain/user/repository/FixedRoomRepository.kt index d2ae0475..ee15db74 100644 --- a/src/main/kotlin/com/b/beep/domain/user/repository/FixedRoomRepository.kt +++ b/src/main/kotlin/com/b/beep/domain/user/repository/FixedRoomRepository.kt @@ -1,9 +1,9 @@ package com.b.beep.domain.user.repository -import com.b.beep.domain.user.entity.FixedRoomEntity -import com.b.beep.domain.user.entity.UserEntity import com.b.beep.domain.attendance.domain.enums.AttendanceType import com.b.beep.domain.attendance.domain.enums.Room +import com.b.beep.domain.user.entity.FixedRoomEntity +import com.b.beep.domain.user.entity.UserEntity import org.springframework.data.jpa.repository.JpaRepository interface FixedRoomRepository : JpaRepository { diff --git a/src/main/kotlin/com/b/beep/domain/user/repository/UserRepository.kt b/src/main/kotlin/com/b/beep/domain/user/repository/UserRepository.kt index b6ae00c9..c8959a03 100644 --- a/src/main/kotlin/com/b/beep/domain/user/repository/UserRepository.kt +++ b/src/main/kotlin/com/b/beep/domain/user/repository/UserRepository.kt @@ -1,8 +1,8 @@ package com.b.beep.domain.user.repository -import com.b.beep.domain.user.entity.UserEntity import com.b.beep.domain.attendance.domain.enums.AttendanceType import com.b.beep.domain.user.domain.UserRole +import com.b.beep.domain.user.entity.UserEntity import org.springframework.data.jpa.repository.JpaRepository import org.springframework.data.jpa.repository.Modifying import org.springframework.data.jpa.repository.Query diff --git a/src/main/kotlin/com/b/beep/domain/user/service/FixedRoomService.kt b/src/main/kotlin/com/b/beep/domain/user/service/FixedRoomService.kt index 7b2d5e7e..23a66e03 100644 --- a/src/main/kotlin/com/b/beep/domain/user/service/FixedRoomService.kt +++ b/src/main/kotlin/com/b/beep/domain/user/service/FixedRoomService.kt @@ -1,12 +1,12 @@ package com.b.beep.domain.user.service -import com.b.beep.global.security.ContextHolder import com.b.beep.domain.user.controller.dto.request.AddFixedRoomRequest import com.b.beep.domain.user.controller.dto.request.UpdateFixedRoomRequest +import com.b.beep.domain.user.domain.FixedRoomError import com.b.beep.domain.user.entity.FixedRoomEntity import com.b.beep.domain.user.repository.FixedRoomRepository import com.b.beep.global.exception.CustomException -import com.b.beep.domain.user.domain.FixedRoomError +import com.b.beep.global.security.ContextHolder import org.springframework.data.repository.findByIdOrNull import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional diff --git a/src/main/kotlin/com/b/beep/domain/user/service/StudentInfoService.kt b/src/main/kotlin/com/b/beep/domain/user/service/StudentInfoService.kt index 596d54db..2cce2c5f 100644 --- a/src/main/kotlin/com/b/beep/domain/user/service/StudentInfoService.kt +++ b/src/main/kotlin/com/b/beep/domain/user/service/StudentInfoService.kt @@ -1,14 +1,14 @@ package com.b.beep.domain.user.service -import com.b.beep.domain.user.entity.UserEntity -import com.b.beep.domain.user.entity.StudentInfoEntity -import com.b.beep.domain.user.repository.StudentInfoRepository -import com.b.beep.domain.user.repository.UserRepository -import com.b.beep.domain.user.domain.UserRole import com.b.beep.domain.attendance.domain.enums.AttendanceType import com.b.beep.domain.attendance.entity.AttendanceEntity import com.b.beep.domain.attendance.repository.AttendanceRepository import com.b.beep.domain.auth.infrastructure.DAuthUserResponse +import com.b.beep.domain.user.domain.UserRole +import com.b.beep.domain.user.entity.StudentInfoEntity +import com.b.beep.domain.user.entity.UserEntity +import com.b.beep.domain.user.repository.StudentInfoRepository +import com.b.beep.domain.user.repository.UserRepository import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional import java.time.LocalDate diff --git a/src/main/kotlin/com/b/beep/domain/user/service/UserService.kt b/src/main/kotlin/com/b/beep/domain/user/service/UserService.kt index a12a31cb..7819fa0b 100644 --- a/src/main/kotlin/com/b/beep/domain/user/service/UserService.kt +++ b/src/main/kotlin/com/b/beep/domain/user/service/UserService.kt @@ -1,11 +1,11 @@ package com.b.beep.domain.user.service -import com.b.beep.global.security.ContextHolder -import com.b.beep.domain.user.entity.UserEntity +import com.b.beep.domain.user.domain.UserError import com.b.beep.domain.user.entity.StudentInfoEntity +import com.b.beep.domain.user.entity.UserEntity import com.b.beep.domain.user.repository.StudentInfoRepository import com.b.beep.global.exception.CustomException -import com.b.beep.domain.user.domain.UserError +import com.b.beep.global.security.ContextHolder import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional diff --git a/src/main/kotlin/com/b/beep/global/security/ContextHolder.kt b/src/main/kotlin/com/b/beep/global/security/ContextHolder.kt index ba340709..88c0ef76 100644 --- a/src/main/kotlin/com/b/beep/global/security/ContextHolder.kt +++ b/src/main/kotlin/com/b/beep/global/security/ContextHolder.kt @@ -1,9 +1,9 @@ package com.b.beep.global.security +import com.b.beep.domain.user.domain.UserError +import com.b.beep.domain.user.entity.UserEntity import com.b.beep.domain.user.repository.UserRepository import com.b.beep.global.exception.CustomException -import com.b.beep.domain.user.entity.UserEntity -import com.b.beep.domain.user.domain.UserError import org.springframework.security.core.context.SecurityContextHolder import org.springframework.stereotype.Component diff --git a/src/main/kotlin/com/b/beep/global/security/jwt/JwtExtractor.kt b/src/main/kotlin/com/b/beep/global/security/jwt/JwtExtractor.kt index 72b22c43..49da666d 100644 --- a/src/main/kotlin/com/b/beep/global/security/jwt/JwtExtractor.kt +++ b/src/main/kotlin/com/b/beep/global/security/jwt/JwtExtractor.kt @@ -1,12 +1,12 @@ package com.b.beep.global.security.jwt +import com.b.beep.domain.user.domain.UserError import com.b.beep.domain.user.repository.UserRepository +import com.b.beep.global.exception.CustomException import com.b.beep.global.security.auth.AuthDetails import com.b.beep.global.security.jwt.config.JwtProperties import com.b.beep.global.security.jwt.enums.JwtType import com.b.beep.global.security.jwt.error.JwtError -import com.b.beep.global.exception.CustomException -import com.b.beep.domain.user.domain.UserError import io.jsonwebtoken.* import io.jsonwebtoken.io.Decoders import io.jsonwebtoken.security.Keys diff --git a/src/main/kotlin/com/b/beep/global/security/jwt/JwtProvider.kt b/src/main/kotlin/com/b/beep/global/security/jwt/JwtProvider.kt index ea3fd670..78491957 100644 --- a/src/main/kotlin/com/b/beep/global/security/jwt/JwtProvider.kt +++ b/src/main/kotlin/com/b/beep/global/security/jwt/JwtProvider.kt @@ -1,9 +1,9 @@ package com.b.beep.global.security.jwt +import com.b.beep.domain.auth.repository.RefreshTokenRepository import com.b.beep.global.security.jwt.config.JwtProperties import com.b.beep.global.security.jwt.dto.response.TokenResponse import com.b.beep.global.security.jwt.enums.JwtType -import com.b.beep.domain.auth.repository.RefreshTokenRepository import io.jsonwebtoken.Header import io.jsonwebtoken.Jwts import io.jsonwebtoken.io.Decoders diff --git a/src/main/kotlin/com/b/beep/global/security/jwt/filter/JwtExceptionFilter.kt b/src/main/kotlin/com/b/beep/global/security/jwt/filter/JwtExceptionFilter.kt index c146eafa..a1e9f82a 100644 --- a/src/main/kotlin/com/b/beep/global/security/jwt/filter/JwtExceptionFilter.kt +++ b/src/main/kotlin/com/b/beep/global/security/jwt/filter/JwtExceptionFilter.kt @@ -1,8 +1,8 @@ package com.b.beep.global.security.jwt.filter -import com.b.beep.global.security.jwt.error.JwtError import com.b.beep.global.exception.CustomException import com.b.beep.global.exception.ErrorResponse +import com.b.beep.global.security.jwt.error.JwtError import com.fasterxml.jackson.databind.ObjectMapper import io.jsonwebtoken.ExpiredJwtException import io.jsonwebtoken.MalformedJwtException From 036e5e472a1a7469c6126fd2564ba10d4d505274 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=ED=98=B8?= Date: Thu, 25 Dec 2025 03:54:08 +0900 Subject: [PATCH 2/2] =?UTF-8?q?test:=20=ED=95=99=EC=83=9D=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=84=B1=EB=8A=A5=20=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 12 +- .../repository/StudentQueryRepositoryTest.kt | 134 ++++++++++++++++++ .../beep/global/config/QueryDslConfigTest.kt | 18 +++ src/test/resources/application.yml | 2 +- 4 files changed, 161 insertions(+), 5 deletions(-) create mode 100644 src/test/kotlin/com/b/beep/domain/student/repository/StudentQueryRepositoryTest.kt create mode 100644 src/test/kotlin/com/b/beep/global/config/QueryDslConfigTest.kt diff --git a/build.gradle b/build.gradle index 11d8e765..3643afee 100644 --- a/build.gradle +++ b/build.gradle @@ -26,10 +26,12 @@ dependencies { implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE' // QueryDSL - implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta' - kapt 'com.querydsl:querydsl-apt:5.0.0:jakarta' - kapt "jakarta.annotation:jakarta.annotation-api" - kapt "jakarta.persistence:jakarta.persistence-api" + + implementation("io.github.openfeign.querydsl:querydsl-jpa:7.1") + + kapt("io.github.openfeign.querydsl:querydsl-apt:7.1:jpa") + kapt("jakarta.persistence:jakarta.persistence-api") + kapt("jakarta.annotation:jakarta.annotation-api") implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-security' @@ -91,6 +93,8 @@ dependencies { testImplementation 'org.mockito:mockito-inline:4.1.0' testImplementation 'org.mockito.kotlin:mockito-kotlin:4.1.0' testImplementation 'org.junit.jupiter:junit-jupiter:5.10.0' + + testRuntimeOnly("com.h2database:h2") } kotlin { diff --git a/src/test/kotlin/com/b/beep/domain/student/repository/StudentQueryRepositoryTest.kt b/src/test/kotlin/com/b/beep/domain/student/repository/StudentQueryRepositoryTest.kt new file mode 100644 index 00000000..a21943fe --- /dev/null +++ b/src/test/kotlin/com/b/beep/domain/student/repository/StudentQueryRepositoryTest.kt @@ -0,0 +1,134 @@ +package com.b.beep.domain.student.repository + +import com.b.beep.domain.attendance.domain.enums.AttendanceType +import com.b.beep.domain.attendance.domain.enums.Room +import com.b.beep.domain.attendance.entity.AttendanceEntity +import com.b.beep.domain.attendance.repository.AttendanceRepository +import com.b.beep.domain.user.domain.UserRole +import com.b.beep.domain.user.entity.FixedRoomEntity +import com.b.beep.domain.user.entity.StudentInfoEntity +import com.b.beep.domain.user.entity.UserEntity +import com.b.beep.domain.user.repository.FixedRoomRepository +import com.b.beep.domain.user.repository.StudentInfoRepository +import com.b.beep.domain.user.repository.UserRepository +import com.b.beep.global.config.QueryDslConfigTest +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.api.Test +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest +import org.springframework.context.annotation.Import +import java.time.LocalDate + +@DataJpaTest +@Import(QueryDslConfigTest::class, StudentQueryRepository::class) +class StudentQueryRepositoryTest @Autowired constructor( + val studentQueryRepository: StudentQueryRepository, + val userRepository: UserRepository, + val studentInfoRepository: StudentInfoRepository, + val fixedRoomRepository: FixedRoomRepository, + val attendanceRepository: AttendanceRepository +) { + + lateinit var student: UserEntity + + @BeforeEach + fun setUp() { + // 학생 생성 + student = userRepository.save( + UserEntity( + email = "test@beep.com", + username = "테스트학생", + role = UserRole.STUDENT, + currentStatus = AttendanceType.CLASS + ) + ) + + // 학생 정보 저장 + studentInfoRepository.save( + StudentInfoEntity( + user = student, + grade = 2, + cls = 1, + num = 10 + ) + ) + + // 고정실 저장 + fixedRoomRepository.save( + FixedRoomEntity( + user = student, + room = Room.LAB1, + type = AttendanceType.AFTER_SCHOOL + ) + ) + } + + @Test + @DisplayName("학년, 반으로 학생 정보와 오늘 출석 정보를 DTO로 조회한다") + fun findAllInfoByStatusAndGradeAndCls() { + // given + val today = LocalDate.now() + attendanceRepository.save( + AttendanceEntity( + user = student, + date = today, + period = 1, + type = AttendanceType.OUTGOING + ) + ) + + // when + val results = studentQueryRepository.findAllInfoByStatusAndGradeAndCls(2, 1, null) + + // then + assertThat(results).hasSize(1) + val dto = results[0] + + // User 검증 + assertThat(dto.user.id).isEqualTo(student.id) + assertThat(dto.user.username).isEqualTo("테스트학생") + + // StudentInfo 검증 (num 필드 확인) + assertThat(dto.studentInfo.num).isEqualTo(10) + + // FixedRooms 검증 (List 이름 변경: fixedRoom -> fixedRooms) + assertThat(dto.fixedRooms).hasSize(1) + assertThat(dto.fixedRooms?.get(0)?.room).isEqualTo(Room.LAB1) + + // Attendances 검증 (List 이름 변경: attendance -> attendances) + assertThat(dto.attendances).hasSize(1) + assertThat(dto.attendances?.get(0)?.type).isEqualTo(AttendanceType.OUTGOING) + } + + @Test + @DisplayName("상태(Status) 조건이 있을 경우 해당 상태의 학생만 조회된다") + fun findAllInfoByStatusAndGradeAndCls_WithStatus() { + // given (currentStatus = CLASS) + + // when & then + val resultEmpty = studentQueryRepository.findAllInfoByStatusAndGradeAndCls(2, 1, AttendanceType.OUTGOING) + assertThat(resultEmpty).isEmpty() + + val resultPresent = studentQueryRepository.findAllInfoByStatusAndGradeAndCls(2, 1, AttendanceType.CLASS) + assertThat(resultPresent).hasSize(1) + } + + @Test + @DisplayName("고정실(Room)과 타입으로 학생들을 조회한다") + fun findAllByStatusAndRoomAndType() { + // given (Room.LAB1, AFTER_SCHOOL) + + // when + val result = studentQueryRepository.findAllByStatusAndRoomAndType( + Room.LAB1, // 변경된 Enum 사용 + AttendanceType.AFTER_SCHOOL, + null + ) + + // then + assertThat(result).hasSize(1) + assertThat(result[0].username).isEqualTo("테스트학생") + } +} \ No newline at end of file diff --git a/src/test/kotlin/com/b/beep/global/config/QueryDslConfigTest.kt b/src/test/kotlin/com/b/beep/global/config/QueryDslConfigTest.kt new file mode 100644 index 00000000..f69023e4 --- /dev/null +++ b/src/test/kotlin/com/b/beep/global/config/QueryDslConfigTest.kt @@ -0,0 +1,18 @@ +package com.b.beep.global.config + +import com.querydsl.jpa.impl.JPAQueryFactory +import jakarta.persistence.EntityManager +import jakarta.persistence.PersistenceContext +import org.springframework.boot.test.context.TestConfiguration +import org.springframework.context.annotation.Bean + +@TestConfiguration +class QueryDslConfigTest { + @PersistenceContext + lateinit var entityManager: EntityManager + + @Bean + fun jpaQueryFactory(): JPAQueryFactory { + return JPAQueryFactory(entityManager) + } +} \ No newline at end of file diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index 78bf358e..2bb789c6 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -7,7 +7,7 @@ spring: show-sql: true properties: hibernate: - dialect: org.hibernate.dialect.MySQLDialect + dialect: org.hibernate.dialect.H2Dialect format_sql: true mail: host: smtp.gmail.com