Skip to content

Commit

Permalink
[AN] hotfix: 주소 등록 오류 수정 (#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinuemong authored Aug 12, 2024
1 parent 71ad2bb commit dd6ec4e
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import com.happy.friendogly.domain.model.UserAddress

fun UserAddressDto.toDomain(): UserAddress {
return UserAddress(
thoroughfare = thoroughfare,
subLocality = subLocality,
thoroughfare = thoroughfare ?: "",
subLocality = subLocality ?: "",
adminArea = adminArea,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package com.happy.friendogly.data.model

data class ClubAddressDto(
val province: String,
val city: String,
val village: String,
val city: String?,
val village: String?,
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.happy.friendogly.data.model

data class UserAddressDto(
val thoroughfare: String,
val subLocality: String,
val adminArea: String,
val thoroughfare: String?,
val subLocality: String?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,12 @@ class AddressRepositoryImpl(
private val addressDataSource: AddressDataSource,
) : AddressRepository {
override suspend fun getAddress(): Result<UserAddress> =
addressDataSource.getAddress().mapCatching {
val address = it.toDomain()
if (isInValidAddress(address)) throw Exception()
address
addressDataSource.getAddress().mapCatching { address ->
address.toDomain()
}

override suspend fun saveAddress(userAddress: UserAddress): Result<Unit> =
addressDataSource.saveAddress(userAddressDto = userAddress.toData()).mapCatching {
if (isInValidAddress(userAddress)) throw Exception()
}
addressDataSource.saveAddress(userAddressDto = userAddress.toData())

override suspend fun deleteAddress(): Result<Unit> = addressDataSource.deleteAddress()

private fun isInValidAddress(userAddress: UserAddress) =
userAddress.thoroughfare.isEmpty() || userAddress.adminArea.isEmpty() || userAddress.subLocality.isEmpty()
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package com.happy.friendogly.domain.model

data class ClubAddress(
val province: String,
val city: String,
val village: String,
val city: String?,
val village: String?,
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.happy.friendogly.domain.model

data class UserAddress(
val thoroughfare: String,
val subLocality: String,
val adminArea: String,
val subLocality: String?,
val thoroughfare: String?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class AddressModule(val context: Context) {

suspend fun saveAddress(userAddressDto: UserAddressDto) {
context.dataStore.edit { preferences ->
preferences[keyThoroughfare] = userAddressDto.thoroughfare
preferences[keyLocality] = userAddressDto.subLocality
preferences[keyThoroughfare] = userAddressDto.thoroughfare ?: ""
preferences[keyLocality] = userAddressDto.subLocality ?: ""
preferences[keyAdmin] = userAddressDto.adminArea
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import com.happy.friendogly.domain.model.ClubAddress
import com.happy.friendogly.domain.model.UserAddress

fun ClubAddress.toPresentation(): String {
val city = if (this.city.isNullOrEmpty()) "" else this.city
val village = if (this.village.isNullOrEmpty()) "" else this.village
return "$province $city $village"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fun TextView.bindMyLocation(userAddress: UserAddress?) {
context.getString(
R.string.my_location_full_address,
userAddress.adminArea,
userAddress.subLocality,
userAddress.thoroughfare,
userAddress.subLocality ?: "",
userAddress.thoroughfare ?: "",
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class SettingMyLocationViewModel(
val addressLine = address.getAddressLine(0)

val adminArea = loadAdmin(address, addressLine)
val locality = loadLocality(addressLine)
val thoroughfare = loadThoroughfare(addressLine)
val locality = loadLocality(address, addressLine)
val thoroughfare = loadThoroughfare(address, addressLine)

makeUserAddress(adminArea, locality, thoroughfare)
}
Expand All @@ -47,35 +47,48 @@ class SettingMyLocationViewModel(
address: Address,
addressLine: String,
): String {
val admin = address.adminArea ?: address.adminArea ?: findAdminAddress(addressLine)
val admin =
address.adminArea
?: address.adminArea
?: findAdminAddress(addressLine)
addressList.add(admin)
return admin
}

private fun loadLocality(addressLine: String): String {
private fun loadLocality(
address: Address,
addressLine: String,
): String? {
val locality =
findAddressElement(
addressLine,
LOCALITY_SPLIT,
)
address.locality
?: address.subLocality
?: findAddressElement(
addressLine,
LOCALITY_SPLIT,
)
addressList.add(locality)
return locality
}

private fun loadThoroughfare(addressLine: String): String {
private fun loadThoroughfare(
address: Address,
addressLine: String,
): String? {
val thoroughfare =
findAddressElement(
addressLine,
THOROUGH_FARE_SPLIT,
)
address.thoroughfare
?: address.subThoroughfare
?: findAddressElement(
addressLine,
THOROUGH_FARE_SPLIT,
)
addressList.add(thoroughfare)
return thoroughfare
}

private fun makeUserAddress(
adminArea: String,
locality: String,
thoroughfare: String,
locality: String?,
thoroughfare: String?,
): UserAddress {
return UserAddress(
adminArea = adminArea,
Expand Down Expand Up @@ -129,12 +142,12 @@ class SettingMyLocationViewModel(
private fun findAddressElement(
addressLine: String,
delimiterChar: String,
): String {
): String? {
val addressElements = addressLine.split(ADDRESS_LINE_SPLIT)

val delimiterChars = delimiterChar.toSet()

return addressElements.first { element ->
return addressElements.firstOrNull { element ->
isValidAddressElements(delimiterChars, element)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ interface ClubService {
suspend fun getSearchingClubs(
@Query("filterCondition") filterCondition: ClubFilterConditionRequest,
@Query("province") province: String,
@Query("city") city: String,
@Query("village") village: String,
@Query("city") city: String?,
@Query("village") village: String?,
@Query("genderParams") genderParams: List<String>,
@Query("sizeParams") sizeParams: List<String>,
): BaseResponse<List<ClubResponse>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ data class PostClubRequest(
val title: String,
val content: String,
val province: String,
val city: String,
val village: String,
val city: String?,
val village: String?,
val allowedGenders: List<String>,
val allowedSizes: List<String>,
val memberCapacity: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
android:orientation="horizontal">

<TextView
android:text="@{vm.myAddress.thoroughfare}"
android:text="@{vm.myAddress.adminArea}"
style="@style/Theme.AppCompat.TextView.SemiBold.Orange.Size16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
2 changes: 1 addition & 1 deletion android/app/src/main/res/layout/fragment_club_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
app:layout_constraintTop_toTopOf="@id/view_club_list_top_bar">

<TextView
android:text="@{vm.myAddress.thoroughfare}"
android:text="@{vm.myAddress.adminArea}"
style="@style/Theme.AppCompat.TextView.Bold.Black.Size18"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down

0 comments on commit dd6ec4e

Please sign in to comment.