Skip to content
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

[FEAT/#117] 장소 검색 API 세팅 #121

Merged
merged 15 commits into from
Jan 22, 2025
Merged
Changes from 1 commit
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
Next Next commit
[FEAT/#117] 장소 검색 API 세팅
angryPodo committed Jan 22, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit f3ec0f1ce836307b854052d01fbdb1b002dfdf76
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.spoony.spoony.data.datasource

import com.spoony.spoony.data.dto.response.BaseResponse
import com.spoony.spoony.data.dto.response.SearchPlaceData

interface PlaceDataSource {
suspend fun searchPlace(query: String, display: Int): BaseResponse<SearchPlaceData>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.spoony.spoony.data.datasourceimpl

import com.spoony.spoony.data.datasource.PlaceDataSource
import com.spoony.spoony.data.dto.response.BaseResponse
import com.spoony.spoony.data.dto.response.SearchPlaceData
import com.spoony.spoony.data.service.PlaceService
import javax.inject.Inject

class PlaceDataSourceImpl @Inject constructor(
private val placeService: PlaceService
) : PlaceDataSource {
override suspend fun searchPlace(
query: String,
display: Int
): BaseResponse<SearchPlaceData> =
placeService.searchPlace(query, display)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.spoony.spoony.data.di

import com.spoony.spoony.data.datasource.DummyRemoteDataSource
import com.spoony.spoony.data.datasource.PlaceDataSource
import com.spoony.spoony.data.datasourceimpl.DummyRemoteDataSourceImpl
import com.spoony.spoony.data.datasourceimpl.PlaceDataSourceImpl
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
@@ -13,5 +15,13 @@ import javax.inject.Singleton
abstract class DataSourceModule {
@Binds
@Singleton
abstract fun bindDummyDataSource(dummyRemoteDataSourceImpl: DummyRemoteDataSourceImpl): DummyRemoteDataSource
abstract fun bindDummyDataSource(
dummyRemoteDataSourceImpl: DummyRemoteDataSourceImpl
): DummyRemoteDataSource

@Binds
@Singleton
abstract fun bindPlaceDataSource(
placeDataSourceImpl: PlaceDataSourceImpl
): PlaceDataSource
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.spoony.spoony.data.di

import com.spoony.spoony.data.service.DummyService
import com.spoony.spoony.data.service.PlaceService
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
@@ -15,4 +16,9 @@ object ServiceModule {
@Singleton
fun provideDummyService(retrofit: Retrofit): DummyService =
retrofit.create(DummyService::class.java)

@Provides
@Singleton
fun providePlaceService(retrofit: Retrofit): PlaceService =
retrofit.create(PlaceService::class.java)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.spoony.spoony.data.dto.response

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class BaseResponse<T>(
@SerialName("success")
val success: Boolean,
@SerialName("error")
val error: ErrorResponse? = null,
@SerialName("data")
val data: T? = null
)

@Serializable
data class ErrorResponse(
@SerialName("message")
val message: String
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

p4) 추후 세홍이형 PR 머지하게되면 충돌 날 것 같아요!
꼭 해결하고 머지부탁드려요 :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

네ㅎ 컨플릭 해결하겠습니다!

Copy link
Collaborator

Choose a reason for hiding this comment

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

P1: 컨벤션에 맞게 네이밍 수정해봅시다~~ 노션 읽어라~~

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

히히 수정했습니다요

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.spoony.spoony.data.dto.response

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class SearchPlaceData(
@SerialName("placeList")
val placeList: List<PlaceDto>
)

@Serializable
data class PlaceDto(
@SerialName("placeName")
val placeName: String,
@SerialName("placeAddress")
val placeAddress: String,
@SerialName("placeRoadAddress")
val placeRoadAddress: String,
@SerialName("latitude")
val latitude: Double,
@SerialName("longitude")
val longitude: Double
)
23 changes: 23 additions & 0 deletions app/src/main/java/com/spoony/spoony/data/mapper/PlaceMapper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.spoony.spoony.data.mapper

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

fun PlaceDto.toPlaceEntity(): PlaceEntity =
Copy link
Collaborator

Choose a reason for hiding this comment

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

P1: 저희 컨벤션에 맞게 함수명 고쳐주세요~~!!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

수정했습니당~

PlaceEntity(
placeName = placeName,
placeAddress = placeAddress,
placeRoadAddress = placeRoadAddress,
latitude = latitude,
longitude = longitude
)

fun PlaceEntity.toPlace(): Place =
Copy link
Collaborator

Choose a reason for hiding this comment

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

p2) 함수명이 저희 컨벤션과 다른 것 같습니다! 수정 해주세요~

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

코딩 컨벤션과 맞게 수정했습니다~

Place(
placeName = placeName,
placeAddress = placeAddress,
placeRoadAddress = placeRoadAddress,
latitude = latitude,
longitude = longitude
)
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package com.spoony.spoony.data.repositoryimpl

import android.net.Uri
import com.spoony.spoony.data.datasource.PlaceDataSource
import com.spoony.spoony.data.mapper.toPlace
import com.spoony.spoony.data.mapper.toPlaceEntity
import com.spoony.spoony.domain.repository.RegisterRepository
import com.spoony.spoony.presentation.register.model.Category
import com.spoony.spoony.presentation.register.model.Place
Copy link
Collaborator

Choose a reason for hiding this comment

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

P1: 어라라????? data레이어에서 presentation 레이어의 모델을 사용하네요?? 수정해주세요!!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

싹 수정했습니다!

import javax.inject.Inject

class RegisterRepositoryImpl @Inject constructor() : RegisterRepository {
class RegisterRepositoryImpl @Inject constructor(
private val placeDataSource: PlaceDataSource
) : RegisterRepository {
override suspend fun getCategories(): Result<List<Category>> = Result.success(
listOf(
Category(
@@ -54,45 +59,15 @@ class RegisterRepositoryImpl @Inject constructor() : RegisterRepository {
)
)

override suspend fun searchPlace(query: String, display: Int): Result<List<Place>> = Result.success(
listOf(
Place(
placeName = "스타벅스 강남대로점",
placeAddress = "서울특별시 서초구 서초동 1305-7",
placeRoadAddress = "서울특별시 서초구 강남대로 369 (서초동)",
latitude = 37.4979,
longitude = 127.0276
),
Place(
placeName = "스타벅스 신촌역점",
placeAddress = "서울특별시 서대문구 창천동 30-1",
placeRoadAddress = "서울특별시 서대문구 연세로 10-1 (창천동)",
latitude = 37.5598,
longitude = 126.9423
),
Place(
placeName = "스타벅스 홍대역점",
placeAddress = "서울특별시 마포구 서교동 358-11",
placeRoadAddress = "서울특별시 마포구 양화로 166 (서교동)",
latitude = 37.5569,
longitude = 126.9237
),
Place(
placeName = "스타벅스 부산센텀시티점",
placeAddress = "부산광역시 해운대구 우동 1505",
placeRoadAddress = "부산광역시 해운대구 센텀남대로 35 (우동)",
latitude = 35.1698,
longitude = 129.1315
),
Place(
placeName = "스타벅스 대구동성로점",
placeAddress = "대구광역시 중구 동성로3가 11",
placeRoadAddress = "대구광역시 중구 동성로 55 (동성로3가)",
latitude = 35.8703,
longitude = 128.5978
)
)
)
override suspend fun searchPlace(query: String, display: Int): Result<List<Place>> = runCatching {
val response = placeDataSource.searchPlace(query, display)
if (!response.success || response.data == null) {
throw IllegalStateException(response.error?.message ?: "에러 발생")
}
response.data.placeList.map { placeDto ->
placeDto.toPlaceEntity().toPlace()
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

p1) 저희 컨벤션 맞게 runCatching 내부에서 !!를 사용하는 방법으로 부탁드려요!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

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

로 수정했습니다!


override suspend fun checkDuplicatePlace(
userId: Long,
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.spoony.spoony.data.service

import com.spoony.spoony.data.dto.response.BaseResponse
import com.spoony.spoony.data.dto.response.SearchPlaceData
import retrofit2.http.GET
import retrofit2.http.Query

interface PlaceService {
@GET("api/v1/place/search")
suspend fun searchPlace(
@Query("query") query: String,
@Query("display") display: Int = 5
): BaseResponse<SearchPlaceData>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.spoony.spoony.domain.entity

data class PlaceEntity(
val placeName: String,
val placeAddress: String,
val placeRoadAddress: String,
val latitude: Double,
val longitude: Double
)

data class PlaceSearchResultEntity(
val placeList: List<PlaceEntity>
)