-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/#17 home api 연동 #20
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
The head ref may contain hidden characters: "feat/#17-home_api_\uC5F0\uB3D9"
Changes from 4 commits
9d4645d
42ea159
a84995c
b8c06ca
550230e
dd5f401
eb8a39e
aef7ab2
b2ec675
6028ad9
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 |
|---|---|---|
| @@ -1,16 +1,21 @@ | ||
| package com.alarmy.near.data.mapper | ||
|
|
||
| import com.alarmy.near.model.Friend | ||
| import com.alarmy.near.model.ContactFrequency | ||
| import com.alarmy.near.model.FriendSummary | ||
| import com.alarmy.near.network.response.FriendEntity | ||
|
|
||
| fun FriendEntity.toModel(): Friend = | ||
| Friend( | ||
| friendId = friendId, | ||
| position = position, | ||
| source = source, | ||
| fun FriendEntity.toModel(): FriendSummary = | ||
| FriendSummary( | ||
| id = friendId, | ||
| name = name, | ||
| imageUrl = imageUrl, | ||
| fileName = fileName, | ||
| checkRate = checkRate, | ||
| lastContactAt = lastContactAt, | ||
| ) | ||
| profileImageUrl = imageUrl, | ||
| lastContactedAt = lastContactAt, | ||
| isContacted = true, | ||
| contactFrequency = | ||
| when (checkRate) { | ||
| in 0..29 -> ContactFrequency.LOW | ||
| in 30..69 -> ContactFrequency.MIDDLE | ||
| in 70..100 -> ContactFrequency.HIGH | ||
| else -> ContactFrequency.LOW | ||
| }, | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package com.alarmy.near.data.mapper | ||
|
|
||
| import com.alarmy.near.model.monthly.MonthlyFriend | ||
| import com.alarmy.near.model.monthly.MonthlyFriendType | ||
| import com.alarmy.near.network.response.MonthlyFriendEntity | ||
|
|
||
| fun MonthlyFriendEntity.toModel(): MonthlyFriend = | ||
| MonthlyFriend( | ||
| friendId = friendId, | ||
| name = name, | ||
| type = MonthlyFriendType.from(type), | ||
| nextContactAt = nextContactAt, | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,11 @@ | ||
| package com.alarmy.near.data.repository | ||
|
|
||
| import com.alarmy.near.model.Friend | ||
| import com.alarmy.near.model.FriendSummary | ||
| import com.alarmy.near.model.monthly.MonthlyFriend | ||
| import kotlinx.coroutines.flow.Flow | ||
|
|
||
| interface FriendRepository { | ||
| fun fetchFriends(): Flow<List<Friend>> | ||
| fun fetchFriends(): Flow<List<FriendSummary>> | ||
|
|
||
| fun fetchMonthlyFriends(): Flow<List<MonthlyFriend>> | ||
| } |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package com.alarmy.near.model | ||
|
|
||
| import androidx.compose.runtime.Immutable | ||
|
|
||
| @Immutable | ||
| data class FriendSummary( | ||
| val id: String, | ||
| val name: String, | ||
| val profileImageUrl: String?, | ||
| val lastContactedAt: String?, | ||
| val isContacted: Boolean, | ||
| val contactFrequency: ContactFrequency, | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,13 @@ | ||
| package com.alarmy.near.model | ||
| package com.alarmy.near.model.monthly | ||
|
|
||
| import java.time.LocalDate | ||
| import java.time.format.DateTimeFormatter | ||
| import java.time.temporal.ChronoUnit | ||
|
|
||
| data class MonthlyContact( | ||
| data class MonthlyFriend( | ||
| val friendId: String, | ||
| val name: String, | ||
| val type: String, | ||
| val type: MonthlyFriendType, | ||
| val nextContactAt: String, | ||
| ) { | ||
| fun daysUntilNextContact(today: LocalDate): String { | ||
|
|
@@ -26,7 +26,7 @@ data class MonthlyContact( | |
| return ChronoUnit.DAYS.between(today, targetDate) | ||
| } | ||
|
|
||
| companion object { | ||
| companion object Companion { | ||
|
||
| private val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd") | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,23 @@ | ||||||||||||||||||||||
| package com.alarmy.near.model.monthly | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| import androidx.annotation.DrawableRes | ||||||||||||||||||||||
| import com.alarmy.near.R | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| enum class MonthlyFriendType( | ||||||||||||||||||||||
| @param:DrawableRes val imageSrc: Int, | ||||||||||||||||||||||
| ) { | ||||||||||||||||||||||
| ANNIVERSARY(R.drawable.icon_visual_24_heart), | ||||||||||||||||||||||
| BIRTHDAY(R.drawable.icon_visual_cake), | ||||||||||||||||||||||
| MESSAGE(R.drawable.icon_visual_mail), | ||||||||||||||||||||||
| ; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| companion object { | ||||||||||||||||||||||
| private const val ERROR_MESSAGE_NOT_FOUND_MONTHLY_TYPE = "일치하는 타입이 없습니다" | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| fun from(value: String): MonthlyFriendType = | ||||||||||||||||||||||
| entries.firstOrNull { it.name == value } | ||||||||||||||||||||||
| ?: throw IllegalArgumentException( | ||||||||||||||||||||||
| ERROR_MESSAGE_NOT_FOUND_MONTHLY_TYPE, | ||||||||||||||||||||||
| ) | ||||||||||||||||||||||
|
||||||||||||||||||||||
| fun from(value: String): MonthlyFriendType = | |
| entries.firstOrNull { it.name == value } | |
| ?: throw IllegalArgumentException( | |
| ERROR_MESSAGE_NOT_FOUND_MONTHLY_TYPE, | |
| ) | |
| fun from(value: String): MonthlyFriendType = try { | |
| valueOf(value.uppercase()) | |
| } catch (e: IllegalArgumentException) { | |
| throw IllegalArgumentException(ERROR_MESSAGE_NOT_FOUND_MONTHLY_TYPE, e) | |
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| package com.alarmy.near.network.response | ||
|
|
||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| data class MonthlyFriendEntity( | ||
| val friendId: String, | ||
| val name: String, | ||
| val type: String, | ||
| val nextContactAt: String, | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,13 @@ | ||
| package com.alarmy.near.network.service | ||
|
|
||
| import com.alarmy.near.network.response.FriendEntity | ||
| import com.alarmy.near.network.response.MonthlyFriendEntity | ||
| import retrofit2.http.GET | ||
|
|
||
| interface FriendService { | ||
| @GET("/friend/list") | ||
| suspend fun fetchFriends(): List<FriendEntity> | ||
|
|
||
| @GET("friend/monthly") | ||
|
||
| suspend fun fetchMonthlyFriends(): List<MonthlyFriendEntity> | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,7 +10,10 @@ import kotlinx.serialization.Serializable | |||||||||||||||||||||||||||||||||||||
| @Serializable | ||||||||||||||||||||||||||||||||||||||
| object RouteFriendProfile | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| fun NavController.navigateToFriendProfile(navOptions: NavOptions) { | ||||||||||||||||||||||||||||||||||||||
| fun NavController.navigateToFriendProfile( | ||||||||||||||||||||||||||||||||||||||
| friendId: String, | ||||||||||||||||||||||||||||||||||||||
| navOptions: NavOptions? = null, | ||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||
| navigate(RouteFriendProfile, navOptions) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
| object RouteFriendProfile | |
| fun NavController.navigateToFriendProfile(navOptions: NavOptions) { | |
| fun NavController.navigateToFriendProfile( | |
| friendId: String, | |
| navOptions: NavOptions? = null, | |
| ) { | |
| navigate(RouteFriendProfile, navOptions) | |
| } | |
| @Serializable | |
| data class RouteFriendProfile(val friendId: String) | |
| fun NavController.navigateToFriendProfile( | |
| friendId: String, | |
| navOptions: NavOptions? = null, | |
| ) { | |
| navigate(RouteFriendProfile(friendId), navOptions) | |
| } |
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.
checkRate가 0..100 범위를 벗어나는 경우를else로 처리하여ContactFrequency.LOW를 반환하고 있습니다. 만약checkRate가 항상 0에서 100 사이의 값이라고 보장된다면 이else구문은 필요 없습니다. 만약 범위를 벗어나는 값이 들어올 수 있다면, 이는 예외적인 상황일 수 있으므로IllegalArgumentException을 던져서 잘못된 데이터가 시스템에 유입되는 것을 방지하는 것이 더 안전한 방법일 수 있습니다.