-
Notifications
You must be signed in to change notification settings - Fork 0
[FEATURE] 친구 프로필 api 연동 #23
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/#21-feat_\uCE5C\uAD6C_\uD504\uB85C\uD544_api_\uC5F0\uB3D9"
Changes from 29 commits
55aeb58
783ba62
83815a3
061043f
7492ab0
d2cc816
4979f35
6d55bbb
3dfd47d
e69e043
7502dae
f76e95c
19df3f3
3d793b5
7933609
7e718b6
5263fb3
2c03a14
bd6ac87
6114ae3
22e4d3a
0d70567
b92b913
e410519
8836162
78237ca
fb89c57
431ccc2
04d6d36
c25a8eb
e066210
0074695
85a40ee
e5fd302
83465cb
acdd13a
9819c4c
79b504f
0c08868
737b9c3
9f03d40
123091c
0f844a8
877388d
131cb47
0800e55
cc27edc
c3edc18
75855d3
6ffe949
c6102a7
7bcd976
2d3062d
9f3475a
e2fa26f
f8b09cf
bbc5704
39d462b
7e3f7b3
a42d27a
90ed514
9bfdb65
ea1c634
ea1bdae
5b0a186
369fd4d
9a66d1a
2891d1d
5119ed8
77ced7c
7bfb1a8
4f5e7af
ccd2f94
bf10b44
9e6673f
22997cd
1c337d2
46fd87f
3367602
6056356
d81ed8c
b802953
0127f09
817ec40
010d395
6eb87dd
77a1c65
b6dfdff
5a0a84c
078384b
7046065
f2807ab
80a0b87
6e07d8e
66c1ddd
adfd5f4
258fa45
867511c
a77678d
72acb6a
c290de7
eb93e25
307da48
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,21 +1,64 @@ | ||
| package com.alarmy.near.data.mapper | ||
|
|
||
| import com.alarmy.near.model.Anniversary | ||
| import com.alarmy.near.model.ContactFrequency | ||
| import com.alarmy.near.model.FriendSummary | ||
| import com.alarmy.near.model.Friend | ||
| import com.alarmy.near.model.Relation | ||
| import com.alarmy.near.model.ReminderInterval | ||
| import com.alarmy.near.network.request.AnniversaryRequest | ||
| import com.alarmy.near.network.request.ContactFrequencyRequest | ||
| import com.alarmy.near.network.request.FriendRequest | ||
| import com.alarmy.near.network.response.AnniversaryEntity | ||
| import com.alarmy.near.network.response.ContactFrequencyEntity | ||
| import com.alarmy.near.network.response.FriendEntity | ||
|
|
||
| fun FriendEntity.toModel(): FriendSummary = | ||
| FriendSummary( | ||
| id = friendId, | ||
| fun FriendEntity.toModel(): Friend = | ||
| Friend( | ||
| friendId = friendId, | ||
| imageUrl = imageUrl, | ||
| relation = Relation.valueOf(relation), | ||
| name = name, | ||
| 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 | ||
| }, | ||
| ) | ||
| contactFrequency = contactFrequency.toModel(), | ||
| birthday = birthday, | ||
| anniversaryList = anniversaryList.map { it.toModel() }, | ||
| memo = memo, | ||
| phone = phone, | ||
| lastContactAt = lastContactAt, | ||
| ) | ||
|
|
||
| fun ContactFrequencyEntity.toModel(): ContactFrequency = | ||
| ContactFrequency( | ||
| reminderInterval = ReminderInterval.valueOf(contactWeek), | ||
| dayOfWeek = dayOfWeek, | ||
| ) | ||
|
|
||
| fun AnniversaryEntity.toModel(): Anniversary = | ||
| Anniversary( | ||
| id = id, | ||
| title = title, | ||
| date = date, | ||
| ) | ||
|
|
||
| fun Friend.toRequest(): FriendRequest = | ||
| FriendRequest( | ||
| name = name, | ||
| relation = relation.toString(), | ||
| contactFrequency = contactFrequency.toRequest(), | ||
| birthday = birthday, | ||
| anniversaryList = anniversaryList.map { it.toRequest() }, | ||
| memo = memo, | ||
| phone = phone, | ||
| ) | ||
|
|
||
| fun ContactFrequency.toRequest(): ContactFrequencyRequest = | ||
| ContactFrequencyRequest( | ||
| contactWeek = reminderInterval.toString(), | ||
| dayOfWeek = dayOfWeek, | ||
| ) | ||
|
|
||
| fun Anniversary.toRequest(): AnniversaryRequest = | ||
| AnniversaryRequest( | ||
| id = id, | ||
| title = title, | ||
| date = date, | ||
| ) | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,20 @@ | ||||||||||||||||||||||||||||||||||||||
| package com.alarmy.near.data.mapper | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| import com.alarmy.near.model.FriendRecord | ||||||||||||||||||||||||||||||||||||||
| import com.alarmy.near.network.response.FriendRecordEntity | ||||||||||||||||||||||||||||||||||||||
| import java.time.LocalDateTime | ||||||||||||||||||||||||||||||||||||||
| import java.time.format.DateTimeFormatter | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| fun FriendRecordEntity.toModel(): FriendRecord = | ||||||||||||||||||||||||||||||||||||||
| FriendRecord( | ||||||||||||||||||||||||||||||||||||||
| isChecked = isChecked, | ||||||||||||||||||||||||||||||||||||||
| createdAt = createdAt.toShortDate(), | ||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| private fun String.toShortDate(): String { | ||||||||||||||||||||||||||||||||||||||
| val inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss") | ||||||||||||||||||||||||||||||||||||||
| val outputFormatter = DateTimeFormatter.ofPattern("yy.MM.dd") | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| val dateTime = LocalDateTime.parse(this, inputFormatter) | ||||||||||||||||||||||||||||||||||||||
| return dateTime.format(outputFormatter) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+14
to
+20
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.
또한,
Suggested change
|
||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.alarmy.near.data.mapper | ||
|
|
||
| import com.alarmy.near.model.friendsummary.ContactFrequencyLevel | ||
| import com.alarmy.near.model.friendsummary.FriendSummary | ||
| import com.alarmy.near.network.response.FriendSummaryEntity | ||
|
|
||
| fun FriendSummaryEntity.toModel(): FriendSummary = | ||
| FriendSummary( | ||
| id = friendId, | ||
| name = name, | ||
| profileImageUrl = imageUrl, | ||
| lastContactedAt = lastContactAt, | ||
| isContacted = true, | ||
| contactFrequencyLevel = | ||
| when (checkRate) { | ||
| in 0..29 -> ContactFrequencyLevel.LOW | ||
| in 30..69 -> ContactFrequencyLevel.MIDDLE | ||
| in 70..100 -> ContactFrequencyLevel.HIGH | ||
| else -> ContactFrequencyLevel.LOW | ||
| }, | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,26 @@ | ||
| package com.alarmy.near.data.repository | ||
|
|
||
| import com.alarmy.near.model.FriendSummary | ||
| import com.alarmy.near.model.Friend | ||
| import com.alarmy.near.model.FriendRecord | ||
| import com.alarmy.near.model.friendsummary.FriendSummary | ||
| import com.alarmy.near.model.monthly.MonthlyFriend | ||
| import kotlinx.coroutines.flow.Flow | ||
|
|
||
| interface FriendRepository { | ||
| fun fetchFriends(): Flow<List<FriendSummary>> | ||
|
|
||
| fun fetchMonthlyFriends(): Flow<List<MonthlyFriend>> | ||
|
|
||
| fun fetchFriendById(friendId: String): Flow<Friend> | ||
|
|
||
| fun updateFriend( | ||
| friendId: String, | ||
| friend: Friend, | ||
| ): Flow<Friend> | ||
|
|
||
| fun deleteFriend(friendId: String): Flow<Unit> | ||
|
|
||
| fun fetchFriendRecord(friendId: String): Flow<List<FriendRecord>> | ||
|
|
||
| fun recordContact(friendId: String): Flow<String> | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package com.alarmy.near.model | ||
|
|
||
| import android.os.Parcelable | ||
| import kotlinx.parcelize.Parcelize | ||
| import kotlinx.serialization.Serializable | ||
| import java.time.LocalDate | ||
| import java.time.format.DateTimeFormatter | ||
| import java.util.Locale | ||
|
|
||
| @Parcelize | ||
| @Serializable | ||
| data class Friend( | ||
| val friendId: String, | ||
| val imageUrl: String?, | ||
| val relation: Relation, | ||
| val name: String, | ||
| val contactFrequency: ContactFrequency, | ||
| val birthday: String?, | ||
| val anniversaryList: List<Anniversary>, | ||
| val memo: String?, | ||
| val phone: String?, | ||
| val lastContactAt: String?, // "2025-07-16" | ||
| ) : Parcelable { | ||
| val isContactedToday: Boolean | ||
| get() = lastContactAt?.isToday() ?: false | ||
|
|
||
| private fun String.isToday(): Boolean { | ||
|
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. 확장함수로 구현하니 사용하기 훨씬 간결하고 편리해진 것 같아요!!
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. 다른 곳에 사용 되는 것이 안보여서, 우선 내부적으로 처리했습니다! 사실 개인적으로 확장함수를 외부에서 쉽게 사용하는 것을 선호하진 않아요!
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. 오 그렇군요! 저는 외부에서 쉽게 활용되는 것은 선호하였습니다..! 주형님 의견을 들어보니 막 남발하는 것도 좋지 않아 보이네요! 의견 감사드려요! |
||
| val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd", Locale.KOREA) | ||
| val targetDate = LocalDate.parse(this, formatter) | ||
| val today = LocalDate.now() | ||
| return targetDate == today | ||
| } | ||
|
Comment on lines
+29
to
+34
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.
또한, private fun String.isToday(): Boolean {
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd", Locale.KOREA)
return try {
val targetDate = LocalDate.parse(this, formatter)
val today = LocalDate.now()
targetDate == today
} catch (e: java.time.format.DateTimeParseException) {
false
}
} |
||
| } | ||
|
|
||
| @Serializable | ||
| @Parcelize | ||
| data class ContactFrequency( | ||
| val reminderInterval: ReminderInterval, | ||
| val dayOfWeek: String, | ||
| ) : Parcelable | ||
|
|
||
| @Serializable | ||
| @Parcelize | ||
| data class Anniversary( | ||
| val id: Int? = null, | ||
| val title: String, | ||
| val date: String? = null, | ||
| ) : Parcelable | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package com.alarmy.near.model | ||
|
|
||
| data class FriendRecord( | ||
| val isChecked: Boolean, | ||
| val createdAt: String, // ex) 25.11.12 | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,12 @@ | ||
| package com.alarmy.near.model | ||
|
|
||
| enum class Relation { | ||
| FRIEND, | ||
| FAMILY, | ||
| ACQUAINTANCE, | ||
| import androidx.annotation.StringRes | ||
| import com.alarmy.near.R | ||
|
|
||
| enum class Relation( | ||
| @param:StringRes val resId: Int, | ||
| ) { | ||
| FRIEND(R.string.relation_friend), | ||
| FAMILY(R.string.relation_family), | ||
| ACQUAINTANCE(R.string.relation_acquaintance), | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.alarmy.near.model.friendsummary | ||
|
|
||
| enum class ContactFrequencyLevel { | ||
| LOW, | ||
| MIDDLE, | ||
| HIGH, | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ package com.alarmy.near.model.monthly | |
| import androidx.annotation.DrawableRes | ||
| import com.alarmy.near.R | ||
|
|
||
| // TODO Drawable Res UI-Layer 이동 | ||
|
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. |
||
| enum class MonthlyFriendType( | ||
| @param:DrawableRes val imageSrc: Int, | ||
| ) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package com.alarmy.near.network.request | ||
|
|
||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| data class FriendRequest( | ||
| val name: String, | ||
| val relation: String, | ||
| val contactFrequency: ContactFrequencyRequest, | ||
| val birthday: String?, | ||
| val anniversaryList: List<AnniversaryRequest>, | ||
| val memo: String?, | ||
| val phone: String?, | ||
| ) | ||
|
|
||
| @Serializable | ||
| data class ContactFrequencyRequest( | ||
| val contactWeek: String, | ||
| val dayOfWeek: String, | ||
| ) | ||
|
|
||
| @Serializable | ||
| data class AnniversaryRequest( | ||
| val id: Int? = null, | ||
| val title: String, | ||
| val date: String? = null, | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package com.alarmy.near.network.response | ||
|
|
||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| data class CommonMessageEntity( | ||
| val message: String, | ||
| ) |
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.
Relation.valueOf(relation)이나ReminderInterval.valueOf(contactWeek)는 서버에서 예상치 못한 값을 보내줄 경우IllegalArgumentException을 발생시켜 앱이 비정상 종료될 수 있습니다. 보다 안전한 처리를 위해try-catch블록을 사용하거나,entries.find와 기본값을 사용하는 것을 권장합니다.