-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from f-lab-edu/feature/13
[#13] FestivalScreen / MoreScreen 구현
- Loading branch information
Showing
42 changed files
with
1,385 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
app/src/main/java/kr/ksw/visitkorea/data/paging/source/SearchFestivalPagingSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package kr.ksw.visitkorea.data.paging.source | ||
|
||
import androidx.paging.PagingSource | ||
import androidx.paging.PagingState | ||
import kr.ksw.visitkorea.data.mapper.toItems | ||
import kr.ksw.visitkorea.data.remote.api.SearchFestivalApi | ||
import kr.ksw.visitkorea.data.remote.dto.SearchFestivalDTO | ||
|
||
class SearchFestivalPagingSource( | ||
private val searchFestivalApi: SearchFestivalApi, | ||
private val eventStartDate: String, | ||
private val eventEndDate: String, | ||
private val areaCode: String?, | ||
private val sigunguCode: String? | ||
) : PagingSource<Int, SearchFestivalDTO>() { | ||
|
||
override fun getRefreshKey(state: PagingState<Int, SearchFestivalDTO>): Int? { | ||
return state.anchorPosition?.let { anchor -> | ||
val anchorPage = state.closestPageToPosition(anchor) | ||
anchorPage?.prevKey?.plus(1) ?: anchorPage?.nextKey?.minus(1) | ||
} | ||
} | ||
|
||
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, SearchFestivalDTO> { | ||
val page = params.key ?: 1 | ||
val loadSize = params.loadSize | ||
val response = searchFestivalApi.searchFestival( | ||
numOfRows = loadSize, | ||
pageNo = page, | ||
eventStartDate = eventStartDate, | ||
eventEndDate = eventEndDate, | ||
areaCode = areaCode, | ||
sigunguCode = sigunguCode | ||
) | ||
val data = response.toItems() | ||
return LoadResult.Page( | ||
data = data, | ||
prevKey = if(page == 1) null else page - 1, | ||
nextKey = if(data.size == loadSize) | ||
page + 1 | ||
else null | ||
) | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
app/src/main/java/kr/ksw/visitkorea/data/remote/api/SearchFestivalApi.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package kr.ksw.visitkorea.data.remote.api | ||
|
||
import kr.ksw.visitkorea.data.remote.dto.SearchFestivalDTO | ||
import kr.ksw.visitkorea.data.remote.model.ApiResponse | ||
import retrofit2.http.GET | ||
import retrofit2.http.Query | ||
|
||
interface SearchFestivalApi { | ||
@GET("searchFestival1") | ||
suspend fun searchFestival( | ||
@Query("arrange") arrange: String = "S", | ||
@Query("numOfRows") numOfRows: Int, | ||
@Query("pageNo") pageNo: Int, | ||
@Query("eventStartDate") eventStartDate: String, | ||
@Query("eventEndDate") eventEndDate: String, | ||
@Query("areaCode") areaCode: String? = null, | ||
@Query("sigunguCode") sigunguCode: String? = null | ||
): ApiResponse<SearchFestivalDTO> | ||
} |
31 changes: 31 additions & 0 deletions
31
app/src/main/java/kr/ksw/visitkorea/data/remote/dto/SearchFestivalDTO.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package kr.ksw.visitkorea.data.remote.dto | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class SearchFestivalDTO( | ||
@SerializedName("addr1") | ||
val address: String, | ||
@SerializedName("areacode") | ||
val areaCode: String, | ||
@SerializedName("sigungucode") | ||
val sigunguCode: String, | ||
@SerializedName("contentid") | ||
val contentId: String, | ||
@SerializedName("contenttypeid") | ||
val contentTypeId: String, | ||
@SerializedName("eventstartdate") | ||
val eventStartDate: String, | ||
@SerializedName("eventenddate") | ||
val eventEndDate: String, | ||
@SerializedName("firstimage") | ||
val firstImage: String, | ||
@SerializedName("firstimage2") | ||
val firstImage2: String, | ||
@SerializedName("mapx") | ||
val mapX: String, | ||
@SerializedName("mapy") | ||
val mapY: String, | ||
val cat3: String, | ||
val tel: String, | ||
val title: String | ||
) |
14 changes: 14 additions & 0 deletions
14
app/src/main/java/kr/ksw/visitkorea/data/repository/SearchFestivalRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package kr.ksw.visitkorea.data.repository | ||
|
||
import kr.ksw.visitkorea.data.remote.dto.SearchFestivalDTO | ||
|
||
interface SearchFestivalRepository { | ||
suspend operator fun invoke( | ||
numOfRows: Int, | ||
pageNo: Int, | ||
eventStartDate: String, | ||
eventEndDate: String, | ||
areaCode: String? = null, | ||
sigunguCode: String? = null | ||
): Result<List<SearchFestivalDTO>> | ||
} |
28 changes: 28 additions & 0 deletions
28
app/src/main/java/kr/ksw/visitkorea/data/repository/SearchFestivalRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package kr.ksw.visitkorea.data.repository | ||
|
||
import kr.ksw.visitkorea.data.mapper.toItems | ||
import kr.ksw.visitkorea.data.remote.api.SearchFestivalApi | ||
import kr.ksw.visitkorea.data.remote.dto.SearchFestivalDTO | ||
import javax.inject.Inject | ||
|
||
class SearchFestivalRepositoryImpl @Inject constructor( | ||
private val searchFestivalApi: SearchFestivalApi | ||
): SearchFestivalRepository { | ||
override suspend fun invoke( | ||
numOfRows: Int, | ||
pageNo: Int, | ||
eventStartDate: String, | ||
eventEndDate: String, | ||
areaCode: String?, | ||
sigunguCode: String? | ||
): Result<List<SearchFestivalDTO>> = runCatching { | ||
searchFestivalApi.searchFestival( | ||
numOfRows = numOfRows, | ||
pageNo = pageNo, | ||
eventStartDate = eventStartDate, | ||
eventEndDate = eventEndDate, | ||
areaCode = areaCode, | ||
sigunguCode = sigunguCode | ||
).toItems() | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/kr/ksw/visitkorea/domain/di/FestivalModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package kr.ksw.visitkorea.domain.di | ||
|
||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.components.ActivityRetainedComponent | ||
import kr.ksw.visitkorea.domain.usecase.festival.GetFestivalListUseCase | ||
import kr.ksw.visitkorea.domain.usecase.festival.GetFestivalListUseCaseImpl | ||
|
||
@Module | ||
@InstallIn(ActivityRetainedComponent::class) | ||
abstract class FestivalModule { | ||
@Binds | ||
abstract fun bindGetFestivalListUseCase(getFestivalListUseCase: GetFestivalListUseCaseImpl): GetFestivalListUseCase | ||
} |
17 changes: 17 additions & 0 deletions
17
app/src/main/java/kr/ksw/visitkorea/domain/di/MoreModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package kr.ksw.visitkorea.domain.di | ||
|
||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.components.ActivityRetainedComponent | ||
import kr.ksw.visitkorea.domain.usecase.more.GetMoreListUseCase | ||
import kr.ksw.visitkorea.domain.usecase.more.GetMoreListUseCaseImpl | ||
|
||
@Module | ||
@InstallIn(ActivityRetainedComponent::class) | ||
abstract class MoreModule { | ||
@Binds | ||
abstract fun bindGetMoreListUseCase( | ||
getMoreListUseCase: GetMoreListUseCaseImpl | ||
): GetMoreListUseCase | ||
} |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/kr/ksw/visitkorea/domain/usecase/festival/GetFestivalListUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package kr.ksw.visitkorea.domain.usecase.festival | ||
|
||
import androidx.paging.PagingData | ||
import kotlinx.coroutines.flow.Flow | ||
import kr.ksw.visitkorea.data.remote.dto.SearchFestivalDTO | ||
|
||
interface GetFestivalListUseCase { | ||
suspend operator fun invoke( | ||
forceFetch: Boolean, | ||
eventStartDate: String, | ||
eventEndDate: String, | ||
areaCode: String?, | ||
sigunguCode: String? | ||
) : Result<Flow<PagingData<SearchFestivalDTO>>> | ||
} |
48 changes: 48 additions & 0 deletions
48
app/src/main/java/kr/ksw/visitkorea/domain/usecase/festival/GetFestivalListUseCaseImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package kr.ksw.visitkorea.domain.usecase.festival | ||
|
||
import androidx.paging.Pager | ||
import androidx.paging.PagingConfig | ||
import androidx.paging.PagingData | ||
import androidx.paging.PagingSource | ||
import kotlinx.coroutines.flow.Flow | ||
import kr.ksw.visitkorea.data.paging.source.SearchFestivalPagingSource | ||
import kr.ksw.visitkorea.data.remote.api.SearchFestivalApi | ||
import kr.ksw.visitkorea.data.remote.dto.SearchFestivalDTO | ||
import javax.inject.Inject | ||
|
||
class GetFestivalListUseCaseImpl @Inject constructor( | ||
private val searchFestivalApi: SearchFestivalApi | ||
) : GetFestivalListUseCase { | ||
private var pagingSource: PagingSource<Int, SearchFestivalDTO>? = null | ||
|
||
override suspend fun invoke( | ||
forceFetch: Boolean, | ||
eventStartDate: String, | ||
eventEndDate: String, | ||
areaCode: String?, | ||
sigunguCode: String? | ||
): Result<Flow<PagingData<SearchFestivalDTO>>> = runCatching { | ||
if(forceFetch && | ||
pagingSource != null && | ||
pagingSource?.invalid != true) { | ||
pagingSource?.invalidate() | ||
} | ||
Pager( | ||
config = PagingConfig( | ||
pageSize = 20, | ||
initialLoadSize = 20 | ||
), | ||
pagingSourceFactory = { | ||
SearchFestivalPagingSource( | ||
searchFestivalApi, | ||
eventStartDate, | ||
eventEndDate, | ||
areaCode, | ||
sigunguCode | ||
).also { | ||
pagingSource = it | ||
} | ||
} | ||
).flow | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
app/src/main/java/kr/ksw/visitkorea/domain/usecase/model/Festival.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package kr.ksw.visitkorea.domain.usecase.model | ||
|
||
data class Festival( | ||
val address: String = "", | ||
val firstImage: String = "", | ||
val title: String = "", | ||
val contentId: String = "", | ||
val eventStartDate: String = "", | ||
val eventEndDate: String = "" | ||
) |
Oops, something went wrong.