Skip to content

Commit

Permalink
feat: 내 출석 조회에 결석 현황 응답값 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
ddingmin committed May 16, 2024
1 parent 4e1656f commit f2ef883
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<GetMemberAttendances.GetMemberAttendancesInput, List<Attendance>> {
private val sessionGateway: SessionGateway,
) : UseCase<GetMemberAttendances.GetMemberAttendancesInput, GetMemberAttendances.GetMemberAttendancesOutput> {
data class GetMemberAttendancesInput(
val memberId: String,
val generation: Int,
)

override fun execute(input: GetMemberAttendancesInput): List<Attendance> {
data class GetMemberAttendancesOutput(
val generation: Int,
val offlineAbsenceScore: Double,
val totalAbsenceScore: Double,
val attendances: List<Attendance>,
)

override fun execute(input: GetMemberAttendancesInput): GetMemberAttendancesOutput {
val member = memberGateway.getById(input.memberId)

val attendances = attendanceGateway.findAllByMemberIdAndGeneration(member.memberId, input.generation)
Expand All @@ -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 }
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,14 +25,13 @@ class AttendanceController(
fun getMyAttendance(
authentication: Authentication,
@RequestParam(defaultValue = "15") generation: Int,
): List<AttendanceResponse> {
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')")
Expand Down
Original file line number Diff line number Diff line change
@@ -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<AttendanceResponse>
) {
companion object {
fun fromDomain(getMemberAttendancesOutput: GetMemberAttendances.GetMemberAttendancesOutput) = MyAttendanceResponse(
generation = getMemberAttendancesOutput.generation,
offlineAbsenceScore = getMemberAttendancesOutput.offlineAbsenceScore,
totalAbsenceScore = getMemberAttendancesOutput.totalAbsenceScore,
attendances = getMemberAttendancesOutput.attendances.map { AttendanceResponse.fromDomain(it) }
)
}
}

0 comments on commit f2ef883

Please sign in to comment.