From f2ef8835c66253c7f7270989a1728d0853cba1c5 Mon Sep 17 00:00:00 2001 From: ddingmin Date: Fri, 17 May 2024 00:44:44 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=82=B4=20=EC=B6=9C=EC=84=9D=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=EC=97=90=20=EA=B2=B0=EC=84=9D=20=ED=98=84?= =?UTF-8?q?=ED=99=A9=20=EC=9D=91=EB=8B=B5=EA=B0=92=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../makers/domain/model/AttendanceStatus.kt | 11 +++--- .../domain/usecase/GetMemberAttendances.kt | 39 +++++++++++++++---- .../controller/AttendanceController.kt | 6 +-- .../dto/response/MyAttendanceResponse.kt | 27 +++++++++++++ 4 files changed, 67 insertions(+), 16 deletions(-) create mode 100644 src/main/kotlin/com/depromeet/makers/presentation/restapi/dto/response/MyAttendanceResponse.kt diff --git a/src/main/kotlin/com/depromeet/makers/domain/model/AttendanceStatus.kt b/src/main/kotlin/com/depromeet/makers/domain/model/AttendanceStatus.kt index 1cddc5c..66e116f 100644 --- a/src/main/kotlin/com/depromeet/makers/domain/model/AttendanceStatus.kt +++ b/src/main/kotlin/com/depromeet/makers/domain/model/AttendanceStatus.kt @@ -1,12 +1,13 @@ package com.depromeet.makers.domain.model enum class AttendanceStatus( - val description: String + val description: String, + val point: Double, ) { - ATTENDANCE_ON_HOLD("출석 대기"), - ATTENDANCE("출석"), - ABSENCE("결석"), - TARDY("지각"); + ATTENDANCE_ON_HOLD("출석 대기", 0.0), + ATTENDANCE("출석", 0.0), + ABSENCE("결석", 1.0), + TARDY("지각", 0.5); fun isAttendanceOnHold() = this == ATTENDANCE_ON_HOLD diff --git a/src/main/kotlin/com/depromeet/makers/domain/usecase/GetMemberAttendances.kt b/src/main/kotlin/com/depromeet/makers/domain/usecase/GetMemberAttendances.kt index 9950cb6..76d745d 100644 --- a/src/main/kotlin/com/depromeet/makers/domain/usecase/GetMemberAttendances.kt +++ b/src/main/kotlin/com/depromeet/makers/domain/usecase/GetMemberAttendances.kt @@ -2,18 +2,27 @@ package com.depromeet.makers.domain.usecase import com.depromeet.makers.domain.gateway.AttendanceGateway import com.depromeet.makers.domain.gateway.MemberGateway +import com.depromeet.makers.domain.gateway.SessionGateway import com.depromeet.makers.domain.model.Attendance class GetMemberAttendances( private val attendanceGateway: AttendanceGateway, private val memberGateway: MemberGateway, -) : UseCase> { + private val sessionGateway: SessionGateway, +) : UseCase { data class GetMemberAttendancesInput( val memberId: String, val generation: Int, ) - override fun execute(input: GetMemberAttendancesInput): List { + data class GetMemberAttendancesOutput( + val generation: Int, + val offlineAbsenceScore: Double, + val totalAbsenceScore: Double, + val attendances: List, + ) + + override fun execute(input: GetMemberAttendancesInput): GetMemberAttendancesOutput { val member = memberGateway.getById(input.memberId) val attendances = attendanceGateway.findAllByMemberIdAndGeneration(member.memberId, input.generation) @@ -22,13 +31,29 @@ class GetMemberAttendances( (1..16).filter { week -> !attendances.contains(week) } .forEach { week -> - attendances[week] = Attendance.newAttendance( - member = member, - generation = input.generation, - week = week, + attendances[week] = attendanceGateway.save( + Attendance.newAttendance( + member = member, + generation = input.generation, + week = week, + ) ) } - return attendances.values.sortedBy { it.week } + var offlineAbsenceScore = 0.0 + var totalAbsenceScore = 0.0 + attendances.values.forEach { + offlineAbsenceScore += if (it.attendanceStatus.isAbsence() && + runCatching { sessionGateway.findByGenerationAndWeek(input.generation, it.week).isOffline() } + .getOrDefault(false) + ) 1.0 else 0.0 + totalAbsenceScore += it.attendanceStatus.point + } + return GetMemberAttendancesOutput( + generation = input.generation, + offlineAbsenceScore = offlineAbsenceScore, + totalAbsenceScore = totalAbsenceScore, + attendances = attendances.values.sortedBy { it.week } + ) } } diff --git a/src/main/kotlin/com/depromeet/makers/presentation/restapi/controller/AttendanceController.kt b/src/main/kotlin/com/depromeet/makers/presentation/restapi/controller/AttendanceController.kt index 759613a..727157f 100644 --- a/src/main/kotlin/com/depromeet/makers/presentation/restapi/controller/AttendanceController.kt +++ b/src/main/kotlin/com/depromeet/makers/presentation/restapi/controller/AttendanceController.kt @@ -3,7 +3,6 @@ package com.depromeet.makers.presentation.restapi.controller import com.depromeet.makers.domain.usecase.GetMemberAttendances import com.depromeet.makers.domain.usecase.UpdateAttendance import com.depromeet.makers.presentation.restapi.dto.request.UpdateAttendanceRequest -import com.depromeet.makers.presentation.restapi.dto.response.AttendanceResponse import com.depromeet.makers.presentation.restapi.dto.response.UpdateAttendanceResponse import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.tags.Tag @@ -26,14 +25,13 @@ class AttendanceController( fun getMyAttendance( authentication: Authentication, @RequestParam(defaultValue = "15") generation: Int, - ): List { - val attendances = getMemberAttendances.execute( + ): GetMemberAttendances.GetMemberAttendancesOutput { + return getMemberAttendances.execute( GetMemberAttendances.GetMemberAttendancesInput( memberId = authentication.name, generation = generation, ) ) - return attendances.map { AttendanceResponse.fromDomain(it) } } @PreAuthorize("hasRole('ORGANIZER')") diff --git a/src/main/kotlin/com/depromeet/makers/presentation/restapi/dto/response/MyAttendanceResponse.kt b/src/main/kotlin/com/depromeet/makers/presentation/restapi/dto/response/MyAttendanceResponse.kt new file mode 100644 index 0000000..7e9ac55 --- /dev/null +++ b/src/main/kotlin/com/depromeet/makers/presentation/restapi/dto/response/MyAttendanceResponse.kt @@ -0,0 +1,27 @@ +package com.depromeet.makers.presentation.restapi.dto.response + +import com.depromeet.makers.domain.usecase.GetMemberAttendances +import io.swagger.v3.oas.annotations.media.Schema + +data class MyAttendanceResponse( + + @Schema(description = "기수", example = "15") + val generation: Int, + + @Schema(description = "오프라인 결석 점수", example = "1.0") + val offlineAbsenceScore: Double, + + @Schema(description = "총 결석 점수 (지각: 0.5)", example = "2.5") + val totalAbsenceScore: Double, + + val attendances: List +) { + companion object { + fun fromDomain(getMemberAttendancesOutput: GetMemberAttendances.GetMemberAttendancesOutput) = MyAttendanceResponse( + generation = getMemberAttendancesOutput.generation, + offlineAbsenceScore = getMemberAttendancesOutput.offlineAbsenceScore, + totalAbsenceScore = getMemberAttendancesOutput.totalAbsenceScore, + attendances = getMemberAttendancesOutput.attendances.map { AttendanceResponse.fromDomain(it) } + ) + } +}