From 9da6479ae003fa47d3146737f5565d35f363b50d Mon Sep 17 00:00:00 2001 From: soohyeon Date: Tue, 9 Apr 2024 20:01:20 +0900 Subject: [PATCH 1/3] add :: QueryClubAttendanceResponse --- .../port/in/QueryClubAttendanceUseCase.kt | 4 ++-- .../dto/response/QueryAttendanceResponse.kt | 2 -- .../dto/response/QueryClubAttendanceResponse.kt | 17 +++++++++++++++++ .../service/QueryClassAttendanceService.kt | 2 -- .../service/QueryClubAttendanceService.kt | 6 +++--- 5 files changed, 22 insertions(+), 9 deletions(-) create mode 100644 src/main/kotlin/dsm/pick2024/domain/attendance/presentation/dto/response/QueryClubAttendanceResponse.kt diff --git a/src/main/kotlin/dsm/pick2024/domain/attendance/port/in/QueryClubAttendanceUseCase.kt b/src/main/kotlin/dsm/pick2024/domain/attendance/port/in/QueryClubAttendanceUseCase.kt index e5b29722..278c0084 100644 --- a/src/main/kotlin/dsm/pick2024/domain/attendance/port/in/QueryClubAttendanceUseCase.kt +++ b/src/main/kotlin/dsm/pick2024/domain/attendance/port/in/QueryClubAttendanceUseCase.kt @@ -1,7 +1,7 @@ package dsm.pick2024.domain.attendance.port.`in` -import dsm.pick2024.domain.attendance.presentation.dto.response.QueryAttendanceResponse +import dsm.pick2024.domain.attendance.presentation.dto.response.QueryClubAttendanceResponse interface QueryClubAttendanceUseCase { - fun queryClubAttendance(club: String): List? + fun queryClubAttendance(club: String): List? } diff --git a/src/main/kotlin/dsm/pick2024/domain/attendance/presentation/dto/response/QueryAttendanceResponse.kt b/src/main/kotlin/dsm/pick2024/domain/attendance/presentation/dto/response/QueryAttendanceResponse.kt index 2d0d52e8..a380c89e 100644 --- a/src/main/kotlin/dsm/pick2024/domain/attendance/presentation/dto/response/QueryAttendanceResponse.kt +++ b/src/main/kotlin/dsm/pick2024/domain/attendance/presentation/dto/response/QueryAttendanceResponse.kt @@ -9,8 +9,6 @@ data class QueryAttendanceResponse( val grade: Int, val classNum: Int, val num: Int, - val status6: Status, - val status7: Status, val status8: Status, val status9: Status, val status10: Status diff --git a/src/main/kotlin/dsm/pick2024/domain/attendance/presentation/dto/response/QueryClubAttendanceResponse.kt b/src/main/kotlin/dsm/pick2024/domain/attendance/presentation/dto/response/QueryClubAttendanceResponse.kt new file mode 100644 index 00000000..41a0a83a --- /dev/null +++ b/src/main/kotlin/dsm/pick2024/domain/attendance/presentation/dto/response/QueryClubAttendanceResponse.kt @@ -0,0 +1,17 @@ +package dsm.pick2024.domain.attendance.presentation.dto.response + +import dsm.pick2024.domain.afterschool.enums.Status +import java.util.UUID + +data class QueryClubAttendanceResponse( + val id: UUID, + val username: String, + val grade: Int, + val classNum: Int, + val num: Int, + val status6: Status, + val status7: Status, + val status8: Status, + val status9: Status, + val status10: Status +) diff --git a/src/main/kotlin/dsm/pick2024/domain/attendance/service/QueryClassAttendanceService.kt b/src/main/kotlin/dsm/pick2024/domain/attendance/service/QueryClassAttendanceService.kt index d1163f15..1a4d5c41 100644 --- a/src/main/kotlin/dsm/pick2024/domain/attendance/service/QueryClassAttendanceService.kt +++ b/src/main/kotlin/dsm/pick2024/domain/attendance/service/QueryClassAttendanceService.kt @@ -20,8 +20,6 @@ class QueryClassAttendanceService( grade = it.grade, classNum = it.classNum, num = it.num, - status6 = it.period6, - status7 = it.period7, status8 = it.period8, status9 = it.period9, status10 = it.period10 diff --git a/src/main/kotlin/dsm/pick2024/domain/attendance/service/QueryClubAttendanceService.kt b/src/main/kotlin/dsm/pick2024/domain/attendance/service/QueryClubAttendanceService.kt index f202c14c..90bbdd0f 100644 --- a/src/main/kotlin/dsm/pick2024/domain/attendance/service/QueryClubAttendanceService.kt +++ b/src/main/kotlin/dsm/pick2024/domain/attendance/service/QueryClubAttendanceService.kt @@ -2,7 +2,7 @@ package dsm.pick2024.domain.attendance.service import dsm.pick2024.domain.attendance.port.`in`.QueryClubAttendanceUseCase import dsm.pick2024.domain.attendance.port.out.QueryClubAttendancePort -import dsm.pick2024.domain.attendance.presentation.dto.response.QueryAttendanceResponse +import dsm.pick2024.domain.attendance.presentation.dto.response.QueryClubAttendanceResponse import dsm.pick2024.domain.earlyreturn.exception.ClubNotFoundException import org.springframework.stereotype.Service @@ -10,7 +10,7 @@ import org.springframework.stereotype.Service class QueryClubAttendanceService( private val queryClubAttendancePort: QueryClubAttendancePort ) : QueryClubAttendanceUseCase { - override fun queryClubAttendance(club: String): List { + override fun queryClubAttendance(club: String): List { val students = queryClubAttendancePort.findByClub(club) if (students.isEmpty()) { @@ -18,7 +18,7 @@ class QueryClubAttendanceService( } return students.map { it -> - QueryAttendanceResponse( + QueryClubAttendanceResponse( id = it.userId, username = it.name, grade = it.grade, From 4b55bf5e9a1ecce68ce0fccae09f729609083b31 Mon Sep 17 00:00:00 2001 From: soohyeon Date: Tue, 9 Apr 2024 20:15:42 +0900 Subject: [PATCH 2/3] delete --- .../port/in/QueryClubAttendanceUseCase.kt | 4 ++-- .../dto/response/QueryAttendanceResponse.kt | 2 ++ .../dto/response/QueryClubAttendanceResponse.kt | 17 ----------------- .../service/QueryClassAttendanceService.kt | 2 ++ .../service/QueryClubAttendanceService.kt | 6 +++--- 5 files changed, 9 insertions(+), 22 deletions(-) delete mode 100644 src/main/kotlin/dsm/pick2024/domain/attendance/presentation/dto/response/QueryClubAttendanceResponse.kt diff --git a/src/main/kotlin/dsm/pick2024/domain/attendance/port/in/QueryClubAttendanceUseCase.kt b/src/main/kotlin/dsm/pick2024/domain/attendance/port/in/QueryClubAttendanceUseCase.kt index 278c0084..e5b29722 100644 --- a/src/main/kotlin/dsm/pick2024/domain/attendance/port/in/QueryClubAttendanceUseCase.kt +++ b/src/main/kotlin/dsm/pick2024/domain/attendance/port/in/QueryClubAttendanceUseCase.kt @@ -1,7 +1,7 @@ package dsm.pick2024.domain.attendance.port.`in` -import dsm.pick2024.domain.attendance.presentation.dto.response.QueryClubAttendanceResponse +import dsm.pick2024.domain.attendance.presentation.dto.response.QueryAttendanceResponse interface QueryClubAttendanceUseCase { - fun queryClubAttendance(club: String): List? + fun queryClubAttendance(club: String): List? } diff --git a/src/main/kotlin/dsm/pick2024/domain/attendance/presentation/dto/response/QueryAttendanceResponse.kt b/src/main/kotlin/dsm/pick2024/domain/attendance/presentation/dto/response/QueryAttendanceResponse.kt index a380c89e..2d0d52e8 100644 --- a/src/main/kotlin/dsm/pick2024/domain/attendance/presentation/dto/response/QueryAttendanceResponse.kt +++ b/src/main/kotlin/dsm/pick2024/domain/attendance/presentation/dto/response/QueryAttendanceResponse.kt @@ -9,6 +9,8 @@ data class QueryAttendanceResponse( val grade: Int, val classNum: Int, val num: Int, + val status6: Status, + val status7: Status, val status8: Status, val status9: Status, val status10: Status diff --git a/src/main/kotlin/dsm/pick2024/domain/attendance/presentation/dto/response/QueryClubAttendanceResponse.kt b/src/main/kotlin/dsm/pick2024/domain/attendance/presentation/dto/response/QueryClubAttendanceResponse.kt deleted file mode 100644 index 41a0a83a..00000000 --- a/src/main/kotlin/dsm/pick2024/domain/attendance/presentation/dto/response/QueryClubAttendanceResponse.kt +++ /dev/null @@ -1,17 +0,0 @@ -package dsm.pick2024.domain.attendance.presentation.dto.response - -import dsm.pick2024.domain.afterschool.enums.Status -import java.util.UUID - -data class QueryClubAttendanceResponse( - val id: UUID, - val username: String, - val grade: Int, - val classNum: Int, - val num: Int, - val status6: Status, - val status7: Status, - val status8: Status, - val status9: Status, - val status10: Status -) diff --git a/src/main/kotlin/dsm/pick2024/domain/attendance/service/QueryClassAttendanceService.kt b/src/main/kotlin/dsm/pick2024/domain/attendance/service/QueryClassAttendanceService.kt index 1a4d5c41..d1163f15 100644 --- a/src/main/kotlin/dsm/pick2024/domain/attendance/service/QueryClassAttendanceService.kt +++ b/src/main/kotlin/dsm/pick2024/domain/attendance/service/QueryClassAttendanceService.kt @@ -20,6 +20,8 @@ class QueryClassAttendanceService( grade = it.grade, classNum = it.classNum, num = it.num, + status6 = it.period6, + status7 = it.period7, status8 = it.period8, status9 = it.period9, status10 = it.period10 diff --git a/src/main/kotlin/dsm/pick2024/domain/attendance/service/QueryClubAttendanceService.kt b/src/main/kotlin/dsm/pick2024/domain/attendance/service/QueryClubAttendanceService.kt index 90bbdd0f..f202c14c 100644 --- a/src/main/kotlin/dsm/pick2024/domain/attendance/service/QueryClubAttendanceService.kt +++ b/src/main/kotlin/dsm/pick2024/domain/attendance/service/QueryClubAttendanceService.kt @@ -2,7 +2,7 @@ package dsm.pick2024.domain.attendance.service import dsm.pick2024.domain.attendance.port.`in`.QueryClubAttendanceUseCase import dsm.pick2024.domain.attendance.port.out.QueryClubAttendancePort -import dsm.pick2024.domain.attendance.presentation.dto.response.QueryClubAttendanceResponse +import dsm.pick2024.domain.attendance.presentation.dto.response.QueryAttendanceResponse import dsm.pick2024.domain.earlyreturn.exception.ClubNotFoundException import org.springframework.stereotype.Service @@ -10,7 +10,7 @@ import org.springframework.stereotype.Service class QueryClubAttendanceService( private val queryClubAttendancePort: QueryClubAttendancePort ) : QueryClubAttendanceUseCase { - override fun queryClubAttendance(club: String): List { + override fun queryClubAttendance(club: String): List { val students = queryClubAttendancePort.findByClub(club) if (students.isEmpty()) { @@ -18,7 +18,7 @@ class QueryClubAttendanceService( } return students.map { it -> - QueryClubAttendanceResponse( + QueryAttendanceResponse( id = it.userId, username = it.name, grade = it.grade, From c9a9927be2e2d9748428abf44776b1cef1147697 Mon Sep 17 00:00:00 2001 From: soohyeon Date: Tue, 9 Apr 2024 22:29:32 +0900 Subject: [PATCH 3/3] add :: resetTable --- .../AttendancePersistenceAdapter.kt | 2 + .../repository/AttendanceRepository.kt | 2 + .../port/in/ResetAttendanceUseCase.kt | 5 +++ .../attendance/port/out/AttendancePort.kt | 3 +- .../port/out/FindAllAttendancePort.kt | 7 ++++ .../service/ResetAttendanceService.kt | 39 +++++++++++++++++++ .../schedule/ScheduleService.kt | 9 ++++- 7 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 src/main/kotlin/dsm/pick2024/domain/attendance/port/in/ResetAttendanceUseCase.kt create mode 100644 src/main/kotlin/dsm/pick2024/domain/attendance/port/out/FindAllAttendancePort.kt create mode 100644 src/main/kotlin/dsm/pick2024/domain/attendance/service/ResetAttendanceService.kt diff --git a/src/main/kotlin/dsm/pick2024/domain/attendance/persistence/AttendancePersistenceAdapter.kt b/src/main/kotlin/dsm/pick2024/domain/attendance/persistence/AttendancePersistenceAdapter.kt index 3df959f6..fc9f6982 100644 --- a/src/main/kotlin/dsm/pick2024/domain/attendance/persistence/AttendancePersistenceAdapter.kt +++ b/src/main/kotlin/dsm/pick2024/domain/attendance/persistence/AttendancePersistenceAdapter.kt @@ -23,6 +23,8 @@ class AttendancePersistenceAdapter( override fun findByUserId(userId: UUID) = attendanceJpaRepository.findByUserId(userId).let { attendanceMapper.toDomain(it) } + override fun findAll() = attendanceJpaRepository.findAll().map { attendanceMapper.toDomain(it) } + override fun findByGradeAndClassNum( grade: Int, classNum: Int diff --git a/src/main/kotlin/dsm/pick2024/domain/attendance/persistence/repository/AttendanceRepository.kt b/src/main/kotlin/dsm/pick2024/domain/attendance/persistence/repository/AttendanceRepository.kt index 6fe5a0f7..755da5e1 100644 --- a/src/main/kotlin/dsm/pick2024/domain/attendance/persistence/repository/AttendanceRepository.kt +++ b/src/main/kotlin/dsm/pick2024/domain/attendance/persistence/repository/AttendanceRepository.kt @@ -8,4 +8,6 @@ interface AttendanceRepository : Repository { fun saveAll(entity: Iterable) fun findByUserId(userId: UUID): AttendanceJpaEntity + + fun findAll(): List } diff --git a/src/main/kotlin/dsm/pick2024/domain/attendance/port/in/ResetAttendanceUseCase.kt b/src/main/kotlin/dsm/pick2024/domain/attendance/port/in/ResetAttendanceUseCase.kt new file mode 100644 index 00000000..a784f8a3 --- /dev/null +++ b/src/main/kotlin/dsm/pick2024/domain/attendance/port/in/ResetAttendanceUseCase.kt @@ -0,0 +1,5 @@ +package dsm.pick2024.domain.attendance.port.`in` + +interface ResetAttendanceUseCase { + fun reset() +} diff --git a/src/main/kotlin/dsm/pick2024/domain/attendance/port/out/AttendancePort.kt b/src/main/kotlin/dsm/pick2024/domain/attendance/port/out/AttendancePort.kt index c347f6c7..9bda5e4d 100644 --- a/src/main/kotlin/dsm/pick2024/domain/attendance/port/out/AttendancePort.kt +++ b/src/main/kotlin/dsm/pick2024/domain/attendance/port/out/AttendancePort.kt @@ -4,4 +4,5 @@ interface AttendancePort : SaveAll, FindByUserIdPort, QueryClassAttendancePort, - QueryClubAttendancePort + QueryClubAttendancePort, + FindAllAttendancePort diff --git a/src/main/kotlin/dsm/pick2024/domain/attendance/port/out/FindAllAttendancePort.kt b/src/main/kotlin/dsm/pick2024/domain/attendance/port/out/FindAllAttendancePort.kt new file mode 100644 index 00000000..02a5cfe3 --- /dev/null +++ b/src/main/kotlin/dsm/pick2024/domain/attendance/port/out/FindAllAttendancePort.kt @@ -0,0 +1,7 @@ +package dsm.pick2024.domain.attendance.port.out + +import dsm.pick2024.domain.attendance.domain.Attendance + +interface FindAllAttendancePort { + fun findAll(): List +} diff --git a/src/main/kotlin/dsm/pick2024/domain/attendance/service/ResetAttendanceService.kt b/src/main/kotlin/dsm/pick2024/domain/attendance/service/ResetAttendanceService.kt new file mode 100644 index 00000000..3b9d1a2c --- /dev/null +++ b/src/main/kotlin/dsm/pick2024/domain/attendance/service/ResetAttendanceService.kt @@ -0,0 +1,39 @@ +package dsm.pick2024.domain.attendance.service + +import dsm.pick2024.domain.afterschool.enums.Status +import dsm.pick2024.domain.attendance.domain.Attendance +import dsm.pick2024.domain.attendance.port.`in`.ResetAttendanceUseCase +import dsm.pick2024.domain.attendance.port.out.FindAllAttendancePort +import dsm.pick2024.domain.attendance.port.out.SaveAll +import org.springframework.stereotype.Service + +@Service +class ResetAttendanceService( + private val findAllAttendancePort: FindAllAttendancePort, + private val saveAll: SaveAll +) : ResetAttendanceUseCase { + override fun reset() { + val allStudent = findAllAttendancePort.findAll() + val update = mutableListOf() + + allStudent.map { attendance -> + val updatedAttendance = + attendance.copy( + period6 = getStatus(attendance.period6), + period7 = getStatus(attendance.period7), + period8 = getStatus(attendance.period8), + period9 = getStatus(attendance.period9), + period10 = getStatus(attendance.period10) + ) + update.add(updatedAttendance) + } + + saveAll.saveAll(update) + } + + private fun getStatus(currentStatus: Status) = + when (currentStatus) { + Status.PICNIC, Status.EMPLOYMENT -> currentStatus + else -> Status.ATTENDANCE + } +} diff --git a/src/main/kotlin/dsm/pick2024/infrastructure/schedule/ScheduleService.kt b/src/main/kotlin/dsm/pick2024/infrastructure/schedule/ScheduleService.kt index 6fe87fef..e411d822 100644 --- a/src/main/kotlin/dsm/pick2024/infrastructure/schedule/ScheduleService.kt +++ b/src/main/kotlin/dsm/pick2024/infrastructure/schedule/ScheduleService.kt @@ -1,6 +1,7 @@ package dsm.pick2024.infrastructure.schedule import dsm.pick2024.domain.application.port.out.DeleteAllApplicationPort +import dsm.pick2024.domain.attendance.port.`in`.ResetAttendanceUseCase import dsm.pick2024.domain.classroom.port.out.DeleteAllClassRoomPort import dsm.pick2024.domain.earlyreturn.port.out.DeleteAllEarlyReturnPort import dsm.pick2024.domain.meal.port.`in`.MealUseCase @@ -12,7 +13,8 @@ class ScheduleService( private val deleteAllClassRoomPort: DeleteAllClassRoomPort, private val deleteAllEarlyReturnPort: DeleteAllEarlyReturnPort, private val deleteAllApplicationPort: DeleteAllApplicationPort, - private val mealUseCase: MealUseCase + private val mealUseCase: MealUseCase, + private val resetAttendanceUseCase: ResetAttendanceUseCase ) { @Scheduled(cron = "0 30 20 * * ?", zone = "Asia/Seoul") fun deleteTable() { @@ -25,4 +27,9 @@ class ScheduleService( fun mealSave() { mealUseCase.saveNeisInfoToDatabase() } + + @Scheduled(cron = "0 00 21 * * ?", zone = "Asia/Seoul") + fun resetTable() { + resetAttendanceUseCase.reset() + } }