From 868c90eb0b674d043324a794383e10f6ef398e1f Mon Sep 17 00:00:00 2001 From: Jung SeokJoon Date: Thu, 23 May 2024 21:27:39 +0900 Subject: [PATCH 1/9] mod getMatchInformation response --- .../goonersapp/core/data/mapper/MatchMapper.kt | 15 --------------- .../core/domain/model/match/MatchInformation.kt | 1 - .../core/network/fake/FakeMatchDataSource.kt | 1 - .../network/model/match/RemoteMatchInformation.kt | 1 - 4 files changed, 18 deletions(-) diff --git a/core/data/src/main/java/com/eshc/goonersapp/core/data/mapper/MatchMapper.kt b/core/data/src/main/java/com/eshc/goonersapp/core/data/mapper/MatchMapper.kt index 39b141e3..a3fefcb5 100644 --- a/core/data/src/main/java/com/eshc/goonersapp/core/data/mapper/MatchMapper.kt +++ b/core/data/src/main/java/com/eshc/goonersapp/core/data/mapper/MatchMapper.kt @@ -54,21 +54,6 @@ fun RemoteMatchInformation.toModel() = MatchInformation( playerGoalCount = remote.goalCount ) }, - lineUp = lineUp.map { remote -> - LineUp( - lineUpId = remote.lineUpId, - matchId = remote.matchId, - playerId = remote.playerId, - teamId = remote.teamId, - playerName = remote.playerName, - playerBackNumber = remote.jerseyNumber, - formationField = remote.formationField, - formationPosition = remote.formationPosition, - positionId = remote.positionId, - positionCategory = remote.positionCategory, - positionInitial = remote.positionInitial - ) - }, performance = Performance( opponentImageUrl = performance.opponentImage, win = performance.win, diff --git a/core/domain/src/main/java/com/eshc/goonersapp/core/domain/model/match/MatchInformation.kt b/core/domain/src/main/java/com/eshc/goonersapp/core/domain/model/match/MatchInformation.kt index 271a29ec..165dbec0 100644 --- a/core/domain/src/main/java/com/eshc/goonersapp/core/domain/model/match/MatchInformation.kt +++ b/core/domain/src/main/java/com/eshc/goonersapp/core/domain/model/match/MatchInformation.kt @@ -2,7 +2,6 @@ package com.eshc.goonersapp.core.domain.model.match data class MatchInformation( val notablePlayer: NotablePlayer? = null, - val lineUp: List, val performance: Performance ) diff --git a/core/network/src/main/java/com/eshc/goonersapp/core/network/fake/FakeMatchDataSource.kt b/core/network/src/main/java/com/eshc/goonersapp/core/network/fake/FakeMatchDataSource.kt index 1ff4a05c..8a84595c 100644 --- a/core/network/src/main/java/com/eshc/goonersapp/core/network/fake/FakeMatchDataSource.kt +++ b/core/network/src/main/java/com/eshc/goonersapp/core/network/fake/FakeMatchDataSource.kt @@ -57,7 +57,6 @@ class FakeMatchDataSource @Inject constructor(): MatchNetworkDataSource { NetworkResult.Success( RemoteMatchInformation( notablePlayer = null, - lineUp = listOf(), performance = Performance() ) ) diff --git a/core/network/src/main/java/com/eshc/goonersapp/core/network/model/match/RemoteMatchInformation.kt b/core/network/src/main/java/com/eshc/goonersapp/core/network/model/match/RemoteMatchInformation.kt index 8da92a8d..d939da87 100644 --- a/core/network/src/main/java/com/eshc/goonersapp/core/network/model/match/RemoteMatchInformation.kt +++ b/core/network/src/main/java/com/eshc/goonersapp/core/network/model/match/RemoteMatchInformation.kt @@ -6,7 +6,6 @@ import kotlinx.serialization.Serializable @Serializable data class RemoteMatchInformation( @SerialName("notablePlayer") val notablePlayer: NotablePlayer? = null, - @SerialName("lineUp") val lineUp: List, @SerialName("performance") val performance: Performance ) From 30e95d6946f83a23228742fdd744c9ed27a0962d Mon Sep 17 00:00:00 2001 From: Jung SeokJoon Date: Thu, 23 May 2024 21:37:39 +0900 Subject: [PATCH 2/9] mod FakeMatchDataSourceTest - fakeGetMatchInformation --- .../goonersapp/core/network/FakeMatchDataSourceTest.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/network/src/test/java/com/eshc/goonersapp/core/network/FakeMatchDataSourceTest.kt b/core/network/src/test/java/com/eshc/goonersapp/core/network/FakeMatchDataSourceTest.kt index f1c878b5..3e690921 100644 --- a/core/network/src/test/java/com/eshc/goonersapp/core/network/FakeMatchDataSourceTest.kt +++ b/core/network/src/test/java/com/eshc/goonersapp/core/network/FakeMatchDataSourceTest.kt @@ -2,9 +2,9 @@ package com.eshc.goonersapp.core.network import com.eshc.goonersapp.core.network.fake.FakeMatchDataSource import com.eshc.goonersapp.core.network.model.NetworkResult -import com.eshc.goonersapp.core.network.model.match.LineUp -import com.eshc.goonersapp.core.network.model.match.RemoteMatchDetail +import com.eshc.goonersapp.core.network.model.match.Performance import com.eshc.goonersapp.core.network.model.match.RemoteMatch +import com.eshc.goonersapp.core.network.model.match.RemoteMatchDetail import kotlinx.coroutines.runBlocking import org.junit.Assert.assertEquals import org.junit.Before @@ -52,8 +52,8 @@ class FakeMatchDataSourceTest { when (result) { is NetworkResult.Success -> { assertEquals( - listOf(), - result.data.lineUp + Performance(), + result.data.performance ) } is NetworkResult.Error -> { From 9c3e5355f0626ec28a66111df924eaf318cfe7ae Mon Sep 17 00:00:00 2001 From: Jung SeokJoon Date: Thu, 23 May 2024 21:38:12 +0900 Subject: [PATCH 3/9] add MatchNetworkService - getMatchLineup --- .../core/network/api/MatchNetworkService.kt | 6 ++++ .../model/match/RemoteMatchInformation.kt | 16 ---------- .../network/model/match/RemoteMatchLineup.kt | 32 +++++++++++++++++++ 3 files changed, 38 insertions(+), 16 deletions(-) create mode 100644 core/network/src/main/java/com/eshc/goonersapp/core/network/model/match/RemoteMatchLineup.kt diff --git a/core/network/src/main/java/com/eshc/goonersapp/core/network/api/MatchNetworkService.kt b/core/network/src/main/java/com/eshc/goonersapp/core/network/api/MatchNetworkService.kt index 5ff24821..b93ee4af 100644 --- a/core/network/src/main/java/com/eshc/goonersapp/core/network/api/MatchNetworkService.kt +++ b/core/network/src/main/java/com/eshc/goonersapp/core/network/api/MatchNetworkService.kt @@ -4,6 +4,7 @@ import com.eshc.goonersapp.core.network.model.BaseResponse 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.match.RemoteMatchInformation +import com.eshc.goonersapp.core.network.model.match.RemoteMatchLineup import retrofit2.Response import retrofit2.http.GET import retrofit2.http.Path @@ -40,4 +41,9 @@ interface MatchNetworkService { suspend fun getRecentlyMatch( @Query("teamId") teamId : Int = 19 ) : Response> + + @GET(value = "$MATCH_BASE_URL/lineup") + suspend fun getMatchLineup( + @Query("matchId") matchId: Int + ) : Response> } \ No newline at end of file diff --git a/core/network/src/main/java/com/eshc/goonersapp/core/network/model/match/RemoteMatchInformation.kt b/core/network/src/main/java/com/eshc/goonersapp/core/network/model/match/RemoteMatchInformation.kt index d939da87..276c04bc 100644 --- a/core/network/src/main/java/com/eshc/goonersapp/core/network/model/match/RemoteMatchInformation.kt +++ b/core/network/src/main/java/com/eshc/goonersapp/core/network/model/match/RemoteMatchInformation.kt @@ -21,22 +21,6 @@ data class NotablePlayer( @SerialName("goal_count") val goalCount: Int ) -@Serializable -data class LineUp( - @SerialName("lineup_id") val lineUpId: Double = 0.0, - @SerialName("match_id") val matchId: Int = 0, - @SerialName("player_id") val playerId: Int = 0, - @SerialName("team_id") val teamId: Int = 0, - @SerialName("player_name") val playerName: String = "", - @SerialName("player_image_url") val playerImageUrl: String = "", - @SerialName("jersey_number") val jerseyNumber: Int = 0, - @SerialName("formation_field") val formationField: String? = "", - @SerialName("formation_position") val formationPosition: Int? = 0, - @SerialName("position_id") val positionId: Int = 0, - @SerialName("position_category") val positionCategory: String = "", - @SerialName("position_initial") val positionInitial: String = "" -) - @Serializable data class Performance( @SerialName("opponent_image_url") val opponentImage: String = "", diff --git a/core/network/src/main/java/com/eshc/goonersapp/core/network/model/match/RemoteMatchLineup.kt b/core/network/src/main/java/com/eshc/goonersapp/core/network/model/match/RemoteMatchLineup.kt new file mode 100644 index 00000000..eede53f1 --- /dev/null +++ b/core/network/src/main/java/com/eshc/goonersapp/core/network/model/match/RemoteMatchLineup.kt @@ -0,0 +1,32 @@ +package com.eshc.goonersapp.core.network.model.match + +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +data class RemoteMatchLineup( + @SerialName("home_lineup") val homeLineup : RemoteTeamLineup = RemoteTeamLineup(), + @SerialName("away_lineup") val awayLineup : RemoteTeamLineup = RemoteTeamLineup(), +) + +@Serializable +data class RemoteTeamLineup( + @SerialName("team_id") val teamId : Long = 0L, + @SerialName("formaition") val formation : String = "", + @SerialName("players") val players : List = emptyList() +) + +@Serializable +data class PlayerLineup( + @SerialName("lineup_id") val lineUpId: Long = 0L, + @SerialName("match_id") val matchId: Int = 0, + @SerialName("player_id") val playerId: Int = 0, + @SerialName("team_id") val teamId: Int = 0, + @SerialName("player_name") val playerName: String = "", + @SerialName("player_image_url") val playerImageUrl: String = "", + @SerialName("jersey_number") val jerseyNumber: Int = 0, + @SerialName("formation_field") val formationField: String? = "", + @SerialName("formation_position") val formationPosition: Int? = 0, + @SerialName("position_id") val positionId: Int = 0, + @SerialName("position_category") val positionCategory: String = "", + @SerialName("position_initial") val positionInitial: String = "" +) \ No newline at end of file From b7641a537d890373d6b77bb862af099190f211db Mon Sep 17 00:00:00 2001 From: Jung SeokJoon Date: Thu, 23 May 2024 21:41:47 +0900 Subject: [PATCH 4/9] mod RemoteMatchLineup --- .../goonersapp/core/network/model/match/RemoteMatchLineup.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/network/src/main/java/com/eshc/goonersapp/core/network/model/match/RemoteMatchLineup.kt b/core/network/src/main/java/com/eshc/goonersapp/core/network/model/match/RemoteMatchLineup.kt index eede53f1..554b9682 100644 --- a/core/network/src/main/java/com/eshc/goonersapp/core/network/model/match/RemoteMatchLineup.kt +++ b/core/network/src/main/java/com/eshc/goonersapp/core/network/model/match/RemoteMatchLineup.kt @@ -3,6 +3,7 @@ package com.eshc.goonersapp.core.network.model.match import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +@Serializable data class RemoteMatchLineup( @SerialName("home_lineup") val homeLineup : RemoteTeamLineup = RemoteTeamLineup(), @SerialName("away_lineup") val awayLineup : RemoteTeamLineup = RemoteTeamLineup(), @@ -11,7 +12,7 @@ data class RemoteMatchLineup( @Serializable data class RemoteTeamLineup( @SerialName("team_id") val teamId : Long = 0L, - @SerialName("formaition") val formation : String = "", + @SerialName("formation") val formation : String = "", @SerialName("players") val players : List = emptyList() ) From c4554f20acb1ebc70618e318b0a4b3b64168661f Mon Sep 17 00:00:00 2001 From: Jung SeokJoon Date: Thu, 23 May 2024 21:42:51 +0900 Subject: [PATCH 5/9] add test_GET_LINEUP_STATUS_IS_OK --- .../goonersapp/core/network/RemoteMatchApiTest.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/network/src/test/java/com/eshc/goonersapp/core/network/RemoteMatchApiTest.kt b/core/network/src/test/java/com/eshc/goonersapp/core/network/RemoteMatchApiTest.kt index c525ad49..24d0ca50 100644 --- a/core/network/src/test/java/com/eshc/goonersapp/core/network/RemoteMatchApiTest.kt +++ b/core/network/src/test/java/com/eshc/goonersapp/core/network/RemoteMatchApiTest.kt @@ -117,4 +117,16 @@ class RemoteMatchApiTest { val response = matchApi.getRecentlyMatch() assertEquals(responseOkCode, response.code()) } + + /** + * (Test Passed) + * + * Match Lineup network communication test + * - when response code is 200, Test Passed + */ + @Test + fun test_GET_LINEUP_STATUS_IS_OK() = runBlocking { + val response = matchApi.getMatchLineup(18138603) + assertEquals(responseOkCode, response.code()) + } } \ No newline at end of file From 6bdb11e669b4a821f29444f96cce5bfd3151c3c7 Mon Sep 17 00:00:00 2001 From: Jung SeokJoon Date: Thu, 23 May 2024 21:48:31 +0900 Subject: [PATCH 6/9] add getMatchLineup in DataSource & FakeDataSource & Test --- .../core/network/MatchNetworkDataSource.kt | 3 +++ .../core/network/fake/FakeMatchDataSource.kt | 18 ++++++++++++++++++ .../remote/MatchNetworkDataSourceImpl.kt | 7 +++++++ .../core/network/FakeMatchDataSourceTest.kt | 16 ++++++++++++++++ 4 files changed, 44 insertions(+) diff --git a/core/network/src/main/java/com/eshc/goonersapp/core/network/MatchNetworkDataSource.kt b/core/network/src/main/java/com/eshc/goonersapp/core/network/MatchNetworkDataSource.kt index 2ccbb9df..c189d6f0 100644 --- a/core/network/src/main/java/com/eshc/goonersapp/core/network/MatchNetworkDataSource.kt +++ b/core/network/src/main/java/com/eshc/goonersapp/core/network/MatchNetworkDataSource.kt @@ -4,6 +4,7 @@ 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.match.RemoteMatchInformation +import com.eshc.goonersapp.core.network.model.match.RemoteMatchLineup interface MatchNetworkDataSource { @@ -20,4 +21,6 @@ interface MatchNetworkDataSource { suspend fun getUpcomingMatches(): NetworkResult> suspend fun getRecentlyMatch(): NetworkResult + + suspend fun getMatchLineup(matchId: Int) : NetworkResult } \ No newline at end of file diff --git a/core/network/src/main/java/com/eshc/goonersapp/core/network/fake/FakeMatchDataSource.kt b/core/network/src/main/java/com/eshc/goonersapp/core/network/fake/FakeMatchDataSource.kt index 8a84595c..29a88cbd 100644 --- a/core/network/src/main/java/com/eshc/goonersapp/core/network/fake/FakeMatchDataSource.kt +++ b/core/network/src/main/java/com/eshc/goonersapp/core/network/fake/FakeMatchDataSource.kt @@ -6,6 +6,8 @@ import com.eshc.goonersapp.core.network.model.match.Performance 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.match.RemoteMatchInformation +import com.eshc.goonersapp.core.network.model.match.RemoteMatchLineup +import com.eshc.goonersapp.core.network.model.match.RemoteTeamLineup import javax.inject.Inject /** @@ -31,6 +33,10 @@ import javax.inject.Inject * * getRecentlyMatch() * - return [NetworkResult.Success] + * + * getMatchLineup(matchId: Int) + * - if matchId is over 39 then return [NetworkResult.Error] + * - else return [NetworkResult.Success] */ class FakeMatchDataSource @Inject constructor(): MatchNetworkDataSource { override suspend fun getMatch(matchId: Int): NetworkResult { @@ -88,4 +94,16 @@ class FakeMatchDataSource @Inject constructor(): MatchNetworkDataSource { ) } + override suspend fun getMatchLineup(matchId: Int): NetworkResult { + return if (matchId < 39) { + NetworkResult.Success( + RemoteMatchLineup( + homeLineup = RemoteTeamLineup(), + awayLineup = RemoteTeamLineup() + ) + ) + } else { + NetworkResult.Error(code = 404, message = "Not Found") + } + } } \ No newline at end of file diff --git a/core/network/src/main/java/com/eshc/goonersapp/core/network/remote/MatchNetworkDataSourceImpl.kt b/core/network/src/main/java/com/eshc/goonersapp/core/network/remote/MatchNetworkDataSourceImpl.kt index 56adf276..18897080 100644 --- a/core/network/src/main/java/com/eshc/goonersapp/core/network/remote/MatchNetworkDataSourceImpl.kt +++ b/core/network/src/main/java/com/eshc/goonersapp/core/network/remote/MatchNetworkDataSourceImpl.kt @@ -7,6 +7,7 @@ import com.eshc.goonersapp.core.network.model.handleApi 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.match.RemoteMatchInformation +import com.eshc.goonersapp.core.network.model.match.RemoteMatchLineup import javax.inject.Inject import javax.inject.Singleton @@ -51,4 +52,10 @@ class MatchNetworkDataSourceImpl @Inject constructor( matchNetworkService.getRecentlyMatch() } } + + override suspend fun getMatchLineup(matchId: Int): NetworkResult { + return handleApi { + matchNetworkService.getMatchLineup(matchId) + } + } } diff --git a/core/network/src/test/java/com/eshc/goonersapp/core/network/FakeMatchDataSourceTest.kt b/core/network/src/test/java/com/eshc/goonersapp/core/network/FakeMatchDataSourceTest.kt index 3e690921..0d66131a 100644 --- a/core/network/src/test/java/com/eshc/goonersapp/core/network/FakeMatchDataSourceTest.kt +++ b/core/network/src/test/java/com/eshc/goonersapp/core/network/FakeMatchDataSourceTest.kt @@ -5,6 +5,7 @@ import com.eshc.goonersapp.core.network.model.NetworkResult import com.eshc.goonersapp.core.network.model.match.Performance import com.eshc.goonersapp.core.network.model.match.RemoteMatch import com.eshc.goonersapp.core.network.model.match.RemoteMatchDetail +import com.eshc.goonersapp.core.network.model.match.RemoteMatchLineup import kotlinx.coroutines.runBlocking import org.junit.Assert.assertEquals import org.junit.Before @@ -113,4 +114,19 @@ class FakeMatchDataSourceTest { } } + + @Test + fun fakeGetMatchLineup() = runBlocking { + when (val result = fakeMatchDataSource.getMatchLineup(38)) { + is NetworkResult.Success -> { + assertEquals( + RemoteMatchLineup(), + result.data + ) + } + is NetworkResult.Error -> { /* Nothing */ } + is NetworkResult.Exception -> { /* Nothing */ } + } + + } } \ No newline at end of file From 39814ac17248076c4a5cfc711b6937695f414cb1 Mon Sep 17 00:00:00 2001 From: Jung SeokJoon Date: Thu, 23 May 2024 22:03:13 +0900 Subject: [PATCH 7/9] add RemoteMatchLineup Mapper & MatchLineup --- .../core/data/mapper/MatchMapper.kt | 39 ++++++++++++++++++- .../domain/model/match/MatchInformation.kt | 14 ------- .../core/domain/model/match/MatchLineup.kt | 27 +++++++++++++ .../network/model/match/RemoteMatchLineup.kt | 4 +- 4 files changed, 66 insertions(+), 18 deletions(-) create mode 100644 core/domain/src/main/java/com/eshc/goonersapp/core/domain/model/match/MatchLineup.kt diff --git a/core/data/src/main/java/com/eshc/goonersapp/core/data/mapper/MatchMapper.kt b/core/data/src/main/java/com/eshc/goonersapp/core/data/mapper/MatchMapper.kt index a3fefcb5..d852de59 100644 --- a/core/data/src/main/java/com/eshc/goonersapp/core/data/mapper/MatchMapper.kt +++ b/core/data/src/main/java/com/eshc/goonersapp/core/data/mapper/MatchMapper.kt @@ -1,17 +1,22 @@ package com.eshc.goonersapp.core.data.mapper -import com.eshc.goonersapp.core.domain.model.match.LineUp +import com.eshc.goonersapp.core.domain.model.match.PlayerLineup import com.eshc.goonersapp.core.domain.model.match.Match import com.eshc.goonersapp.core.domain.model.match.MatchData import com.eshc.goonersapp.core.domain.model.match.MatchDetail import com.eshc.goonersapp.core.domain.model.match.MatchInformation +import com.eshc.goonersapp.core.domain.model.match.MatchLineup import com.eshc.goonersapp.core.domain.model.match.NotablePlayer import com.eshc.goonersapp.core.domain.model.match.Performance +import com.eshc.goonersapp.core.domain.model.match.TeamLineup import com.eshc.goonersapp.core.domain.model.match.toMatchDetailType 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.match.RemoteMatchDetail import com.eshc.goonersapp.core.network.model.match.RemoteMatchInformation +import com.eshc.goonersapp.core.network.model.match.RemoteMatchLineup +import com.eshc.goonersapp.core.network.model.match.RemotePlayerLineup +import com.eshc.goonersapp.core.network.model.match.RemoteTeamLineup /** * [RemoteMatch] Mapper @@ -86,4 +91,34 @@ fun RemoteMatchDetail.toModel() = MatchDetail( fun RemoteMatchData.toModel() = MatchData( match = match.toModel(), matchDetail = matchDetail.map { remote -> remote.toModel() } -) \ No newline at end of file +) + +/** + * [RemoteMatchLineup] Mapper + * - Mapper [RemoteMatchLineup] to [MatchLineup] + */ +fun RemoteMatchLineup.toModel() = MatchLineup( + homeLineup = homeLineup.toModel(), + awayLineup = awayLineup.toModel() +) + +fun RemoteTeamLineup.toModel() = TeamLineup( + teamId = teamId.toInt(), + formation = formation, + playerLineup = players.map { remote -> remote.toModel() } +) + +fun RemotePlayerLineup.toModel() = PlayerLineup( + lineUpId = lineUpId, + matchId = matchId, + playerId = playerId, + teamId = teamId, + playerName = playerName, + playerImageUrl = playerImageUrl, + playerBackNumber = jerseyNumber, + formationField = formationField, + formationPosition = formationPosition, + positionId = positionId, + positionCategory = positionCategory, + positionInitial = positionInitial +) diff --git a/core/domain/src/main/java/com/eshc/goonersapp/core/domain/model/match/MatchInformation.kt b/core/domain/src/main/java/com/eshc/goonersapp/core/domain/model/match/MatchInformation.kt index 165dbec0..25867754 100644 --- a/core/domain/src/main/java/com/eshc/goonersapp/core/domain/model/match/MatchInformation.kt +++ b/core/domain/src/main/java/com/eshc/goonersapp/core/domain/model/match/MatchInformation.kt @@ -16,20 +16,6 @@ data class NotablePlayer( val playerGoalCount: Int ) -data class LineUp( - val lineUpId: Double, - val matchId: Int, - val playerId: Int, - val teamId: Int, - val playerName: String, - val playerBackNumber: Int, - val formationField: String?, - val formationPosition: Int?, - val positionId: Int, - val positionCategory: String, - val positionInitial: String -) - data class Performance( val opponentImageUrl: String, val win: Int, diff --git a/core/domain/src/main/java/com/eshc/goonersapp/core/domain/model/match/MatchLineup.kt b/core/domain/src/main/java/com/eshc/goonersapp/core/domain/model/match/MatchLineup.kt new file mode 100644 index 00000000..5819fcca --- /dev/null +++ b/core/domain/src/main/java/com/eshc/goonersapp/core/domain/model/match/MatchLineup.kt @@ -0,0 +1,27 @@ +package com.eshc.goonersapp.core.domain.model.match + +data class MatchLineup( + val homeLineup : TeamLineup, + val awayLineup : TeamLineup +) + +data class TeamLineup( + val teamId : Int, + val formation : String, + val playerLineup : List +) + +data class PlayerLineup( + val lineUpId: Long, + val matchId: Int, + val playerId: Int, + val teamId: Int, + val playerName: String, + val playerImageUrl : String, + val playerBackNumber: Int, + val formationField: String?, + val formationPosition: Int?, + val positionId: Int, + val positionCategory: String, + val positionInitial: String +) \ No newline at end of file diff --git a/core/network/src/main/java/com/eshc/goonersapp/core/network/model/match/RemoteMatchLineup.kt b/core/network/src/main/java/com/eshc/goonersapp/core/network/model/match/RemoteMatchLineup.kt index 554b9682..87e6680d 100644 --- a/core/network/src/main/java/com/eshc/goonersapp/core/network/model/match/RemoteMatchLineup.kt +++ b/core/network/src/main/java/com/eshc/goonersapp/core/network/model/match/RemoteMatchLineup.kt @@ -13,11 +13,11 @@ data class RemoteMatchLineup( data class RemoteTeamLineup( @SerialName("team_id") val teamId : Long = 0L, @SerialName("formation") val formation : String = "", - @SerialName("players") val players : List = emptyList() + @SerialName("players") val players : List = emptyList() ) @Serializable -data class PlayerLineup( +data class RemotePlayerLineup( @SerialName("lineup_id") val lineUpId: Long = 0L, @SerialName("match_id") val matchId: Int = 0, @SerialName("player_id") val playerId: Int = 0, From 0f7b097eb516b92caa21d82f4deb9fc99f9469f9 Mon Sep 17 00:00:00 2001 From: Jung SeokJoon Date: Thu, 23 May 2024 22:03:38 +0900 Subject: [PATCH 8/9] add getMatchLineup in Repository & Fake Repository & Test --- .../core/data/fake/FakeMatchRepositoryImpl.kt | 9 ++++++ .../data/repository/MatchRepositoryImpl.kt | 9 ++++++ .../goonersapp/core/data/FakeMatchTest.kt | 29 ++++++++++++++++++- .../core/domain/repository/MatchRepository.kt | 2 ++ 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/core/data/src/main/java/com/eshc/goonersapp/core/data/fake/FakeMatchRepositoryImpl.kt b/core/data/src/main/java/com/eshc/goonersapp/core/data/fake/FakeMatchRepositoryImpl.kt index 1f0930a1..7da05adb 100644 --- a/core/data/src/main/java/com/eshc/goonersapp/core/data/fake/FakeMatchRepositoryImpl.kt +++ b/core/data/src/main/java/com/eshc/goonersapp/core/data/fake/FakeMatchRepositoryImpl.kt @@ -6,6 +6,7 @@ import com.eshc.goonersapp.core.domain.model.DataResult import com.eshc.goonersapp.core.domain.model.match.Match import com.eshc.goonersapp.core.domain.model.match.MatchData import com.eshc.goonersapp.core.domain.model.match.MatchInformation +import com.eshc.goonersapp.core.domain.model.match.MatchLineup import com.eshc.goonersapp.core.domain.repository.MatchRepository import com.eshc.goonersapp.core.network.fake.FakeMatchDataSource import kotlinx.coroutines.flow.Flow @@ -63,4 +64,12 @@ class FakeMatchRepositoryImpl @Inject constructor( emit(result) } + override fun getMatchLineup(matchId: Int): Flow> = flow { + val result = fakeMatchDataSource + .getMatchLineup(matchId) + .toDataResult { remote -> remote.toModel() } + + emit(result) + } + } \ No newline at end of file diff --git a/core/data/src/main/java/com/eshc/goonersapp/core/data/repository/MatchRepositoryImpl.kt b/core/data/src/main/java/com/eshc/goonersapp/core/data/repository/MatchRepositoryImpl.kt index 6a1bc887..a867ea9b 100644 --- a/core/data/src/main/java/com/eshc/goonersapp/core/data/repository/MatchRepositoryImpl.kt +++ b/core/data/src/main/java/com/eshc/goonersapp/core/data/repository/MatchRepositoryImpl.kt @@ -6,6 +6,7 @@ import com.eshc.goonersapp.core.domain.model.DataResult import com.eshc.goonersapp.core.domain.model.match.Match import com.eshc.goonersapp.core.domain.model.match.MatchData import com.eshc.goonersapp.core.domain.model.match.MatchInformation +import com.eshc.goonersapp.core.domain.model.match.MatchLineup import com.eshc.goonersapp.core.domain.repository.MatchRepository import com.eshc.goonersapp.core.network.MatchNetworkDataSource import kotlinx.coroutines.flow.Flow @@ -59,4 +60,12 @@ class MatchRepositoryImpl @Inject constructor( emit(result) } + + override fun getMatchLineup(matchId: Int): Flow> = flow { + val result = matchNetworkDataSource + .getMatchLineup(matchId) + .toDataResult { remote -> remote.toModel() } + + emit(result) + } } \ No newline at end of file diff --git a/core/data/src/test/java/com/eshc/goonersapp/core/data/FakeMatchTest.kt b/core/data/src/test/java/com/eshc/goonersapp/core/data/FakeMatchTest.kt index 8907f530..69aec972 100644 --- a/core/data/src/test/java/com/eshc/goonersapp/core/data/FakeMatchTest.kt +++ b/core/data/src/test/java/com/eshc/goonersapp/core/data/FakeMatchTest.kt @@ -5,7 +5,9 @@ import com.eshc.goonersapp.core.domain.model.DataResult import com.eshc.goonersapp.core.domain.model.match.Match import com.eshc.goonersapp.core.domain.model.match.MatchData import com.eshc.goonersapp.core.domain.model.match.MatchInformation +import com.eshc.goonersapp.core.domain.model.match.MatchLineup import com.eshc.goonersapp.core.domain.model.match.Performance +import com.eshc.goonersapp.core.domain.model.match.TeamLineup import com.eshc.goonersapp.core.domain.repository.MatchRepository import com.eshc.goonersapp.core.network.fake.FakeMatchDataSource import kotlinx.coroutines.runBlocking @@ -62,7 +64,6 @@ class FakeMatchTest { assertEquals( MatchInformation( notablePlayer = null, - lineUp = listOf(), performance = Performance(opponentImageUrl = "", win = 0, draw = 0, lose = 0) ), result.data @@ -110,4 +111,30 @@ class FakeMatchTest { } } } + + @Test + fun testMatchLineupWithFake() = runBlocking { + fakeMatchRepository.getMatchLineup(38).collect { result -> + when (result) { + is DataResult.Success -> { + assertEquals( + MatchLineup( + homeLineup = TeamLineup( + teamId = 0, + formation = "", + playerLineup = emptyList() + ), + awayLineup = TeamLineup( + teamId = 0, + formation = "", + playerLineup = emptyList() + ) + ), + result.data + ) + } + is DataResult.Failure -> { /* Nothing */ } + } + } + } } \ No newline at end of file diff --git a/core/domain/src/main/java/com/eshc/goonersapp/core/domain/repository/MatchRepository.kt b/core/domain/src/main/java/com/eshc/goonersapp/core/domain/repository/MatchRepository.kt index bb41a976..e624246b 100644 --- a/core/domain/src/main/java/com/eshc/goonersapp/core/domain/repository/MatchRepository.kt +++ b/core/domain/src/main/java/com/eshc/goonersapp/core/domain/repository/MatchRepository.kt @@ -4,6 +4,7 @@ import com.eshc.goonersapp.core.domain.model.DataResult import com.eshc.goonersapp.core.domain.model.match.Match import com.eshc.goonersapp.core.domain.model.match.MatchData import com.eshc.goonersapp.core.domain.model.match.MatchInformation +import com.eshc.goonersapp.core.domain.model.match.MatchLineup import kotlinx.coroutines.flow.Flow interface MatchRepository { @@ -18,4 +19,5 @@ interface MatchRepository { fun getRecentlyMatch() : Flow> + fun getMatchLineup(matchId: Int) : Flow> } \ No newline at end of file From 31679379d97bd0b4dceb20b1ff7605b2799d953f Mon Sep 17 00:00:00 2001 From: Jung SeokJoon Date: Thu, 23 May 2024 22:07:38 +0900 Subject: [PATCH 9/9] add GetMatchLineupUseCase --- .../usecase/match/GetMatchLineupUseCase.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 core/domain/src/main/java/com/eshc/goonersapp/core/domain/usecase/match/GetMatchLineupUseCase.kt diff --git a/core/domain/src/main/java/com/eshc/goonersapp/core/domain/usecase/match/GetMatchLineupUseCase.kt b/core/domain/src/main/java/com/eshc/goonersapp/core/domain/usecase/match/GetMatchLineupUseCase.kt new file mode 100644 index 00000000..75f7adf4 --- /dev/null +++ b/core/domain/src/main/java/com/eshc/goonersapp/core/domain/usecase/match/GetMatchLineupUseCase.kt @@ -0,0 +1,17 @@ +package com.eshc.goonersapp.core.domain.usecase.match + +import com.eshc.goonersapp.core.domain.model.DataResult +import com.eshc.goonersapp.core.domain.model.match.MatchLineup +import com.eshc.goonersapp.core.domain.repository.MatchRepository +import kotlinx.coroutines.flow.Flow +import javax.inject.Inject + +class GetMatchLineupUseCase @Inject constructor( + private val matchRepository: MatchRepository +) { + operator fun invoke( + matchId: Int, + ): Flow> = matchRepository.getMatchLineup( + matchId + ) +} \ No newline at end of file