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

[refactor/#708] attendance Time Format 방식 수정 #925

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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 @@ -25,8 +25,12 @@
package org.sopt.official.data.model.attendance

import kotlinx.datetime.LocalDateTime
import kotlinx.datetime.format.DateTimeFormat
import kotlinx.datetime.format.FormatStringsInDatetimeFormats
import kotlinx.datetime.format.byUnicodePattern
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import org.sopt.official.data.model.attendance.TimeFormat.getTimeFormat
import org.sopt.official.domain.entity.attendance.AttendanceStatus
import org.sopt.official.domain.entity.attendance.EventType
import org.sopt.official.domain.entity.attendance.SoptEvent
Expand All @@ -50,6 +54,7 @@ data class SoptEventResponse(
@SerialName("attendances")
val attendances: List<AttendanceResponse>
) {

@Serializable
data class AttendanceResponse(
@SerialName("status")
Expand All @@ -58,39 +63,37 @@ data class SoptEventResponse(
val attendedAt: String = ""
) {
fun toEntity(index: Int): SoptEvent.Attendance {
val attendedAtTime = if (this.status == "ATTENDANCE") {
LocalDateTime.parse(attendedAt).run {
"${this.hour.toString().padStart(2, '0')}:${this.minute.toString().padStart(2, '0')}"
val attendedAtTime =
if (this.status == "ATTENDANCE") {
LocalDateTime.parse(attendedAt).run {
val localDateTime = LocalDateTime.parse(attendedAt)
getTimeFormat().format(localDateTime)
}
} else {
"${index + 1}차 출석"
}
} else {
"${index + 1}차 출석"
}

return SoptEvent.Attendance(
AttendanceStatus.valueOf(this.status),
attendedAtTime
attendedAtTime,
)
}
}

fun toEntity(): SoptEvent {
val eventDateTime: String = if (startAt != "" && endAt != "") {
val eventDateTime: String = if (startAt.isNotBlank() && endAt.isNotBlank()) {
val startAtDateTime = LocalDateTime.parse(startAt)
val endAtDateTime = LocalDateTime.parse(endAt)

if (startAtDateTime.date == endAtDateTime.date) {
"${startAtDateTime.monthNumber}월 ${startAtDateTime.dayOfMonth}일 ${
startAtDateTime.hour.toString().padStart(2, '0')
}:${startAtDateTime.minute.toString().padStart(2, '0')} - ${
endAtDateTime.hour.toString().padStart(2, '0')
}:${endAtDateTime.minute.toString().padStart(2, '0')}"
"${startAtDateTime.monthNumber}\uC6D4 ${startAtDateTime.dayOfMonth}\uC77C " +
"${getTimeFormat().format(startAtDateTime)} - " +
getTimeFormat().format(endAtDateTime)
} else {
"${startAtDateTime.monthNumber}월 ${startAtDateTime.dayOfMonth}일 ${
startAtDateTime.hour.toString().padStart(2, '0')
}:${
startAtDateTime.minute.toString().padStart(2, '0')
} - ${endAtDateTime.monthNumber}월 ${endAtDateTime.dayOfMonth}일 ${
endAtDateTime.hour.toString().padStart(2, '0')
}:${endAtDateTime.minute.toString().padStart(2, '0')}"
"${startAtDateTime.monthNumber}\uC6D4 ${startAtDateTime.dayOfMonth}\uC77C " +
"${getTimeFormat().format(startAtDateTime)} - " +
"${endAtDateTime.monthNumber}\uC6D4 ${endAtDateTime.dayOfMonth}\uC77C " +
getTimeFormat().format(endAtDateTime)
Comment on lines -81 to +96
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 블로그 활용해서 이 부분 코드 어떻게 고칠 수 있을 지 한번 고민해보시면 좋을 것 같아요! 그러면 timeFormat 함수쪽 설계도 조금 달라져야겠죠?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

시험만 끝나고 얼른 해보겠습니다..!!
늦어져서 죄송합니다 ㅜㅜ

}
} else {
""
Expand All @@ -104,7 +107,18 @@ data class SoptEventResponse(
eventName = this.eventName,
message = this.message,
isAttendancePointAwardedEvent = type == "HAS_ATTENDANCE",
attendances = this.attendances.mapIndexed { index, attendanceResponse -> attendanceResponse.toEntity(index) }
attendances = this.attendances.mapIndexed { index, attendanceResponse -> attendanceResponse.toEntity(index) },
)
}
}

object TimeFormat {
private const val DEFAULT_FORMAT_PATTERN = "HH:mm"

@OptIn(FormatStringsInDatetimeFormats::class)
fun getTimeFormat(pattern: String = DEFAULT_FORMAT_PATTERN): DateTimeFormat<LocalDateTime> {
return LocalDateTime.Format {
byUnicodePattern(pattern)
}
}
}
Comment on lines +115 to +124
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 기능이 attendance에만 사용될 기능이 아닐 것 같아서 웬만하면 core common 모듈 쪽으로 빼두는 걸 추천드릴게요.