Skip to content

Commit a56f126

Browse files
committed
[NDGL-69] feature: 장소 관련 API 연동
- placeRepository, placeApi, 관련 Response 제작
1 parent e873670 commit a56f126

7 files changed

Lines changed: 135 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.yapp.ndgl.data.travel.api
2+
3+
import com.yapp.ndgl.data.core.model.BaseResponse
4+
import com.yapp.ndgl.data.travel.model.GetPlacePhotosResponse
5+
import com.yapp.ndgl.data.travel.model.PlaceDetailResponse
6+
import com.yapp.ndgl.data.travel.model.SavePlaceRequest
7+
import retrofit2.http.Body
8+
import retrofit2.http.GET
9+
import retrofit2.http.POST
10+
import retrofit2.http.Query
11+
12+
interface PlaceApi {
13+
@GET("/api/v1/places/detail")
14+
suspend fun getPlaceDetail(
15+
@Query("googlePlaceId") googlePlaceId: String,
16+
): BaseResponse<PlaceDetailResponse>
17+
18+
@POST("/api/v1/places")
19+
suspend fun savePlace(
20+
@Body request: SavePlaceRequest,
21+
): BaseResponse<PlaceDetailResponse>
22+
23+
@GET("/api/v1/places/photos")
24+
suspend fun getPlacePhotos(
25+
@Query("googlePlaceId") googlePlaceId: String,
26+
): BaseResponse<GetPlacePhotosResponse>
27+
}

data/travel/src/main/java/com/yapp/ndgl/data/travel/di/TravelNetworkModule.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.yapp.ndgl.data.travel.di
22

3+
import com.yapp.ndgl.data.travel.api.PlaceApi
34
import com.yapp.ndgl.data.travel.api.TravelProgramApi
45
import com.yapp.ndgl.data.travel.api.TravelTemplateApi
56
import com.yapp.ndgl.data.travel.api.UserTravelApi
@@ -30,4 +31,10 @@ object TravelNetworkModule {
3031
fun provideUserTravelApi(
3132
retrofit: Retrofit,
3233
): UserTravelApi = retrofit.create(UserTravelApi::class.java)
34+
35+
@Provides
36+
@Singleton
37+
fun providePlaceApi(
38+
retrofit: Retrofit,
39+
): PlaceApi = retrofit.create(PlaceApi::class.java)
3340
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.yapp.ndgl.data.travel.model
2+
3+
import kotlinx.serialization.Serializable
4+
5+
@Serializable
6+
data class GetPlacePhotosResponse(
7+
val photos: List<PlacePhoto>,
8+
)
9+
10+
@Serializable
11+
data class PlacePhoto(
12+
val photoUri: String,
13+
val widthPx: Int,
14+
val heightPx: Int,
15+
)
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.yapp.ndgl.data.travel.model
2+
3+
import kotlinx.serialization.Serializable
4+
5+
@Serializable
6+
data class PlaceDetailResponse(
7+
val place: PlaceDetail,
8+
)
9+
10+
@Serializable
11+
data class PlaceDetail(
12+
val id: String,
13+
val name: String,
14+
val category: PlaceCategory,
15+
val thumbnail: String? = null,
16+
val nationalPhoneNumber: String? = null,
17+
val internationalPhoneNumber: String? = null,
18+
val formattedAddress: String? = null,
19+
val location: Location,
20+
val userRatingCount: Int? = null,
21+
val rating: Double? = null,
22+
val regularOpeningHours: List<String>? = null,
23+
val googleMapsUri: String? = null,
24+
val websiteUri: String? = null,
25+
val priceRange: PriceRange? = null,
26+
) {
27+
@Serializable
28+
data class Location(
29+
val latitude: Double,
30+
val longitude: Double,
31+
)
32+
33+
@Serializable
34+
data class PriceRange(
35+
val startPrice: Price,
36+
val endPrice: Price,
37+
)
38+
39+
@Serializable
40+
data class Price(
41+
val currencyCode: String,
42+
val units: String,
43+
val symbol: String,
44+
)
45+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.yapp.ndgl.data.travel.model
2+
3+
import kotlinx.serialization.Serializable
4+
5+
@Serializable
6+
data class SavePlaceRequest(
7+
val googlePlaceId: String,
8+
)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.yapp.ndgl.data.travel.repository
2+
3+
import com.yapp.ndgl.data.core.model.error.HttpResponseException
4+
import com.yapp.ndgl.data.core.model.getData
5+
import com.yapp.ndgl.data.travel.api.PlaceApi
6+
import com.yapp.ndgl.data.travel.model.GetPlacePhotosResponse
7+
import com.yapp.ndgl.data.travel.model.PlaceDetailResponse
8+
import com.yapp.ndgl.data.travel.model.SavePlaceRequest
9+
import javax.inject.Inject
10+
import javax.inject.Singleton
11+
12+
@Singleton
13+
class PlaceRepository @Inject constructor(
14+
private val placeApi: PlaceApi,
15+
) {
16+
suspend fun getPlace(googlePlaceId: String): PlaceDetailResponse {
17+
return try {
18+
placeApi.getPlaceDetail(googlePlaceId).getData()
19+
} catch (e: HttpResponseException) {
20+
if (e.code == "PLACE-02-001") {
21+
placeApi.savePlace(SavePlaceRequest(googlePlaceId)).getData()
22+
} else {
23+
throw e
24+
}
25+
}
26+
}
27+
28+
suspend fun getPlacePhotos(googlePlaceId: String): GetPlacePhotosResponse {
29+
return placeApi.getPlacePhotos(googlePlaceId).getData()
30+
}
31+
}

feature/travel/src/main/java/com/yapp/ndgl/feature/travel/model/PlaceType.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,5 @@ internal fun PlaceCategory.toPlaceType(): PlaceType = when (this) {
3434
PlaceCategory.CAFE -> PlaceType.CAFE
3535
PlaceCategory.ACCOMMODATION -> PlaceType.ACCOMMODATION
3636
}
37+
38+
fun String.toPlaceType(): PlaceType = PlaceType.entries.find { it.name == this } ?: PlaceType.ATTRACTION

0 commit comments

Comments
 (0)