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] Commons API 연동 #33

Merged
merged 3 commits into from
Jun 6, 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 @@ -2,11 +2,13 @@ package com.dongguk.telepigeon.di

import com.dongguk.telepigeon.data.local.datasource.TelePigeonLocalDataSource
import com.dongguk.telepigeon.data.local.datasourceimpl.TelePigeonLocalDataSourceImpl
import com.dongguk.telepigeon.data.remote.datasource.CommonRemoteDataSource
import com.dongguk.telepigeon.data.remote.datasource.HurryRemoteDataSource
import com.dongguk.telepigeon.data.remote.datasource.ProfileRemoteDataSource
import com.dongguk.telepigeon.data.remote.datasource.QuestionAnswerRemoteDataSource
import com.dongguk.telepigeon.data.remote.datasource.RoomRemoteDataSource
import com.dongguk.telepigeon.data.remote.datasource.WorryRemoteDataSource
import com.dongguk.telepigeon.data.remote.datasourceimpl.CommonRemoteDataSourceImpl
import com.dongguk.telepigeon.data.remote.datasourceimpl.HurryRemoteDataSourceImpl
import com.dongguk.telepigeon.data.remote.datasourceimpl.ProfileRemoteDataSourceImpl
import com.dongguk.telepigeon.data.remote.datasourceimpl.QuestionAnswerRemoteDataSourceImpl
Expand All @@ -25,6 +27,10 @@ abstract class DataSourceModule {
@Singleton
abstract fun bindsTelePigeonLocalDataSource(telePigeonLocalDataSourceImpl: TelePigeonLocalDataSourceImpl): TelePigeonLocalDataSource

@Binds
@Singleton
abstract fun bindsCommonRemoteDataSource(commonRemoteDataSourceImpl: CommonRemoteDataSourceImpl): CommonRemoteDataSource

@Binds
@Singleton
abstract fun bindsHurryRemoteDataSource(hurryRemoteDataSourceImpl: HurryRemoteDataSourceImpl): HurryRemoteDataSource
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.dongguk.telepigeon.di

import com.dongguk.telepigeon.data.repositoryimpl.CommonRepositoryImpl
import com.dongguk.telepigeon.data.repositoryimpl.HurryRepositoryImpl
import com.dongguk.telepigeon.data.repositoryimpl.ProfileRepositoryImpl
import com.dongguk.telepigeon.data.repositoryimpl.QuestionAnswerRepositoryImpl
import com.dongguk.telepigeon.data.repositoryimpl.RoomRepositoryImpl
import com.dongguk.telepigeon.data.repositoryimpl.TelePigeonRepositoryImpl
import com.dongguk.telepigeon.data.repositoryimpl.WorryRepositoryImpl
import com.dongguk.telepigeon.domain.repository.CommonRepository
import com.dongguk.telepigeon.domain.repository.HurryRepository
import com.dongguk.telepigeon.domain.repository.ProfileRepository
import com.dongguk.telepigeon.domain.repository.QuestionAnswerRepository
Expand All @@ -23,12 +25,16 @@ import javax.inject.Singleton
abstract class RepositoryModule {
@Binds
@Singleton
abstract fun bindsProfileRepository(profileRepositoryImpl: ProfileRepositoryImpl): ProfileRepository
abstract fun bindsCommonRepository(commonRepositoryImpl: CommonRepositoryImpl): CommonRepository

@Binds
@Singleton
abstract fun bindsHurryRepository(hurryRepositoryImpl: HurryRepositoryImpl): HurryRepository

@Binds
@Singleton
abstract fun bindsProfileRepository(profileRepositoryImpl: ProfileRepositoryImpl): ProfileRepository

@Binds
@Singleton
abstract fun bindsQuestionAnswerRepository(questionAnswerRepositoryImpl: QuestionAnswerRepositoryImpl): QuestionAnswerRepository
Expand Down
14 changes: 11 additions & 3 deletions app/src/main/java/com/dongguk/telepigeon/di/ServiceModule.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dongguk.telepigeon.di

import com.dongguk.telepigeon.data.remote.service.CommonService
import com.dongguk.telepigeon.data.remote.service.HurryService
import com.dongguk.telepigeon.data.remote.service.ProfileService
import com.dongguk.telepigeon.data.remote.service.QuestionAnswerService
Expand All @@ -18,10 +19,10 @@ import javax.inject.Singleton
object ServiceModule {
@Provides
@Singleton
fun providesProfileService(
fun providesCommonService(
@TelePigeon retrofit: Retrofit,
): ProfileService =
retrofit.create(ProfileService::class.java)
): CommonService =
retrofit.create(CommonService::class.java)

@Provides
@Singleton
Expand All @@ -30,6 +31,13 @@ object ServiceModule {
): HurryService =
retrofit.create(HurryService::class.java)

@Provides
@Singleton
fun providesProfileService(
@TelePigeon retrofit: Retrofit,
): ProfileService =
retrofit.create(ProfileService::class.java)

@Provides
@Singleton
fun providesQuestionAnswerService(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.dongguk.telepigeon.data.remote.datasource

import com.dongguk.telepigeon.data.remote.model.response.ResponseGetAgeRangesDto
import com.dongguk.telepigeon.data.remote.model.response.ResponseGetGendersDto
import com.dongguk.telepigeon.data.remote.model.response.ResponseGetKeywordsDto
import com.dongguk.telepigeon.data.remote.model.response.ResponseGetRelationsDto
import com.dongguk.telepigeon.data.remote.model.response.base.BaseResponseDto

interface CommonRemoteDataSource {
suspend fun getKeywords(): BaseResponseDto<ResponseGetKeywordsDto>

suspend fun getGenders(): BaseResponseDto<ResponseGetGendersDto>

suspend fun getAgeRanges(): BaseResponseDto<ResponseGetAgeRangesDto>

suspend fun getRelations(): BaseResponseDto<ResponseGetRelationsDto>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.dongguk.telepigeon.data.remote.datasourceimpl

import com.dongguk.telepigeon.data.remote.datasource.CommonRemoteDataSource
import com.dongguk.telepigeon.data.remote.model.response.ResponseGetAgeRangesDto
import com.dongguk.telepigeon.data.remote.model.response.ResponseGetGendersDto
import com.dongguk.telepigeon.data.remote.model.response.ResponseGetKeywordsDto
import com.dongguk.telepigeon.data.remote.model.response.ResponseGetRelationsDto
import com.dongguk.telepigeon.data.remote.model.response.base.BaseResponseDto
import com.dongguk.telepigeon.data.remote.service.CommonService
import javax.inject.Inject

class CommonRemoteDataSourceImpl
@Inject
constructor(
private val commonService: CommonService,
) : CommonRemoteDataSource {
override suspend fun getKeywords(): BaseResponseDto<ResponseGetKeywordsDto> = commonService.getKeywords()

override suspend fun getGenders(): BaseResponseDto<ResponseGetGendersDto> = commonService.getGenders()

override suspend fun getAgeRanges(): BaseResponseDto<ResponseGetAgeRangesDto> = commonService.getAgeRanges()

override suspend fun getRelations(): BaseResponseDto<ResponseGetRelationsDto> = commonService.getRelations()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.dongguk.telepigeon.data.remote.model.response

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

@Serializable
data class ResponseGetAgeRangesDto(
@SerialName("ageRanges")
val ageRanges: List<String>,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.dongguk.telepigeon.data.remote.model.response

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

@Serializable
data class ResponseGetGendersDto(
@SerialName("gender")
val gender: List<String>,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.dongguk.telepigeon.data.remote.model.response

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

@Serializable
data class ResponseGetKeywordsDto(
@SerialName("keywords")
val keywords: List<String>,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.dongguk.telepigeon.data.remote.model.response

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

@Serializable
data class ResponseGetRelationsDto(
@SerialName("relations")
val relations: List<String>,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.dongguk.telepigeon.data.remote.service

import com.dongguk.telepigeon.data.remote.model.response.ResponseGetAgeRangesDto
import com.dongguk.telepigeon.data.remote.model.response.ResponseGetGendersDto
import com.dongguk.telepigeon.data.remote.model.response.ResponseGetKeywordsDto
import com.dongguk.telepigeon.data.remote.model.response.ResponseGetRelationsDto
import com.dongguk.telepigeon.data.remote.model.response.base.BaseResponseDto
import retrofit2.http.GET

interface CommonService {
@GET(KEYWORDS)
suspend fun getKeywords(): BaseResponseDto<ResponseGetKeywordsDto>

@GET(GENDERS)
suspend fun getGenders(): BaseResponseDto<ResponseGetGendersDto>

@GET(AGE_RANGES)
suspend fun getAgeRanges(): BaseResponseDto<ResponseGetAgeRangesDto>

@GET(RELATIONS)
suspend fun getRelations(): BaseResponseDto<ResponseGetRelationsDto>

companion object {
const val KEYWORDS = "keywords"
const val GENDERS = "genders"
const val AGE_RANGES = "age-ranges"
const val RELATIONS = "relations"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.dongguk.telepigeon.data.repositoryimpl

import com.dongguk.telepigeon.data.remote.datasource.CommonRemoteDataSource
import com.dongguk.telepigeon.domain.repository.CommonRepository
import javax.inject.Inject

class CommonRepositoryImpl
@Inject
constructor(
private val commonRemoteDataSource: CommonRemoteDataSource,
) : CommonRepository {
override suspend fun getKeywords(): Result<List<String>> =
runCatching {
commonRemoteDataSource.getKeywords().data.keywords
}

override suspend fun getGenders(): Result<List<String>> =
runCatching {
commonRemoteDataSource.getGenders().data.gender
}

override suspend fun getAgeRanges(): Result<List<String>> =
runCatching {
commonRemoteDataSource.getAgeRanges().data.ageRanges
}

override suspend fun getRelations(): Result<List<String>> =
runCatching {
commonRemoteDataSource.getRelations().data.relations
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.dongguk.telepigeon.domain.repository

interface CommonRepository {
suspend fun getKeywords(): Result<List<String>>

suspend fun getGenders(): Result<List<String>>

suspend fun getAgeRanges(): Result<List<String>>

suspend fun getRelations(): Result<List<String>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.dongguk.telepigeon.domain.usecase

import com.dongguk.telepigeon.domain.repository.CommonRepository
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class GetAgeRangesUseCase
@Inject
constructor(
private val commonRepository: CommonRepository,
) {
suspend operator fun invoke() = commonRepository.getAgeRanges()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.dongguk.telepigeon.domain.usecase

import com.dongguk.telepigeon.domain.repository.CommonRepository
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class GetGendersUseCase
@Inject
constructor(
private val commonRepository: CommonRepository,
) {
suspend operator fun invoke() = commonRepository.getGenders()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.dongguk.telepigeon.domain.usecase

import com.dongguk.telepigeon.domain.repository.CommonRepository
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class GetKeywordsUseCase
@Inject
constructor(
private val commonRepository: CommonRepository,
) {
suspend operator fun invoke() = commonRepository.getKeywords()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.dongguk.telepigeon.domain.usecase

import com.dongguk.telepigeon.domain.repository.CommonRepository
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class GetRelationsUseCase
@Inject
constructor(
private val commonRepository: CommonRepository,
) {
suspend operator fun invoke() = commonRepository.getRelations()
}
Loading
Loading