From 92312340f4b5c67ff178bc9d7acdc2a2a2934bb9 Mon Sep 17 00:00:00 2001 From: vrexpert Date: Wed, 20 Mar 2024 14:07:01 +0900 Subject: [PATCH] =?UTF-8?q?feat(DefaultSearchRepository):=20=EA=B2=80?= =?UTF-8?q?=EC=83=89=20=EC=A0=80=EC=9E=A5=EC=86=8C=20=EC=A0=95=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/DefaultSearchRepository.kt | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 android/festago/data/src/main/java/com/festago/festago/data/repository/DefaultSearchRepository.kt diff --git a/android/festago/data/src/main/java/com/festago/festago/data/repository/DefaultSearchRepository.kt b/android/festago/data/src/main/java/com/festago/festago/data/repository/DefaultSearchRepository.kt new file mode 100644 index 000000000..322fbcb23 --- /dev/null +++ b/android/festago/data/src/main/java/com/festago/festago/data/repository/DefaultSearchRepository.kt @@ -0,0 +1,33 @@ +package com.festago.festago.data.repository + +import com.festago.festago.data.service.SearchRetrofitService +import com.festago.festago.data.util.onSuccessOrCatch +import com.festago.festago.data.util.runCatchingResponse +import com.festago.festago.domain.model.festival.Festival +import com.festago.festago.domain.model.search.ArtistSearch +import com.festago.festago.domain.model.search.SchoolSearch +import com.festago.festago.domain.repository.SearchRepository +import javax.inject.Inject + +class DefaultSearchRepository @Inject constructor( + private val searchRetrofitService: SearchRetrofitService, +) : SearchRepository { + + override suspend fun searchFestivals(searchQuery: String): Result> { + return runCatchingResponse { searchRetrofitService.searchFestivals(searchQuery) }.onSuccessOrCatch { festivalResponses -> + festivalResponses.map { it.toDomain() } + } + } + + override suspend fun searchArtists(searchQuery: String): Result> { + return runCatchingResponse { + searchRetrofitService.searchArtists(searchQuery) + }.onSuccessOrCatch { artistSearchResponses -> artistSearchResponses.map { it.toDomain() } } + } + + override suspend fun searchSchools(searchQuery: String): Result> { + return runCatchingResponse { + searchRetrofitService.searchSchools(searchQuery) + }.onSuccessOrCatch { schoolSearchResponses -> schoolSearchResponses.map { it.toDomain() } } + } +}