-
Notifications
You must be signed in to change notification settings - Fork 0
[FEAT] 연락처 불러오기 & 주기 설정 기능 #40
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 49 commits
4aedce3
a9e0cfe
8b2bc90
16a07ab
d9ce4a6
b4a1ca6
4e70734
3636490
b52b65e
cdd10a2
8d36cbc
d91e542
33d6d21
66ea180
0394344
168239e
64bf08a
b158dc3
3c93cc0
3614e90
e25befc
e8c0e11
69697ef
848af59
eb2c982
ba28f86
f623125
66a61c4
124e03f
27a65fa
6248747
f65dccc
3454f58
fdd70dc
ca6f100
fc5ab12
ed86d0c
37f144f
e41d61d
029f446
fd435e0
6c2f47f
0407c69
c4b137f
cf30e6c
90da47f
d05063c
f82cca6
b45e8e4
fdbb7d1
a3fc9ed
ec02439
ea72f99
3ed57a5
18ae79c
5c7fff2
09c880a
727371c
611784b
8a4db8a
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,95 @@ | ||
| package com.alarmy.near.data.mapper | ||
|
|
||
| import com.alarmy.near.model.Anniversary | ||
| import com.alarmy.near.model.ContactFrequency | ||
| import com.alarmy.near.model.DayOfWeek | ||
| import com.alarmy.near.model.Friend | ||
| import com.alarmy.near.model.Relation | ||
| import com.alarmy.near.model.ReminderInterval | ||
| import com.alarmy.near.network.request.ContactFrequencyInitRequest | ||
| import com.alarmy.near.network.request.FriendInitItemRequest | ||
| import com.alarmy.near.network.response.AnniversaryInitEntity | ||
| import com.alarmy.near.network.response.ContactFrequencyInitEntity | ||
| import com.alarmy.near.network.response.FriendInitItemEntity | ||
| import com.alarmy.near.presentation.feature.friendcontactcycle.model.FriendContactUIModel | ||
| import com.alarmy.near.utils.extensions.DateExtension | ||
|
|
||
| /** | ||
| * 010 전화번호를 010-0000-0000 형태로 포맷팅하는 함수 | ||
| * - //010-0000-0000 으로 앞에 //가 붙는 경우 | ||
| * - 01012341234로 하이픈이 없는 경우 | ||
| * 최종적으로 010-0000-0000 형태로 변환합니다. | ||
| */ | ||
| private fun String.formatPhoneNumber(): String { | ||
| // 1. 불필요한 문자들 제거 | ||
| val cleaned = | ||
| this | ||
| .replace("//", "") // // 제거 | ||
| .replace("-", "") // 하이픈 제거 (하이픈이 없는 경우 위치값으로 넣어줘야 하기때문에 우선 제거) | ||
| .replace(" ", "") // 공백 제거 | ||
| .trim() | ||
|
|
||
| // 2. 000-0000-0000 형태로 포맷팅 | ||
| return "${cleaned.substring(0, 3)}-${cleaned.substring(3, 7)}-${cleaned.substring(7)}" | ||
| } | ||
|
||
|
|
||
| /** | ||
| * UI 모델을 서버 요청 모델로 변환 | ||
| */ | ||
| fun FriendContactUIModel.toFriendInitItemRequest(providerType: String): FriendInitItemRequest = | ||
| FriendInitItemRequest( | ||
| name = name, | ||
| phone = phones.first().formatPhoneNumber(), | ||
|
||
| memo = memo, | ||
| birthDay = birthDay, | ||
| source = providerType, | ||
| contactFrequency = createContactFrequencyRequest(reminderInterval!!), | ||
| imageUploadRequest = null, | ||
| anniversary = null, | ||
| relation = "FRIEND", // 기본값으로 FRIEND 설정 | ||
| ) | ||
|
|
||
| /** | ||
| * ContactFrequencyInitEntity를 모델로 변환 | ||
| */ | ||
| fun ContactFrequencyInitEntity.toModel(): ContactFrequency = | ||
| ContactFrequency( | ||
| reminderInterval = ReminderInterval.valueOf(contactWeek), | ||
| dayOfWeek = DayOfWeek.valueOf(dayOfWeek), | ||
| ) | ||
|
Comment on lines
46
to
50
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. 서버에서 예상치 못한 fun ContactFrequencyInitEntity.toModel(): ContactFrequency =
ContactFrequency(
reminderInterval = runCatching { ReminderInterval.valueOf(contactWeek) }.getOrDefault(ReminderInterval.EVERY_WEEK),
dayOfWeek = runCatching { DayOfWeek.valueOf(dayOfWeek) }.getOrDefault(DayOfWeek.MONDAY),
) |
||
|
|
||
| /** | ||
| * AnniversaryInitEntity를 모델로 변환 | ||
| */ | ||
| fun AnniversaryInitEntity.toModel(): Anniversary = | ||
| Anniversary( | ||
| id = id, | ||
| title = title, | ||
| date = date, | ||
| ) | ||
|
|
||
| /** | ||
| * 서버 응답을 모델로 변환 | ||
| */ | ||
| fun FriendInitItemEntity.toModel(): Friend = | ||
| Friend( | ||
| friendId = friendId, | ||
| name = name, | ||
| phone = phone, | ||
| memo = memo, | ||
| birthday = null, | ||
| imageUrl = preSignedImageUrl, | ||
| relation = Relation.valueOf(source), | ||
stopstone marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| contactFrequency = contactFrequency.toModel(), | ||
| anniversaryList = anniversary?.let { listOf(it.toModel()) } ?: emptyList(), | ||
| lastContactAt = nextContactAt, | ||
| ) | ||
|
|
||
| /** | ||
| * ReminderInterval을 ContactFrequencyInitRequest로 변환 | ||
| */ | ||
| private fun createContactFrequencyRequest(reminderInterval: ReminderInterval): ContactFrequencyInitRequest = | ||
| ContactFrequencyInitRequest( | ||
| contactWeek = DateExtension.toContactWeekString(reminderInterval), | ||
| dayOfWeek = DateExtension.getTodayDayOfWeekInEnglish(), | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package com.alarmy.near.network.request | ||
|
|
||
| import kotlinx.serialization.Serializable | ||
|
|
||
| /** | ||
| * 친구 초기 설정 API 요청 데이터 모델 | ||
| */ | ||
| @Serializable | ||
| data class FriendInitRequest( | ||
| val friendList: List<FriendInitItemRequest>, | ||
| ) | ||
|
|
||
| /** | ||
| * 친구 초기 설정 개별 아이템 요청 데이터 모델 | ||
| */ | ||
| @Serializable | ||
| data class FriendInitItemRequest( | ||
| val name: String, | ||
| val phone: String, | ||
| val memo: String? = null, | ||
| val birthDay: String? = null, | ||
| val source: String, | ||
| val contactFrequency: ContactFrequencyInitRequest, | ||
| val imageUploadRequest: ImageUploadRequest? = null, | ||
| val anniversary: AnniversaryInitRequest? = null, | ||
| val relation: String? = null, | ||
| ) | ||
|
|
||
| /** | ||
| * 연락처 주기 설정 요청 데이터 모델 | ||
| */ | ||
| @Serializable | ||
| data class ContactFrequencyInitRequest( | ||
| val contactWeek: String, // EVERY_WEEK, EVERY_TWO_WEEKS, EVERY_MONTH | ||
| val dayOfWeek: String, // MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY | ||
| ) | ||
|
|
||
| /** | ||
| * 이미지 업로드 요청 데이터 모델 | ||
| */ | ||
| @Serializable | ||
| data class ImageUploadRequest( | ||
| val fileName: String? = null, | ||
| val contentType: String? = null, | ||
| val fileSize: Int? = null, | ||
| val category: String? = null, | ||
| ) | ||
|
|
||
| /** | ||
| * 기념일 요청 데이터 모델 | ||
| */ | ||
| @Serializable | ||
| data class AnniversaryInitRequest( | ||
| val title: String, | ||
| val date: String? = null, | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package com.alarmy.near.network.response | ||
|
|
||
| import kotlinx.serialization.Serializable | ||
|
|
||
| /** | ||
| * 친구 초기 설정 API 응답 데이터 | ||
| */ | ||
| @Serializable | ||
| data class FriendInitEntity( | ||
| val friendList: List<FriendInitItemEntity>, | ||
| ) | ||
|
|
||
| @Serializable | ||
| data class FriendInitItemEntity( | ||
| val friendId: String, | ||
| val name: String, | ||
| val source: String, | ||
| val contactFrequency: ContactFrequencyInitEntity, | ||
| val nextContactAt: String, | ||
| val phone: String, | ||
| val preSignedImageUrl: String? = null, | ||
| val fileName: String? = null, | ||
| val memo: String? = null, | ||
| val anniversary: AnniversaryInitEntity? = null, | ||
| ) | ||
|
|
||
| @Serializable | ||
| data class ContactFrequencyInitEntity( | ||
| val contactWeek: String, | ||
| val dayOfWeek: String, | ||
| ) | ||
|
|
||
| @Serializable | ||
| data class AnniversaryInitEntity( | ||
| val id: Int, | ||
| val title: String, | ||
| val date: 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.
@stopstone // 혹시 02, 031같은 010으로 시작하지 않는 번호로 들어올 땐 어떻게 되나요?
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.
휴대전화 형식으로만 변환하게 두었습니다..!
지역번호 같은 경우 000-0000-0000, 000-000-0000와 같이 형식이 다양해서 어떻게 수정을 해야할지 좀 더 고민을 해봐야 할 것 같습니다
작업하면서 제 연락처에 있는 케이스 (//010~, 하이픈X, 하이픈O)만 우선 처리하였습니다!
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.
@stopstone // libphonenumber을 쓰면 안될까요?
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.
@slg1119 앗 감사합니다 한번 시도해보겠습니다 될 거 같아요!
android에서 사용하려면 공식 포트는 아니라서 verySlow 라고 되어있긴 한데 큰 문제는 없을 것 같습니다!
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.
@stopstone // 감사합니다 😁
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.
@slg1119 유용한 라이브러리 추천 감사합니다 :)