Skip to content
Merged
Show file tree
Hide file tree
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
27 changes: 16 additions & 11 deletions Near/app/src/main/java/com/alarmy/near/data/mapper/FriendMapper.kt
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

Choose a reason for hiding this comment

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

medium

checkRate가 0..100 범위를 벗어나는 경우를 else로 처리하여 ContactFrequency.LOW를 반환하고 있습니다. 만약 checkRate가 항상 0에서 100 사이의 값이라고 보장된다면 이 else 구문은 필요 없습니다. 만약 범위를 벗어나는 값이 들어올 수 있다면, 이는 예외적인 상황일 수 있으므로 IllegalArgumentException을 던져서 잘못된 데이터가 시스템에 유입되는 것을 방지하는 것이 더 안전한 방법일 수 있습니다.

Suggested change
else -> ContactFrequency.LOW
else -> throw IllegalArgumentException("checkRate must be between 0 and 100, but was $checkRate")

},
)
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,7 +1,8 @@
package com.alarmy.near.data.repository

import com.alarmy.near.data.mapper.toModel
import com.alarmy.near.model.Friend
import com.alarmy.near.model.FriendSummary
import com.alarmy.near.model.monthly.MonthlyFriend
import com.alarmy.near.network.service.FriendService
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
Expand All @@ -12,12 +13,21 @@ class DefaultFriendRepository
constructor(
private val friendService: FriendService,
) : FriendRepository {
override fun fetchFriends(): Flow<List<Friend>> =
override fun fetchFriends(): Flow<List<FriendSummary>> =
flow {
emit(
friendService.fetchFriends().map {
it.toModel()
},
)
}

override fun fetchMonthlyFriends(): Flow<List<MonthlyFriend>> =
flow {
emit(
friendService.fetchMonthlyFriends().map {
it.toModel()
},
)
}
}
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>>
}
22 changes: 0 additions & 22 deletions Near/app/src/main/java/com/alarmy/near/model/ContactSummary.kt

This file was deleted.

12 changes: 0 additions & 12 deletions Near/app/src/main/java/com/alarmy/near/model/Friend.kt

This file was deleted.

13 changes: 13 additions & 0 deletions Near/app/src/main/java/com/alarmy/near/model/FriendSummary.kt
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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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 =
runCatching { valueOf(value.uppercase()) }.getOrNull() ?: throw IllegalStateException(
ERROR_MESSAGE_NOT_FOUND_MONTHLY_TYPE,
)
}
}
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
Expand Up @@ -8,10 +8,15 @@ import com.alarmy.near.presentation.feature.friendprofile.FriendProfileRoute
import kotlinx.serialization.Serializable

@Serializable
object RouteFriendProfile
data class RouteFriendProfile(
val friendId: String,
)

fun NavController.navigateToFriendProfile(navOptions: NavOptions) {
navigate(RouteFriendProfile, navOptions)
fun NavController.navigateToFriendProfile(
friendId: String,
navOptions: NavOptions? = null,
) {
navigate(RouteFriendProfile(friendId), navOptions)
}

fun NavGraphBuilder.friendProfileNavGraph(
Expand Down
Loading