-
Notifications
You must be signed in to change notification settings - Fork 1
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: 현재 출석 상태 조회 기능 구현 #29
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
src/main/kotlin/com/depromeet/makers/domain/usecase/GetCheckInStatus.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package com.depromeet.makers.domain.usecase | ||
|
||
import com.depromeet.makers.domain.exception.InvalidCheckInTimeException | ||
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 | ||
import com.depromeet.makers.domain.model.AttendanceStatus | ||
import java.time.DayOfWeek | ||
import java.time.LocalDateTime | ||
|
||
class GetCheckInStatus( | ||
private val memberGateway: MemberGateway, | ||
private val sessionGateway: SessionGateway, | ||
private val attendanceGateway: AttendanceGateway, | ||
) : UseCase<GetCheckInStatus.GetCheckInStatusInput, GetCheckInStatus.GetCheckInStatusOutput> { | ||
data class GetCheckInStatusInput( | ||
val now: LocalDateTime, | ||
val memberId: String, | ||
) | ||
|
||
data class GetCheckInStatusOutput( | ||
val generation: Int, | ||
val week: Int, | ||
val isBeforeSession15minutes: Boolean, | ||
val needFloatingButton: Boolean, | ||
val expectAttendanceStatus: AttendanceStatus, | ||
) | ||
|
||
override fun execute(input: GetCheckInStatusInput): GetCheckInStatusOutput { | ||
val member = memberGateway.getById(input.memberId) | ||
|
||
val monday = input.now.getMonday() | ||
val thisWeekSession = sessionGateway.findByStartTimeBetween( | ||
monday, | ||
monday.plusDays(7) | ||
) ?: throw InvalidCheckInTimeException() | ||
|
||
val attendance = runCatching { | ||
attendanceGateway.findByMemberIdAndGenerationAndWeek( | ||
member.memberId, | ||
thisWeekSession.generation, | ||
thisWeekSession.week | ||
) | ||
}.getOrDefault( | ||
Attendance.newAttendance( | ||
generation = thisWeekSession.generation, | ||
week = thisWeekSession.week, | ||
member = member, | ||
) | ||
) | ||
|
||
// 현재 시간이 세션 시간 15분 전 && 세션 시작 시간 사이인지 확인 -> 팝업 띄우기 여부 | ||
val isBeforeSession15minutes = input.now.isAfter(thisWeekSession.startTime.minusMinutes(15)) && | ||
input.now.isBefore(thisWeekSession.startTime) | ||
|
||
// 현재 시간이 출석 요청 가능 시간 사이 && 출석 상태가 ON_HOLD인 경우 -> 플로팅 버튼 띄우기 여부 | ||
val needFloatingButton = attendance.isAttendanceOnHold() && | ||
input.now.isAfter(thisWeekSession.startTime) && input.now.isBefore(thisWeekSession.startTime.plusMinutes(120)) | ||
|
||
val expectAttendanceStatus = when { | ||
// 세션 시작 ~ 30분 사이 -> 출석으로 인정될 상태 | ||
input.now.isAfter(thisWeekSession.startTime) && input.now.isBefore(thisWeekSession.startTime.plusMinutes(30)) -> AttendanceStatus.ATTENDANCE | ||
// 세션 시작 30분 ~ 120분 사이 -> 지각으로 인정될 상태 | ||
input.now.isAfter(thisWeekSession.startTime.plusMinutes(30)) && | ||
input.now.isBefore(thisWeekSession.startTime.plusMinutes(120)) -> AttendanceStatus.TARDY | ||
|
||
else -> AttendanceStatus.ATTENDANCE_ON_HOLD | ||
} | ||
|
||
return GetCheckInStatusOutput( | ||
generation = attendance.generation, | ||
week = attendance.week, | ||
isBeforeSession15minutes = isBeforeSession15minutes, | ||
needFloatingButton = needFloatingButton, | ||
expectAttendanceStatus = expectAttendanceStatus, | ||
) | ||
} | ||
|
||
private fun LocalDateTime.getMonday(): LocalDateTime { | ||
val dayOfWeek = this.dayOfWeek | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 요거 LocalDate#withDayOfWeek(MONDAY) 형태로도 꺼낼 수 있었던거같아요 |
||
val daysToAdd = DayOfWeek.MONDAY.value - dayOfWeek.value | ||
return this.plusDays(daysToAdd.toLong()) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...in/kotlin/com/depromeet/makers/presentation/restapi/dto/response/CheckInStatusResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.depromeet.makers.presentation.restapi.dto.response | ||
|
||
import com.depromeet.makers.domain.model.AttendanceStatus | ||
import io.swagger.v3.oas.annotations.media.Schema | ||
|
||
@Schema(name = "CheckInStatusResponse", description = "세션 출석 상태 응답 DTO") | ||
data class CheckInStatusResponse( | ||
@Schema(name = "generation", description = "기수") | ||
val generation: Int, | ||
|
||
@Schema(name = "week", description = "주차") | ||
val week: Int, | ||
|
||
@Schema(name = "isBeforeSession15minutes", description = "팝업 메시지를 띄울지 여부 (세션 시작 15분 전 ~ 세션 시작 시간 사이인 경우)") | ||
val isBeforeSession15minutes: Boolean, | ||
|
||
@Schema(name = "needFloatingButton", description = "플로팅 버튼 노출 여부 (현재 시간이 출석 요청 가능 시간 && 멤버의 출석 상태가 ATTENDANCE_ON_HOLD 인 경우)") | ||
val needFloatingButton: Boolean, | ||
|
||
@Schema(name = "expectAttendanceStatus", description = "출석 시 예상하는 상태") | ||
val expectAttendanceStatus: AttendanceStatus, | ||
) { | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이거 당일이 아니라 그 주 range로 찾는 이유가 따로 있나용?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
원래 있던 로직 가져온거긴한데 당일 아니면 시간체크 다르게 먹어서 크게 상관없을것 같긴 합니다!