Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/DSM-PICK/PICK2024_SERVER
Browse files Browse the repository at this point in the history
…into develop
  • Loading branch information
rudeh2926 committed Apr 10, 2024
2 parents be9ad54 + c9a9927 commit 8941afc
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ interface AttendanceRepository : Repository<AttendanceJpaEntity, UUID> {
fun saveAll(entity: Iterable<AttendanceJpaEntity>)

fun findByUserId(userId: UUID): AttendanceJpaEntity

fun findAll(): List<AttendanceJpaEntity>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package dsm.pick2024.domain.attendance.port.`in`

interface ResetAttendanceUseCase {
fun reset()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ interface AttendancePort :
SaveAll,
FindByUserIdPort,
QueryClassAttendancePort,
QueryClubAttendancePort
QueryClubAttendancePort,
FindAllAttendancePort
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package dsm.pick2024.domain.attendance.port.out

import dsm.pick2024.domain.attendance.domain.Attendance

interface FindAllAttendancePort {
fun findAll(): List<Attendance>
}
Original file line number Diff line number Diff line change
@@ -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<Attendance>()

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
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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() {
Expand All @@ -25,4 +27,9 @@ class ScheduleService(
fun mealSave() {
mealUseCase.saveNeisInfoToDatabase()
}

@Scheduled(cron = "0 00 21 * * ?", zone = "Asia/Seoul")
fun resetTable() {
resetAttendanceUseCase.reset()
}
}

0 comments on commit 8941afc

Please sign in to comment.