Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 주차, 팀 별 출석 현황 조회 #35

Merged
merged 2 commits into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ interface AttendanceGateway {
fun findByMemberIdAndGenerationAndWeek(memberId: String, generation: Int, week: Int): Attendance

fun findAllByMemberIdAndGeneration(memberId: String, generation: Int): List<Attendance>

fun findAllByGenerationAndWeek(generation: Int, week: Int): List<Attendance>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.depromeet.makers.domain.usecase

import com.depromeet.makers.domain.gateway.AttendanceGateway
import com.depromeet.makers.domain.model.Attendance

class GetAttendancesByTeamAndWeek(
private val attendanceGateway: AttendanceGateway,
) : UseCase<GetAttendancesByTeamAndWeek.GetAttendancesByTeamAndWeekInput, List<Attendance>> {
data class GetAttendancesByTeamAndWeekInput(
val generation: Int,
val groupId: Int,
val week: Int,
)

override fun execute(input: GetAttendancesByTeamAndWeekInput): List<Attendance> {
return attendanceGateway.findAllByGenerationAndWeek(
input.generation,
input.week,
).filter {
it.member.generations.any {
it.generationId == input.generation && it.groupId == input.groupId
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ class AttendanceGatewayImpl(
.map { it.toDomain() }
}

override fun findAllByGenerationAndWeek(generation: Int, week: Int): List<Attendance> {
return jpaAttendanceRepository
.findAllByGenerationAndWeek(generation, week)
.map { it.toDomain() }
}

override fun getById(attendanceId: String): Attendance {
return jpaAttendanceRepository
.findById(attendanceId)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.depromeet.makers.presentation.restapi.controller

import com.depromeet.makers.domain.usecase.GetAttendancesByTeamAndWeek
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.MyAttendanceResponse
import com.depromeet.makers.presentation.restapi.dto.response.UpdateAttendanceResponse
import io.swagger.v3.oas.annotations.Operation
Expand All @@ -19,6 +21,7 @@ import org.springframework.web.bind.annotation.*
class AttendanceController(
private val getMemberAttendances: GetMemberAttendances,
private val updateAttendance: UpdateAttendance,
private val getAttendancesByTeamAndWeek: GetAttendancesByTeamAndWeek,
) {

@Operation(summary = "나의 출석 현황 조회", description = "로그인한 사용자의 출석 현황을 조회합니다.")
Expand Down Expand Up @@ -52,4 +55,21 @@ class AttendanceController(
)
return UpdateAttendanceResponse.fromDomain(attendances)
}

@Operation(summary = "팀, 주차별 출석률 조회", description = "팀, 주차별 출석률을 조회합니다.")
@GetMapping("/groupId/{groupId}")
fun getTeamAttendance(
@RequestParam(defaultValue = "15") generation: Int,
@RequestParam week: Int,
@PathVariable groupId: Int,
): List<AttendanceResponse> {
return getAttendancesByTeamAndWeek.execute(
GetAttendancesByTeamAndWeek.GetAttendancesByTeamAndWeekInput(
generation = generation,
groupId = groupId,
week = week,
)
).map { AttendanceResponse.fromDomain(it) }
.sortedBy { it.memberName }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ data class AttendanceResponse(
@Schema(description = "회원 ID", example = "01HWPNRE5TS9S7VC99WPETE5KE")
val memberId: String,

@Schema(description = "멤버 이름", example = "김개발")
val memberName: String,

@Schema(description = "멤버 포지션", example = "DESIGN")
val memberPosition: String,

@Schema(description = "세션 타입", example = "ONLINE")
val sessionType: SessionType,

Expand All @@ -39,6 +45,9 @@ data class AttendanceResponse(
sessionType = sessionType,
attendanceStatus = attendanceStatus,
attendanceTime = attendanceTime,
memberPosition = member.generations
.let { generations -> generations.find { it.generationId == generation }!!.position.name },
memberName = member.name,
)
}
}
Expand Down