-
Notifications
You must be signed in to change notification settings - Fork 9
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
t1nm1ksun
wants to merge
3
commits into
sopt-makers:develop
Choose a base branch
from
t1nm1ksun:refactor/#708
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+35
−21
Open
Changes from all 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
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 |
---|---|---|
|
@@ -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 | ||
|
@@ -50,6 +54,7 @@ data class SoptEventResponse( | |
@SerialName("attendances") | ||
val attendances: List<AttendanceResponse> | ||
) { | ||
|
||
@Serializable | ||
data class AttendanceResponse( | ||
@SerialName("status") | ||
|
@@ -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) | ||
} | ||
} else { | ||
"" | ||
|
@@ -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
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. 이 기능이 attendance에만 사용될 기능이 아닐 것 같아서 웬만하면 core common 모듈 쪽으로 빼두는 걸 추천드릴게요. |
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.
이 블로그 활용해서 이 부분 코드 어떻게 고칠 수 있을 지 한번 고민해보시면 좋을 것 같아요! 그러면 timeFormat 함수쪽 설계도 조금 달라져야겠죠?
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.
시험만 끝나고 얼른 해보겠습니다..!!
늦어져서 죄송합니다 ㅜㅜ