Skip to content

Commit

Permalink
[MOD/#117] 코드 리뷰 수정 사항 반영
Browse files Browse the repository at this point in the history
angryPodo committed Jan 22, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 4348c27 commit b4b54da
Showing 4 changed files with 50 additions and 62 deletions.
10 changes: 0 additions & 10 deletions app/src/main/java/com/spoony/spoony/data/mapper/PlaceMapper.kt
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@ package com.spoony.spoony.data.mapper

import com.spoony.spoony.data.dto.response.PlaceResponseDto
import com.spoony.spoony.domain.entity.PlaceEntity
import com.spoony.spoony.presentation.register.model.Place

fun PlaceResponseDto.toDomain(): PlaceEntity =
PlaceEntity(
@@ -12,12 +11,3 @@ fun PlaceResponseDto.toDomain(): PlaceEntity =
latitude = latitude,
longitude = longitude
)

fun PlaceEntity.toPresentation(): Place =
Place(
placeName = placeName,
placeAddress = placeAddress,
placeRoadAddress = placeRoadAddress,
latitude = latitude,
longitude = longitude
)
Original file line number Diff line number Diff line change
@@ -3,65 +3,64 @@ package com.spoony.spoony.data.repositoryimpl
import android.net.Uri
import com.spoony.spoony.data.datasource.PlaceDataSource
import com.spoony.spoony.data.mapper.toDomain
import com.spoony.spoony.data.mapper.toPresentation
import com.spoony.spoony.domain.entity.CategoryEntity
import com.spoony.spoony.domain.entity.PlaceEntity
import com.spoony.spoony.domain.repository.RegisterRepository
import com.spoony.spoony.presentation.register.model.Category
import com.spoony.spoony.presentation.register.model.Place
import javax.inject.Inject

class RegisterRepositoryImpl @Inject constructor(
private val placeDataSource: PlaceDataSource
) : RegisterRepository {
override suspend fun getCategories(): Result<List<Category>> = Result.success(
override suspend fun getCategories(): Result<List<CategoryEntity>> = Result.success(
listOf(
Category(
CategoryEntity(
categoryId = 2,
categoryName = "한식",
iconUrlSelected = "https://spoony-storage.s3.ap-northeast-2.amazonaws.com/category/icons/korean_white.png",
iconUrlNotSelected = "https://spoony-storage.s3.ap-northeast-2.amazonaws.com/category/icons/korean_black.png"
iconUrl = "https://spoony-storage.s3.ap-northeast-2.amazonaws.com/category/icons/korean_white.png",
unSelectedIconUrl = "https://spoony-storage.s3.ap-northeast-2.amazonaws.com/category/icons/korean_black.png"
),
Category(
CategoryEntity(
categoryId = 3,
categoryName = "일식",
iconUrlSelected = "https://spoony-storage.s3.ap-northeast-2.amazonaws.com/category/icons/korean_white.png",
iconUrlNotSelected = "https://spoony-storage.s3.ap-northeast-2.amazonaws.com/category/icons/korean_black.png"
iconUrl = "https://spoony-storage.s3.ap-northeast-2.amazonaws.com/category/icons/korean_white.png",
unSelectedIconUrl = "https://spoony-storage.s3.ap-northeast-2.amazonaws.com/category/icons/korean_black.png"
),
Category(
CategoryEntity(
categoryId = 4,
categoryName = "중식",
iconUrlSelected = "https://spoony-storage.s3.ap-northeast-2.amazonaws.com/category/icons/korean_white.png",
iconUrlNotSelected = "https://spoony-storage.s3.ap-northeast-2.amazonaws.com/category/icons/korean_black.png"
iconUrl = "https://spoony-storage.s3.ap-northeast-2.amazonaws.com/category/icons/korean_white.png",
unSelectedIconUrl = "https://spoony-storage.s3.ap-northeast-2.amazonaws.com/category/icons/korean_black.png"
),
Category(
CategoryEntity(
categoryId = 5,
categoryName = "양식",
iconUrlSelected = "https://spoony-storage.s3.ap-northeast-2.amazonaws.com/category/icons/korean_white.png",
iconUrlNotSelected = "https://spoony-storage.s3.ap-northeast-2.amazonaws.com/category/icons/korean_black.png"
iconUrl = "https://spoony-storage.s3.ap-northeast-2.amazonaws.com/category/icons/korean_white.png",
unSelectedIconUrl = "https://spoony-storage.s3.ap-northeast-2.amazonaws.com/category/icons/korean_black.png"
),
Category(
CategoryEntity(
categoryId = 6,
categoryName = "퓨전/세계요리",
iconUrlSelected = "https://spoony-storage.s3.ap-northeast-2.amazonaws.com/category/icons/korean_white.png",
iconUrlNotSelected = "https://spoony-storage.s3.ap-northeast-2.amazonaws.com/category/icons/korean_black.png"
iconUrl = "https://spoony-storage.s3.ap-northeast-2.amazonaws.com/category/icons/korean_white.png",
unSelectedIconUrl = "https://spoony-storage.s3.ap-northeast-2.amazonaws.com/category/icons/korean_black.png"
),
Category(
CategoryEntity(
categoryId = 7,
categoryName = "카페",
iconUrlSelected = "https://spoony-storage.s3.ap-northeast-2.amazonaws.com/category/icons/korean_white.png",
iconUrlNotSelected = "https://spoony-storage.s3.ap-northeast-2.amazonaws.com/category/icons/korean_black.png"
iconUrl = "https://spoony-storage.s3.ap-northeast-2.amazonaws.com/category/icons/korean_white.png",
unSelectedIconUrl = "https://spoony-storage.s3.ap-northeast-2.amazonaws.com/category/icons/korean_black.png"
),
Category(
CategoryEntity(
categoryId = 8,
categoryName = "주류",
iconUrlSelected = "https://spoony-storage.s3.ap-northeast-2.amazonaws.com/category/icons/korean_white.png",
iconUrlNotSelected = "https://spoony-storage.s3.ap-northeast-2.amazonaws.com/category/icons/korean_black.png"
iconUrl = "https://spoony-storage.s3.ap-northeast-2.amazonaws.com/category/icons/korean_white.png",
unSelectedIconUrl = "https://spoony-storage.s3.ap-northeast-2.amazonaws.com/category/icons/korean_black.png"
)
)
)

override suspend fun searchPlace(query: String, display: Int): Result<List<Place>> = runCatching {
override suspend fun searchPlace(query: String, display: Int): Result<List<PlaceEntity>> = runCatching {
placeDataSource.getPlaces(query, display).data!!.placeList
.map { it.toDomain().toPresentation() }
.map { it.toDomain() }
}

override suspend fun checkDuplicatePlace(
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
package com.spoony.spoony.domain.repository

import android.net.Uri
import com.spoony.spoony.presentation.register.model.Category
import com.spoony.spoony.presentation.register.model.Place
import com.spoony.spoony.domain.entity.CategoryEntity
import com.spoony.spoony.domain.entity.PlaceEntity

interface RegisterRepository {
suspend fun getCategories(): Result<List<Category>>

suspend fun searchPlace(query: String, display: Int = 5): Result<List<Place>>

suspend fun getCategories(): Result<List<CategoryEntity>>
suspend fun searchPlace(query: String, display: Int = 5): Result<List<PlaceEntity>>
suspend fun checkDuplicatePlace(
userId: Long,
latitude: Double,
longitude: Double
): Result<Boolean>

suspend fun registerPost(
userId: Long,
title: String,
Original file line number Diff line number Diff line change
@@ -38,11 +38,17 @@ class RegisterViewModel @Inject constructor(
private fun loadCategories() {
viewModelScope.launch {
repository.getCategories()
.onSuccess { categories ->
.onSuccess { categoryEntities ->
val categories = categoryEntities.map { entity ->
Category(
categoryId = entity.categoryId,
categoryName = entity.categoryName,
iconUrlSelected = entity.iconUrl,
iconUrlNotSelected = entity.unSelectedIconUrl ?: entity.iconUrl
)
}
_state.update { it.copy(categories = categories.toImmutableList()) }
}
.onFailure {
}
}
}

@@ -51,25 +57,21 @@ class RegisterViewModel @Inject constructor(
}

fun searchPlace(query: String) {
if (query.isBlank()) {
_state.update { it.copy(searchResults = persistentListOf()) }
return
}

viewModelScope.launch {
_state.update { it.copy(isSearching = true) }

repository.searchPlace(query)
.onSuccess { places ->
_state.update {
it.copy(
searchResults = places.toImmutableList(),
isSearching = false
.onSuccess { placeEntities ->
val places = placeEntities.map { entity ->
Place(
placeName = entity.placeName,
placeAddress = entity.placeAddress,
placeRoadAddress = entity.placeRoadAddress,
latitude = entity.latitude,
longitude = entity.longitude
)
}
}
.onFailure {
_state.update { it.copy(isSearching = false) }
_state.update {
it.copy(searchResults = places.toImmutableList())
}
}
}
}

0 comments on commit b4b54da

Please sign in to comment.