diff --git a/core/data/src/main/java/com/eshc/goonersapp/core/data/mapper/PlayerMapper.kt b/core/data/src/main/java/com/eshc/goonersapp/core/data/mapper/PlayerMapper.kt index 988d2824..9066e923 100644 --- a/core/data/src/main/java/com/eshc/goonersapp/core/data/mapper/PlayerMapper.kt +++ b/core/data/src/main/java/com/eshc/goonersapp/core/data/mapper/PlayerMapper.kt @@ -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, diff --git a/core/data/src/main/java/com/eshc/goonersapp/core/data/repository/PlayerRepositoryImpl.kt b/core/data/src/main/java/com/eshc/goonersapp/core/data/repository/PlayerRepositoryImpl.kt index 74988eef..d5913b98 100644 --- a/core/data/src/main/java/com/eshc/goonersapp/core/data/repository/PlayerRepositoryImpl.kt +++ b/core/data/src/main/java/com/eshc/goonersapp/core/data/repository/PlayerRepositoryImpl.kt @@ -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 @@ -22,12 +24,10 @@ class PlayerRepositoryImpl @Inject constructor( private val playerNetworkDataSource: PlayerNetworkDataSource, private val playerLocalDataSource: PlayerLocalDataSource ) : PlayerRepository { - override fun getPlayers(): Flow>> = flow { + override fun getPlayers(): Flow> = flow { emit( playerNetworkDataSource.getPlayerList().toDataResult { - it.map { remotePlayer -> - remotePlayer.toModel() - } + it.toModel() } ) } diff --git a/core/domain/src/main/java/com/eshc/goonersapp/core/domain/model/player/PlayerList.kt b/core/domain/src/main/java/com/eshc/goonersapp/core/domain/model/player/PlayerList.kt new file mode 100644 index 00000000..8712f494 --- /dev/null +++ b/core/domain/src/main/java/com/eshc/goonersapp/core/domain/model/player/PlayerList.kt @@ -0,0 +1,7 @@ +package com.eshc.goonersapp.core.domain.model.player + +data class PlayerList( + val players : List, + val page : Int, + val size : Int +) diff --git a/core/domain/src/main/java/com/eshc/goonersapp/core/domain/repository/PlayerRepository.kt b/core/domain/src/main/java/com/eshc/goonersapp/core/domain/repository/PlayerRepository.kt index 5589f96d..927ce0ce 100644 --- a/core/domain/src/main/java/com/eshc/goonersapp/core/domain/repository/PlayerRepository.kt +++ b/core/domain/src/main/java/com/eshc/goonersapp/core/domain/repository/PlayerRepository.kt @@ -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>> + fun getPlayers() : Flow> fun getPlayerDetail(playerId: Int) : Flow } \ No newline at end of file diff --git a/core/domain/src/main/java/com/eshc/goonersapp/core/domain/usecase/player/GetPlayersUseCase.kt b/core/domain/src/main/java/com/eshc/goonersapp/core/domain/usecase/player/GetPlayersUseCase.kt index ea918027..a7fa8ae1 100644 --- a/core/domain/src/main/java/com/eshc/goonersapp/core/domain/usecase/player/GetPlayersUseCase.kt +++ b/core/domain/src/main/java/com/eshc/goonersapp/core/domain/usecase/player/GetPlayersUseCase.kt @@ -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 @@ -10,6 +11,6 @@ class GetPlayersUseCase @Inject constructor( private val playerRepository: PlayerRepository ) { - operator fun invoke(): Flow>> = + operator fun invoke(): Flow> = playerRepository.getPlayers() } \ No newline at end of file diff --git a/core/network/src/main/java/com/eshc/goonersapp/core/network/PlayerNetworkDataSource.kt b/core/network/src/main/java/com/eshc/goonersapp/core/network/PlayerNetworkDataSource.kt index c04ab8f4..dc1bc037 100644 --- a/core/network/src/main/java/com/eshc/goonersapp/core/network/PlayerNetworkDataSource.kt +++ b/core/network/src/main/java/com/eshc/goonersapp/core/network/PlayerNetworkDataSource.kt @@ -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> + suspend fun getPlayerList() : NetworkResult suspend fun getPlayerDetail(playerId : Int) : NetworkResult } \ No newline at end of file diff --git a/core/network/src/main/java/com/eshc/goonersapp/core/network/api/PlayerNetworkService.kt b/core/network/src/main/java/com/eshc/goonersapp/core/network/api/PlayerNetworkService.kt index 667581f8..9e32098a 100644 --- a/core/network/src/main/java/com/eshc/goonersapp/core/network/api/PlayerNetworkService.kt +++ b/core/network/src/main/java/com/eshc/goonersapp/core/network/api/PlayerNetworkService.kt @@ -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 @@ -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>> + @Query("keyword") keyword : String? = null, + @Query("page") page : Int? = null, + @Query("size") size : Int? = null + ) : Response> @GET(value = "$PLAYER_BASE_URL/detail") suspend fun getPlayerDetail( diff --git a/core/network/src/main/java/com/eshc/goonersapp/core/network/fake/FakePlayerNetworkDataSource.kt b/core/network/src/main/java/com/eshc/goonersapp/core/network/fake/FakePlayerNetworkDataSource.kt index 554f313c..11c20186 100644 --- a/core/network/src/main/java/com/eshc/goonersapp/core/network/fake/FakePlayerNetworkDataSource.kt +++ b/core/network/src/main/java/com/eshc/goonersapp/core/network/fake/FakePlayerNetworkDataSource.kt @@ -5,13 +5,14 @@ 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)? = null + private var responseForPlayerList: (() -> RemotePlayerList)? = null private var responseForPlayerDetail: (() -> RemotePlayer)? = null - fun setResponseForPlayerList(response:( () -> List)?) { + fun setResponseForPlayerList(response:( () -> RemotePlayerList)?) { this.responseForPlayerList = response } @@ -19,7 +20,7 @@ class FakePlayerNetworkDataSource : PlayerNetworkDataSource { this.responseForPlayerDetail = response } - override suspend fun getPlayerList(): NetworkResult> { + override suspend fun getPlayerList(): NetworkResult { val response = responseForPlayerList?.invoke() return if (response != null) { NetworkResult.Success(response) diff --git a/core/network/src/main/java/com/eshc/goonersapp/core/network/model/player/RemotePlayerList.kt b/core/network/src/main/java/com/eshc/goonersapp/core/network/model/player/RemotePlayerList.kt new file mode 100644 index 00000000..517db41d --- /dev/null +++ b/core/network/src/main/java/com/eshc/goonersapp/core/network/model/player/RemotePlayerList.kt @@ -0,0 +1,11 @@ +package com.eshc.goonersapp.core.network.model.player + +import kotlinx.serialization.Serializable + +@Serializable + +data class RemotePlayerList( + val teamPlayer : List, + val page : Int? = 0, + val size : Int? = 0 +) diff --git a/core/network/src/main/java/com/eshc/goonersapp/core/network/remote/PlayerNetworkDataSourceImpl.kt b/core/network/src/main/java/com/eshc/goonersapp/core/network/remote/PlayerNetworkDataSourceImpl.kt index 057231e6..594644fe 100644 --- a/core/network/src/main/java/com/eshc/goonersapp/core/network/remote/PlayerNetworkDataSourceImpl.kt +++ b/core/network/src/main/java/com/eshc/goonersapp/core/network/remote/PlayerNetworkDataSourceImpl.kt @@ -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 @@ -13,7 +14,7 @@ class PlayerNetworkDataSourceImpl @Inject constructor( private val playerNetworkService: PlayerNetworkService ) : PlayerNetworkDataSource { - override suspend fun getPlayerList(): NetworkResult> { + override suspend fun getPlayerList(): NetworkResult { return handleApi { playerNetworkService.getPlayers() } diff --git a/core/network/src/test/java/com/eshc/goonersapp/core/network/FakePlayerDataSourceTest.kt b/core/network/src/test/java/com/eshc/goonersapp/core/network/FakePlayerDataSourceTest.kt index 2fcf802a..8d0ec037 100644 --- a/core/network/src/test/java/com/eshc/goonersapp/core/network/FakePlayerDataSourceTest.kt +++ b/core/network/src/test/java/com/eshc/goonersapp/core/network/FakePlayerDataSourceTest.kt @@ -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 @@ -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()) { diff --git a/feature/team/src/main/java/com/eshc/goonersapp/feature/team/TeamViewModel.kt b/feature/team/src/main/java/com/eshc/goonersapp/feature/team/TeamViewModel.kt index a5d62eb3..73d3940a 100644 --- a/feature/team/src/main/java/com/eshc/goonersapp/feature/team/TeamViewModel.kt +++ b/feature/team/src/main/java/com/eshc/goonersapp/feature/team/TeamViewModel.kt @@ -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