Skip to content

Commit

Permalink
Refactor: renamed all episodes use case.
Browse files Browse the repository at this point in the history
  • Loading branch information
hypeapps committed Apr 28, 2018
1 parent 23ed93c commit 8956355
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 52 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ import pl.hypeapp.domain.executor.ThreadExecutor
import pl.hypeapp.domain.model.WatchState
import pl.hypeapp.domain.model.tvshow.EpisodeModel
import pl.hypeapp.domain.repository.WatchedShowRepository
import pl.hypeapp.domain.usecase.allepisodes.AllEpisodesUseCase
import pl.hypeapp.domain.usecase.base.AbsRxCompletableUseCase
import pl.hypeapp.domain.usecase.gettvshow.GetTvShowExtendedUseCase
import pl.hypeapp.domain.usecase.watchstate.mapwatched.MapTvShowWatchStateUseCase
import javax.inject.Inject

class UpdateEpisodeWatchStateUseCase @Inject constructor(threadExecutor: ThreadExecutor,
postExecutionThread: PostExecutionThread,
private val allEpisodesUseCase: AllEpisodesUseCase,
private val getTvShowExtendedUseCase: GetTvShowExtendedUseCase,
private val mapTvShowWatchStateUseCase: MapTvShowWatchStateUseCase,
private val showRepository: WatchedShowRepository)
: AbsRxCompletableUseCase<UpdateEpisodeWatchStateUseCase.Params>(threadExecutor, postExecutionThread) {

override fun createCompletable(params: Params): Completable {
return allEpisodesUseCase.execute(AllEpisodesUseCase.Params.createQuery(params.episodeModel.tvShowId!!, false))
return getTvShowExtendedUseCase.execute(GetTvShowExtendedUseCase.Params.createQuery(params.episodeModel.tvShowId!!, false))
.flatMap { mapTvShowWatchStateUseCase.execute(MapTvShowWatchStateUseCase.Params.createParams(it)) }
.flatMapCompletable {
with(params) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ import pl.hypeapp.domain.executor.ThreadExecutor
import pl.hypeapp.domain.model.WatchState
import pl.hypeapp.domain.model.tvshow.SeasonModel
import pl.hypeapp.domain.repository.WatchedShowRepository
import pl.hypeapp.domain.usecase.allepisodes.AllEpisodesUseCase
import pl.hypeapp.domain.usecase.base.AbsRxCompletableUseCase
import pl.hypeapp.domain.usecase.gettvshow.GetTvShowExtendedUseCase
import pl.hypeapp.domain.usecase.watchstate.mapwatched.MapTvShowWatchStateUseCase
import javax.inject.Inject

class UpdateSeasonWatchStateUseCase @Inject constructor(threadExecutor: ThreadExecutor,
postExecutionThread: PostExecutionThread,
private val allEpisodesUseCase: AllEpisodesUseCase,
private val getTvShowExtendedUseCase: GetTvShowExtendedUseCase,
private val mapTvShowWatchStateUseCase: MapTvShowWatchStateUseCase,
private val showRepository: WatchedShowRepository)
: AbsRxCompletableUseCase<UpdateSeasonWatchStateUseCase.Params>(threadExecutor, postExecutionThread) {

override fun createCompletable(params: Params): Completable {
return allEpisodesUseCase.execute(AllEpisodesUseCase.Params.createQuery(params.seasonModel.tvShowId!!, false))
return getTvShowExtendedUseCase.execute(GetTvShowExtendedUseCase.Params.createQuery(params.seasonModel.tvShowId!!, false))
.flatMap { mapTvShowWatchStateUseCase.execute(MapTvShowWatchStateUseCase.Params.createParams(it)) }
.flatMapCompletable {
if (params.addToWatched) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ package pl.hypeapp.domain.usecase.watchstate
import io.reactivex.Completable
import pl.hypeapp.domain.executor.PostExecutionThread
import pl.hypeapp.domain.executor.ThreadExecutor
import pl.hypeapp.domain.usecase.allepisodes.AllEpisodesUseCase
import pl.hypeapp.domain.usecase.base.AbsRxCompletableUseCase
import pl.hypeapp.domain.usecase.gettvshow.GetTvShowExtendedUseCase
import javax.inject.Inject

class UpdateTvShowWatchStateByIdUseCase @Inject constructor(threadExecutor: ThreadExecutor,
postExecutionThread: PostExecutionThread,
private val allEpisodesUseCase: AllEpisodesUseCase,
private val getTvShowExtendedUseCase: GetTvShowExtendedUseCase,
private val updateTvShowWatchStateUseCase: UpdateTvShowWatchStateUseCase)
: AbsRxCompletableUseCase<UpdateTvShowWatchStateByIdUseCase.Params>(threadExecutor, postExecutionThread) {

override fun createCompletable(params: UpdateTvShowWatchStateByIdUseCase.Params): Completable {
return allEpisodesUseCase
.execute(AllEpisodesUseCase.Params.createQuery(params.tvShowId, update = false))
return getTvShowExtendedUseCase
.execute(GetTvShowExtendedUseCase.Params.createQuery(params.tvShowId, update = false))
.flatMapCompletable {
updateTvShowWatchStateUseCase.execute(UpdateTvShowWatchStateUseCase.Params.createParams(it, params.addToWatched))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import pl.hypeapp.domain.executor.PostExecutionThread
import pl.hypeapp.domain.executor.ThreadExecutor
import pl.hypeapp.domain.model.tvshow.TvShowExtendedModel
import pl.hypeapp.domain.repository.AllSeasonsRepository
import pl.hypeapp.domain.usecase.gettvshow.GetTvShowExtendedUseCase
import pl.hypeapp.domain.usecase.watchstate.mapwatched.WatchStateMapper

class AllEpisodesUseCaseTest {

private lateinit var useCase: AllEpisodesUseCase
private lateinit var useCase: GetTvShowExtendedUseCase

private val repository: AllSeasonsRepository = mock()

Expand All @@ -32,12 +33,12 @@ class AllEpisodesUseCaseTest {

@Before
fun setUp() {
useCase = AllEpisodesUseCase(threadExecutor, postExecutionThread, watchStateMapper, repository)
useCase = GetTvShowExtendedUseCase(threadExecutor, postExecutionThread, watchStateMapper, repository)
}

@Test
fun `should get all seasons`() {
val params: AllEpisodesUseCase.Params = AllEpisodesUseCase.Params.createQuery(ID, UPDATE)
val params: GetTvShowExtendedUseCase.Params = GetTvShowExtendedUseCase.Params.createQuery(ID, UPDATE)
val tvShowExtendedModel: TvShowExtendedModel = mock()
val returnedSingle: Single<TvShowExtendedModel> = Single.just(tvShowExtendedModel)
given(repository.getAllSeasonsAfterPremiereDate(ID, UPDATE)).willReturn(returnedSingle)
Expand Down

0 comments on commit 8956355

Please sign in to comment.