-
Notifications
You must be signed in to change notification settings - Fork 0
[FEAT/#45] 캘린더 API 연결 #63
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
Changes from all commits
44b9b9d
545f04b
cf2fe10
3678005
81e24fa
d177a31
363dde1
fce0c02
20b678f
be7f19a
dae6b8c
cf391bd
b22ffad
ecbab52
f3736ec
b849b04
c3a1eaa
e36dec5
49b54e9
c8a3332
04b095c
7226ed5
0133395
f3d1341
c074b72
eed2dc1
b184832
87fb189
7d7add4
7b7ec49
f81ac76
6905929
9e2114d
bb09f2a
c998029
2a0358a
0a0b921
7339e27
72fc82b
30c8d3a
99bf2c8
0983606
33409be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package com.cherrish.android.core.util | ||
|
|
||
| import java.time.DayOfWeek | ||
| import java.time.LocalDateTime | ||
|
|
||
| fun DayOfWeek.daysUntil(other: DayOfWeek) = (other.value - value + 7) % 7 | ||
|
|
||
| fun formatProcedureDay(scheduledAt: String): String { | ||
| val dateTime = LocalDateTime.parse(scheduledAt) | ||
| val month = dateTime.month.value | ||
| val day = dateTime.dayOfMonth | ||
| val dayOfWeek = dateTime.dayOfWeek.toKoreanName() | ||
| return "${month}월 ${day}일 $dayOfWeek" | ||
| } | ||
|
|
||
| fun DayOfWeek.toKoreanName(): String = when (this) { | ||
| DayOfWeek.MONDAY -> "월요일" | ||
| DayOfWeek.TUESDAY -> "화요일" | ||
| DayOfWeek.WEDNESDAY -> "수요일" | ||
| DayOfWeek.THURSDAY -> "목요일" | ||
| DayOfWeek.FRIDAY -> "금요일" | ||
| DayOfWeek.SATURDAY -> "토요일" | ||
| DayOfWeek.SUNDAY -> "일요일" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package com.cherrish.android.data.model | ||
|
|
||
| import com.cherrish.android.data.remote.dto.response.CalendarDailyResponseDto | ||
| import com.cherrish.android.data.remote.dto.response.EventDto | ||
|
|
||
| data class CalendarDailyResponseModel( | ||
| val eventCount: Int, | ||
| val events: List<EventModel> | ||
| ) | ||
|
|
||
| data class EventModel( | ||
| val type: String, | ||
| val userProcedureId: Long, | ||
| val procedureId: Long, | ||
| val name: String, | ||
| val scheduledAt: String, | ||
| val downtimeDays: Int | ||
| ) | ||
|
|
||
| fun CalendarDailyResponseDto.toModel() = CalendarDailyResponseModel( | ||
| eventCount = this.eventCount, | ||
| events = this.events.map { it.toModel() } | ||
| ) | ||
|
|
||
| fun EventDto.toModel() = EventModel( | ||
| type = this.type, | ||
| userProcedureId = this.userProcedureId, | ||
| procedureId = this.procedureId, | ||
| name = this.name, | ||
| scheduledAt = this.scheduledAt, | ||
| downtimeDays = this.downtimeDays | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.cherrish.android.data.model | ||
|
|
||
| import com.cherrish.android.data.remote.dto.response.CalendarDownTimeResponseDto | ||
|
|
||
| data class CalendarDownTimeResponseModel( | ||
| val userProcedureId: Long, | ||
| val scheduledAt: String, | ||
| val downtimeDays: Int, | ||
| val sensitiveDays: List<String>, | ||
| val cautionDays: List<String>, | ||
| val recoveryDays: List<String> | ||
| ) | ||
|
|
||
| fun CalendarDownTimeResponseDto.toModel() = CalendarDownTimeResponseModel( | ||
| userProcedureId = this.userProcedureId, | ||
| scheduledAt = this.scheduledAt, | ||
| downtimeDays = this.downtimeDays, | ||
| sensitiveDays = this.sensitiveDays, | ||
| cautionDays = this.cautionDays, | ||
| recoveryDays = this.recoveryDays | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package com.cherrish.android.data.model | ||
|
|
||
| import com.cherrish.android.data.remote.dto.request.CalendarMonthlyRequestDto | ||
|
|
||
| data class CalendarMonthlyRequestModel( | ||
| val year: Int, | ||
| val month: Int | ||
| ) | ||
|
|
||
| fun CalendarMonthlyRequestModel.toDto() = CalendarMonthlyRequestDto( | ||
| year = this.year, | ||
| month = this.month | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package com.cherrish.android.data.model | ||
|
|
||
| import com.cherrish.android.data.remote.dto.response.CalendarMonthlyResponseDto | ||
|
|
||
| data class CalendarMonthlyResponseModel( | ||
| val dailyProcedureCounts: Map<Int, Long> | ||
| ) | ||
|
|
||
| fun CalendarMonthlyResponseDto.toModel() = CalendarMonthlyResponseModel( | ||
| dailyProcedureCounts = this.dailyProcedureCounts | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.cherrish.android.data.remote.datasource | ||
|
|
||
| import com.cherrish.android.core.network.BaseResponse | ||
| import com.cherrish.android.data.remote.dto.response.CalendarDailyResponseDto | ||
| import com.cherrish.android.data.remote.dto.response.CalendarDownTimeResponseDto | ||
| import com.cherrish.android.data.remote.dto.response.CalendarMonthlyResponseDto | ||
|
|
||
| interface CalendarDataSource { | ||
| suspend fun getCalendarMonthly(year: Int, month: Int): BaseResponse<CalendarMonthlyResponseDto> | ||
| suspend fun getCalendarDaily(date: String): BaseResponse<CalendarDailyResponseDto> | ||
| suspend fun getCalendarEventDowntime(id: Long): BaseResponse<CalendarDownTimeResponseDto> | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package com.cherrish.android.data.remote.datasourceimpl | ||
|
|
||
| import com.cherrish.android.core.network.BaseResponse | ||
| import com.cherrish.android.data.remote.datasource.CalendarDataSource | ||
| import com.cherrish.android.data.remote.dto.response.CalendarDailyResponseDto | ||
| import com.cherrish.android.data.remote.dto.response.CalendarDownTimeResponseDto | ||
| import com.cherrish.android.data.remote.dto.response.CalendarMonthlyResponseDto | ||
| import com.cherrish.android.data.remote.service.CalendarService | ||
| import javax.inject.Inject | ||
|
|
||
| class CalendarDataSourceImpl @Inject constructor( | ||
| private val calendarService: CalendarService | ||
| ) : CalendarDataSource { | ||
| override suspend fun getCalendarMonthly( | ||
| year: Int, | ||
| month: Int | ||
| ): BaseResponse<CalendarMonthlyResponseDto> = | ||
| calendarService.getCalendarMonthly(year = year, month = month) | ||
|
|
||
| override suspend fun getCalendarDaily( | ||
| date: String | ||
| ): BaseResponse<CalendarDailyResponseDto> = | ||
| calendarService.getCalendarDaily(date = date) | ||
|
|
||
| override suspend fun getCalendarEventDowntime( | ||
| id: Long | ||
| ): BaseResponse<CalendarDownTimeResponseDto> = | ||
| calendarService.getCalendarEventDowntime(id = id) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package com.cherrish.android.data.remote.dto.request | ||
|
|
||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| data class CalendarDailyRequestDto( | ||
| @SerialName("date") | ||
| val date: String | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.cherrish.android.data.remote.dto.request | ||
|
|
||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| data class CalendarMonthlyRequestDto( | ||
| @SerialName("year") | ||
| val year: Int, | ||
| @SerialName("month") | ||
| val month: Int | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package com.cherrish.android.data.remote.dto.response | ||
|
|
||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| data class CalendarDailyResponseDto( | ||
| @SerialName("eventCount") | ||
| val eventCount: Int, | ||
| @SerialName("events") | ||
| val events: List<EventDto> | ||
| ) | ||
|
|
||
| @Serializable | ||
| data class EventDto( | ||
| @SerialName("type") | ||
| val type: String, | ||
| @SerialName("userProcedureId") | ||
| val userProcedureId: Long, | ||
| @SerialName("procedureId") | ||
| val procedureId: Long, | ||
| @SerialName("name") | ||
| val name: String, | ||
| @SerialName("scheduledAt") | ||
| val scheduledAt: String, | ||
| @SerialName("downtimeDays") | ||
| val downtimeDays: Int | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package com.cherrish.android.data.remote.dto.response | ||
|
|
||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| data class CalendarDownTimeResponseDto( | ||
| @SerialName("userProcedureId") | ||
| val userProcedureId: Long, | ||
| @SerialName("scheduledAt") | ||
| val scheduledAt: String, | ||
| @SerialName("downtimeDays") | ||
| val downtimeDays: Int, | ||
| @SerialName("sensitiveDays") | ||
| val sensitiveDays: List<String>, | ||
| @SerialName("cautionDays") | ||
| val cautionDays: List<String>, | ||
| @SerialName("recoveryDays") | ||
| val recoveryDays: List<String> | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package com.cherrish.android.data.remote.dto.response | ||
|
|
||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| data class CalendarMonthlyResponseDto( | ||
| @SerialName("dailyProcedureCounts") | ||
| val dailyProcedureCounts: Map<Int, Long> | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package com.cherrish.android.data.remote.service | ||
|
|
||
| import com.cherrish.android.core.network.BaseResponse | ||
| import com.cherrish.android.data.remote.dto.response.CalendarDailyResponseDto | ||
| import com.cherrish.android.data.remote.dto.response.CalendarDownTimeResponseDto | ||
| import com.cherrish.android.data.remote.dto.response.CalendarMonthlyResponseDto | ||
| import retrofit2.http.GET | ||
| import retrofit2.http.Path | ||
| import retrofit2.http.Query | ||
|
|
||
| interface CalendarService { | ||
| @GET("api/calendar/monthly") | ||
| suspend fun getCalendarMonthly( | ||
| @Query("year") year: Int, | ||
| @Query("month") month: Int | ||
| ): BaseResponse<CalendarMonthlyResponseDto> | ||
|
|
||
| @GET("api/calendar/daily") | ||
| suspend fun getCalendarDaily( | ||
| @Query("date") date: String | ||
| ): BaseResponse<CalendarDailyResponseDto> | ||
|
|
||
| @GET("api/calendar/events/{id}/downtime") | ||
| suspend fun getCalendarEventDowntime( | ||
| @Path("id") id: Long | ||
| ): BaseResponse<CalendarDownTimeResponseDto> | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package com.cherrish.android.data.repository | ||
|
|
||
| import com.cherrish.android.data.model.CalendarDailyResponseModel | ||
| import com.cherrish.android.data.model.CalendarDownTimeResponseModel | ||
| import com.cherrish.android.data.model.CalendarMonthlyResponseModel | ||
|
|
||
| interface CalendarRepository { | ||
| suspend fun getCalendarMonthly( | ||
| year: Int, | ||
| month: Int | ||
| ): Result<CalendarMonthlyResponseModel> | ||
|
|
||
| suspend fun getCalendarDaily( | ||
| date: String | ||
| ): Result<CalendarDailyResponseModel> | ||
|
|
||
| suspend fun getCalendarEventDowntime( | ||
| id: Long | ||
| ): Result<CalendarDownTimeResponseModel> | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| package com.cherrish.android.data.repositoryimpl | ||
|
|
||
| import com.cherrish.android.core.util.suspendRunCatching | ||
| import com.cherrish.android.data.model.CalendarDailyResponseModel | ||
| import com.cherrish.android.data.model.CalendarDownTimeResponseModel | ||
| import com.cherrish.android.data.model.CalendarMonthlyResponseModel | ||
| import com.cherrish.android.data.model.toModel | ||
| import com.cherrish.android.data.remote.datasource.CalendarDataSource | ||
| import com.cherrish.android.data.repository.CalendarRepository | ||
| import javax.inject.Inject | ||
|
|
||
| class CalendarRepositoryImpl @Inject constructor( | ||
| private val calendarDataSource: CalendarDataSource | ||
| ) : CalendarRepository { | ||
| override suspend fun getCalendarMonthly( | ||
| year: Int, | ||
| month: Int | ||
| ): Result<CalendarMonthlyResponseModel> = | ||
| suspendRunCatching { | ||
| calendarDataSource.getCalendarMonthly(year = year, month = month).data!!.toModel() | ||
|
Contributor
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. P3: (단순 궁금) data!! 사용은 NullPointerException 위험이 있다는데 괜찮은가용~/!?!?
Contributor
Author
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. data!! 사용 시 NPE 가능성은 잇지용 ~~ 다만 앱 크래시는 안 나고, 에러 흐름은 통제할 수 잇어 이런식으로 사용했엉요 ! 해당 API는 스펙상 성공 응답일 경우 data가 항상 내려오도록 보장되어 있고 null인 경우는 서버 계약 위반 또는 비정상 응답으로 판단하고 있답니닿ㅎㅎㅎ 그래서 suspendRunCatching을 통해 실패로 감싸 상위 레이어에서 공통 에러 처리하도록 의도햇어요 !! 그냥 runCatching이 아니라 suspendRunCatching util 함수를 사용하는 이유랍니도 ! |
||
| } | ||
|
|
||
| override suspend fun getCalendarDaily(date: String): Result<CalendarDailyResponseModel> = | ||
| suspendRunCatching { | ||
| calendarDataSource.getCalendarDaily(date = date).data!!.toModel() | ||
| } | ||
|
|
||
| override suspend fun getCalendarEventDowntime(id: Long): Result<CalendarDownTimeResponseModel> = | ||
| suspendRunCatching { | ||
| calendarDataSource.getCalendarEventDowntime(id = id).data!!.toModel() | ||
| } | ||
|
nhyeonii marked this conversation as resolved.
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.