|
25 | 25 | package org.sopt.official.data.model.attendance
|
26 | 26 |
|
27 | 27 | import kotlinx.datetime.LocalDateTime
|
| 28 | +import kotlinx.datetime.format.DateTimeFormat |
28 | 29 | import kotlinx.datetime.format.FormatStringsInDatetimeFormats
|
29 | 30 | import kotlinx.datetime.format.byUnicodePattern
|
30 | 31 | import kotlinx.serialization.SerialName
|
31 | 32 | import kotlinx.serialization.Serializable
|
32 |
| -import org.sopt.official.data.model.attendance.TimeFormat.timeFormat |
| 33 | +import org.sopt.official.data.model.attendance.TimeFormat.getTimeFormat |
33 | 34 | import org.sopt.official.domain.entity.attendance.AttendanceStatus
|
34 | 35 | import org.sopt.official.domain.entity.attendance.EventType
|
35 | 36 | import org.sopt.official.domain.entity.attendance.SoptEvent
|
36 | 37 |
|
37 |
| - |
38 | 38 | @Serializable
|
39 | 39 | data class SoptEventResponse(
|
40 | 40 | @SerialName("id")
|
@@ -62,20 +62,20 @@ data class SoptEventResponse(
|
62 | 62 | @SerialName("attendedAt")
|
63 | 63 | val attendedAt: String = ""
|
64 | 64 | ) {
|
65 |
| - |
66 | 65 | fun toEntity(index: Int): SoptEvent.Attendance {
|
67 |
| - val attendedAtTime = if (this.status == "ATTENDANCE") { |
68 |
| - LocalDateTime.parse(attendedAt).run { |
69 |
| - val localDateTime = LocalDateTime.parse(attendedAt) |
70 |
| - timeFormat.format(localDateTime) |
| 66 | + val attendedAtTime = |
| 67 | + if (this.status == "ATTENDANCE") { |
| 68 | + LocalDateTime.parse(attendedAt).run { |
| 69 | + val localDateTime = LocalDateTime.parse(attendedAt) |
| 70 | + getTimeFormat().format(localDateTime) |
| 71 | + } |
| 72 | + } else { |
| 73 | + "${index + 1}차 출석" |
71 | 74 | }
|
72 |
| - } else { |
73 |
| - "${index + 1}차 출석" |
74 |
| - } |
75 | 75 |
|
76 | 76 | return SoptEvent.Attendance(
|
77 | 77 | AttendanceStatus.valueOf(this.status),
|
78 |
| - attendedAtTime |
| 78 | + attendedAtTime, |
79 | 79 | )
|
80 | 80 | }
|
81 | 81 | }
|
@@ -107,17 +107,18 @@ data class SoptEventResponse(
|
107 | 107 | eventName = this.eventName,
|
108 | 108 | message = this.message,
|
109 | 109 | isAttendancePointAwardedEvent = type == "HAS_ATTENDANCE",
|
110 |
| - attendances = this.attendances.mapIndexed { index, attendanceResponse -> attendanceResponse.toEntity(index) } |
| 110 | + attendances = this.attendances.mapIndexed { index, attendanceResponse -> attendanceResponse.toEntity(index) }, |
111 | 111 | )
|
112 | 112 | }
|
113 |
| - |
114 | 113 | }
|
115 | 114 |
|
116 |
| -object TimeFormat{ |
117 |
| - private const val FORMAT_PATTERN = "HH:mm" |
| 115 | +object TimeFormat { |
| 116 | + private const val DEFAULT_FORMAT_PATTERN = "HH:mm" |
118 | 117 |
|
119 | 118 | @OptIn(FormatStringsInDatetimeFormats::class)
|
120 |
| - val timeFormat = LocalDateTime.Format { |
121 |
| - byUnicodePattern(FORMAT_PATTERN) |
| 119 | + fun getTimeFormat(pattern: String = DEFAULT_FORMAT_PATTERN): DateTimeFormat<LocalDateTime> { |
| 120 | + return LocalDateTime.Format { |
| 121 | + byUnicodePattern(pattern) |
| 122 | + } |
122 | 123 | }
|
123 | 124 | }
|
0 commit comments