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

[Feature/#30] : 지도 api 연결 #31

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package com.hackathon.alddeul_babsang.app.di
import com.hackathon.alddeul_babsang.data.datasource.BabsangDataSource
import com.hackathon.alddeul_babsang.data.datasource.DetailDataSource
import com.hackathon.alddeul_babsang.data.datasource.ExampleDataSource
import com.hackathon.alddeul_babsang.data.datasource.MapDataSource
import com.hackathon.alddeul_babsang.data.datasource.ProfileDataSource
import com.hackathon.alddeul_babsang.data.datasource.UserPreferencesDataSource
import com.hackathon.alddeul_babsang.data.datasourceimpl.BabsangDataSourceImpl
import com.hackathon.alddeul_babsang.data.datasourceimpl.DetailDataSourceImpl
import com.hackathon.alddeul_babsang.data.datasourceimpl.ExampleDataSourceImpl
import com.hackathon.alddeul_babsang.data.datasourceimpl.MapDataSourceImpl
import com.hackathon.alddeul_babsang.data.datasourceimpl.ProfileDataSourceImpl
import com.hackathon.alddeul_babsang.data.datasourceimpl.UserPreferencesDataSourceImpl
import dagger.Binds
Expand Down Expand Up @@ -39,4 +41,8 @@ abstract class DataSourceModule {
@Binds
@Singleton
abstract fun bindDetailDataSource(detailDataSourceImpl: DetailDataSourceImpl): DetailDataSource

@Binds
@Singleton
abstract fun bindMapDataSource(mapDataSourceImpl: MapDataSourceImpl): MapDataSource
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package com.hackathon.alddeul_babsang.app.di
import com.hackathon.alddeul_babsang.data.repositoryimpl.BabsangRepositoryImpl
import com.hackathon.alddeul_babsang.data.repositoryimpl.DetailRepositoryImpl
import com.hackathon.alddeul_babsang.data.repositoryimpl.ExampleRepositoryImpl
import com.hackathon.alddeul_babsang.data.repositoryimpl.MapRepositoryImpl
import com.hackathon.alddeul_babsang.data.repositoryimpl.ProfileRepositoryImpl
import com.hackathon.alddeul_babsang.data.repositoryimpl.UserPreferencesRepositoryImpl
import com.hackathon.alddeul_babsang.domain.repository.BabsangRepository
import com.hackathon.alddeul_babsang.domain.repository.DetailRepository
import com.hackathon.alddeul_babsang.domain.repository.ExampleRepository
import com.hackathon.alddeul_babsang.domain.repository.MapRepository
import com.hackathon.alddeul_babsang.domain.repository.ProfileRepository
import com.hackathon.alddeul_babsang.domain.repository.UserPreferencesRepository
import dagger.Binds
Expand Down Expand Up @@ -39,4 +41,8 @@ abstract class RepositoryModule {
@Binds
@Singleton
abstract fun bindDetailRepository(detailRepositoryImpl: DetailRepositoryImpl): DetailRepository

@Binds
@Singleton
abstract fun bindMapRepository(mapRepositoryImpl: MapRepositoryImpl): MapRepository
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.hackathon.alddeul_babsang.app.di

import com.hackathon.alddeul_babsang.data.service.BabsangApiService
import com.hackathon.alddeul_babsang.data.service.DetailApiService
import com.hackathon.alddeul_babsang.data.service.MapApiService
import com.hackathon.alddeul_babsang.data.service.ProfileApiService
import com.sopt.data.service.ExampleApiService
import dagger.Module
Expand Down Expand Up @@ -38,4 +39,10 @@ object ServiceModule {
fun provideDetailService(
@AlddeulRetrofit retrofit: Retrofit
): DetailApiService = retrofit.create(DetailApiService::class.java)

@Provides
@Singleton
fun provideMapService(
@AlddeulRetrofit retrofit: Retrofit
): MapApiService = retrofit.create(MapApiService::class.java)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.hackathon.alddeul_babsang.data.datasource

import com.hackathon.alddeul_babsang.data.dto.BaseResponse
import com.hackathon.alddeul_babsang.data.dto.response.ResponseMapStoreDetailDto
import com.hackathon.alddeul_babsang.data.dto.response.ResponseMapStoresDto

interface MapDataSource {
suspend fun getMapStores(): BaseResponse<List<ResponseMapStoresDto>>
suspend fun getMapStoreDetail(id: Long): BaseResponse<ResponseMapStoreDetailDto>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.hackathon.alddeul_babsang.data.datasourceimpl

import com.hackathon.alddeul_babsang.data.datasource.MapDataSource
import com.hackathon.alddeul_babsang.data.dto.BaseResponse
import com.hackathon.alddeul_babsang.data.dto.response.ResponseMapStoreDetailDto
import com.hackathon.alddeul_babsang.data.dto.response.ResponseMapStoresDto
import com.hackathon.alddeul_babsang.data.service.MapApiService
import javax.inject.Inject

class MapDataSourceImpl @Inject constructor(
private val mapApiService: MapApiService
) : MapDataSource {
override suspend fun getMapStores(): BaseResponse<List<ResponseMapStoresDto>> {
return mapApiService.getMapStores()
}

override suspend fun getMapStoreDetail(id: Long): BaseResponse<ResponseMapStoreDetailDto> {
return mapApiService.getMapStoreDetail(id)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.hackathon.alddeul_babsang.data.dto.response

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

@Serializable
data class ResponseMapStoreDetailDto (
@SerialName("id") val id: Long,
@SerialName("name") val name: String,
@SerialName("category") val category: String,
@SerialName("address") val address: String,
@SerialName("contact") val contact: String,
@SerialName("imageUrl") val imageUrl: String? = null,
@SerialName("favorite") val favorite: Boolean,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.hackathon.alddeul_babsang.data.dto.response

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

@Serializable
data class ResponseMapStoresDto (
@SerialName("storeId") val storeId: Long,
@SerialName("name") val name: String,
@SerialName("category") val category: String,
@SerialName("address") val address: String,
@SerialName("region") val region: String,
@SerialName("latitude") val latitude: Double,
@SerialName("longitude") val longitude: Double,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.hackathon.alddeul_babsang.data.repositoryimpl

import com.hackathon.alddeul_babsang.data.datasource.MapDataSource
import com.hackathon.alddeul_babsang.data.dto.response.ResponseMapStoreDetailDto
import com.hackathon.alddeul_babsang.data.dto.response.ResponseMapStoresDto
import com.hackathon.alddeul_babsang.domain.repository.MapRepository
import javax.inject.Inject

class MapRepositoryImpl @Inject constructor(
private val mapDataSource: MapDataSource
) : MapRepository {
override suspend fun getMapStores(): Result<List<ResponseMapStoresDto>> {
return runCatching {
mapDataSource.getMapStores().result ?: emptyList()
}
}

override suspend fun getMapStoreDetail(id: Long): Result<ResponseMapStoreDetailDto?> {
return runCatching {
mapDataSource.getMapStoreDetail(id).result
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ object ApiKeyStorage {
const val LOGOUT = "logout"
const val USER_ID = "userId"
const val STORE_ID = "storeId"
const val ID = "id"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.hackathon.alddeul_babsang.data.service

import com.hackathon.alddeul_babsang.data.dto.BaseResponse
import com.hackathon.alddeul_babsang.data.dto.response.ResponseMapStoreDetailDto
import com.hackathon.alddeul_babsang.data.dto.response.ResponseMapStoresDto
import com.sopt.data.service.ApiKeyStorage.ID
import com.sopt.data.service.ApiKeyStorage.MAP
import com.sopt.data.service.ApiKeyStorage.STORES
import retrofit2.http.GET
import retrofit2.http.Path

interface MapApiService {
@GET("/$MAP/$STORES")
suspend fun getMapStores(): BaseResponse<List<ResponseMapStoresDto>>

@GET("/$MAP/$STORES/{$ID}")
suspend fun getMapStoreDetail(
@Path("id") id: Long
): BaseResponse<ResponseMapStoreDetailDto>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.hackathon.alddeul_babsang.domain.repository

import com.hackathon.alddeul_babsang.data.dto.response.ResponseMapStoreDetailDto
import com.hackathon.alddeul_babsang.data.dto.response.ResponseMapStoresDto

interface MapRepository {
suspend fun getMapStores(): Result<List<ResponseMapStoresDto>>
suspend fun getMapStoreDetail(id: Long): Result<ResponseMapStoreDetailDto?>
}
Loading
Loading