Skip to content

Commit

Permalink
Merge pull request #92 from eshc123/dev
Browse files Browse the repository at this point in the history
[RELEASE]
  • Loading branch information
eshc123 authored Jun 7, 2024
2 parents 60d7331 + a15e3ec commit 7279145
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ package com.eshc.goonersapp.core.data.mapper

import com.eshc.goonersapp.core.database.model.PlayerEntity
import com.eshc.goonersapp.core.domain.model.player.Player
import com.eshc.goonersapp.core.domain.model.player.PlayerList
import com.eshc.goonersapp.core.network.model.player.RemotePlayer
import com.eshc.goonersapp.core.network.model.player.RemotePlayerList

fun RemotePlayerList.toModel() = PlayerList(
players = teamPlayer.map { it.toModel() },
page = page ?: 0,
size = size ?: 0
)

fun RemotePlayer.toModel() = Player(
id = playerId ?: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import com.eshc.goonersapp.core.database.model.onFailure
import com.eshc.goonersapp.core.database.model.onSuccess
import com.eshc.goonersapp.core.domain.model.DataResult
import com.eshc.goonersapp.core.domain.model.player.Player
import com.eshc.goonersapp.core.domain.model.player.PlayerList
import com.eshc.goonersapp.core.domain.repository.PlayerRepository
import com.eshc.goonersapp.core.network.PlayerNetworkDataSource
import com.eshc.goonersapp.core.network.model.NetworkResult
import com.eshc.goonersapp.core.network.model.player.RemotePlayerList
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import javax.inject.Inject
Expand All @@ -22,12 +24,10 @@ class PlayerRepositoryImpl @Inject constructor(
private val playerNetworkDataSource: PlayerNetworkDataSource,
private val playerLocalDataSource: PlayerLocalDataSource
) : PlayerRepository {
override fun getPlayers(): Flow<DataResult<List<Player>>> = flow {
override fun getPlayers(): Flow<DataResult<PlayerList>> = flow {
emit(
playerNetworkDataSource.getPlayerList().toDataResult {
it.map { remotePlayer ->
remotePlayer.toModel()
}
it.toModel()
}
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.eshc.goonersapp.core.domain.model.player

data class PlayerList(
val players : List<Player>,
val page : Int,
val size : Int
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package com.eshc.goonersapp.core.domain.repository

import com.eshc.goonersapp.core.domain.model.DataResult
import com.eshc.goonersapp.core.domain.model.player.Player
import com.eshc.goonersapp.core.domain.model.player.PlayerList
import kotlinx.coroutines.flow.Flow

interface PlayerRepository {

fun getPlayers() : Flow<DataResult<List<Player>>>
fun getPlayers() : Flow<DataResult<PlayerList>>

fun getPlayerDetail(playerId: Int) : Flow<Player>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.eshc.goonersapp.core.domain.usecase.player

import com.eshc.goonersapp.core.domain.model.DataResult
import com.eshc.goonersapp.core.domain.model.player.Player
import com.eshc.goonersapp.core.domain.model.player.PlayerList
import com.eshc.goonersapp.core.domain.repository.PlayerRepository
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject
Expand All @@ -10,6 +11,6 @@ class GetPlayersUseCase @Inject constructor(
private val playerRepository: PlayerRepository
) {

operator fun invoke(): Flow<DataResult<List<Player>>> =
operator fun invoke(): Flow<DataResult<PlayerList>> =
playerRepository.getPlayers()
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package com.eshc.goonersapp.core.network

import com.eshc.goonersapp.core.network.model.NetworkResult
import com.eshc.goonersapp.core.network.model.player.RemotePlayer
import com.eshc.goonersapp.core.network.model.player.RemotePlayerList

interface PlayerNetworkDataSource {

suspend fun getPlayerList() : NetworkResult<List<RemotePlayer>>
suspend fun getPlayerList() : NetworkResult<RemotePlayerList>

suspend fun getPlayerDetail(playerId : Int) : NetworkResult<RemotePlayer>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.eshc.goonersapp.core.network.api

import com.eshc.goonersapp.core.network.model.BaseResponse
import com.eshc.goonersapp.core.network.model.player.RemotePlayer
import com.eshc.goonersapp.core.network.model.player.RemotePlayerList
import retrofit2.Response
import retrofit2.http.GET
import retrofit2.http.Query
Expand All @@ -14,9 +15,10 @@ interface PlayerNetworkService {
@Query("teamId") teamId : Int = 19,
@Query("seasonId") seasonId : Int = 21646,
@Query("positionId") positionId : Int? = null,
@Query("keyword") keyword : String? = null

) : Response<BaseResponse<List<RemotePlayer>>>
@Query("keyword") keyword : String? = null,
@Query("page") page : Int? = null,
@Query("size") size : Int? = null
) : Response<BaseResponse<RemotePlayerList>>

@GET(value = "$PLAYER_BASE_URL/detail")
suspend fun getPlayerDetail(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@ import com.eshc.goonersapp.core.network.model.NetworkResult
import com.eshc.goonersapp.core.network.model.match.RemoteMatch
import com.eshc.goonersapp.core.network.model.match.RemoteMatchData
import com.eshc.goonersapp.core.network.model.player.RemotePlayer
import com.eshc.goonersapp.core.network.model.player.RemotePlayerList

class FakePlayerNetworkDataSource : PlayerNetworkDataSource {

private var responseForPlayerList: (() -> List<RemotePlayer>)? = null
private var responseForPlayerList: (() -> RemotePlayerList)? = null
private var responseForPlayerDetail: (() -> RemotePlayer)? = null

fun setResponseForPlayerList(response:( () -> List<RemotePlayer>)?) {
fun setResponseForPlayerList(response:( () -> RemotePlayerList)?) {
this.responseForPlayerList = response
}

fun setResponseForPlayerDetail(response: (() -> RemotePlayer)?) {
this.responseForPlayerDetail = response
}

override suspend fun getPlayerList(): NetworkResult<List<RemotePlayer>> {
override suspend fun getPlayerList(): NetworkResult<RemotePlayerList> {
val response = responseForPlayerList?.invoke()
return if (response != null) {
NetworkResult.Success(response)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.eshc.goonersapp.core.network.model.player

import kotlinx.serialization.Serializable

@Serializable

data class RemotePlayerList(
val teamPlayer : List<RemotePlayer>,
val page : Int? = 0,
val size : Int? = 0
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.eshc.goonersapp.core.network.api.PlayerNetworkService
import com.eshc.goonersapp.core.network.model.NetworkResult
import com.eshc.goonersapp.core.network.model.handleApi
import com.eshc.goonersapp.core.network.model.player.RemotePlayer
import com.eshc.goonersapp.core.network.model.player.RemotePlayerList
import javax.inject.Inject
import javax.inject.Singleton

Expand All @@ -13,7 +14,7 @@ class PlayerNetworkDataSourceImpl @Inject constructor(
private val playerNetworkService: PlayerNetworkService
) : PlayerNetworkDataSource {

override suspend fun getPlayerList(): NetworkResult<List<RemotePlayer>> {
override suspend fun getPlayerList(): NetworkResult<RemotePlayerList> {
return handleApi {
playerNetworkService.getPlayers()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.eshc.goonersapp.core.network
import com.eshc.goonersapp.core.network.fake.FakePlayerNetworkDataSource
import com.eshc.goonersapp.core.network.model.NetworkResult
import com.eshc.goonersapp.core.network.model.player.RemotePlayer
import com.eshc.goonersapp.core.network.model.player.RemotePlayerList
import kotlinx.coroutines.runBlocking
import org.junit.Assert
import org.junit.Assert.fail
Expand All @@ -29,7 +30,9 @@ class FakePlayerDataSourceTest {
@Test
fun `fake_get_player_list_as_success`() = runBlocking {
fakePlayerNetworkDataSource.setResponseForPlayerList {
playerList
RemotePlayerList(
teamPlayer = playerList
)
}

when (val result = fakePlayerNetworkDataSource.getPlayerList()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class TeamViewModel @Inject constructor(
.map {
when(it){
is DataResult.Success -> {
TeamUiState.Success(it.data)
TeamUiState.Success(it.data.players)
}
is DataResult.Failure -> {
TeamUiState.Error
Expand Down

0 comments on commit 7279145

Please sign in to comment.