-
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 #277 from 6QuizOnTheBlock/and/feat#275-student_rel…
…ay_main And/feat#275 학생 릴레이 메인화면 기능
- Loading branch information
Showing
16 changed files
with
322 additions
and
7 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
24 changes: 24 additions & 0 deletions
24
android/data/src/main/java/com/sixkids/data/api/RelayService.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,24 @@ | ||
package com.sixkids.data.api | ||
|
||
import com.sixkids.data.model.response.RelayHistoryResponse | ||
import com.sixkids.data.model.response.RunningRelayResponse | ||
import com.sixkids.data.network.ApiResponse | ||
import com.sixkids.data.network.ApiResult | ||
import retrofit2.http.GET | ||
import retrofit2.http.Query | ||
|
||
interface RelayService { | ||
|
||
@GET("relays") | ||
suspend fun getRelayHistory( | ||
@Query("orgId") organizationId: Int, | ||
@Query("memberId") memberId: Int? = null, | ||
@Query("page") page: Int, | ||
@Query("size") size: Int, | ||
): ApiResult<ApiResponse<RelayHistoryResponse>> | ||
|
||
@GET("relays/running") | ||
suspend fun getRunningRelay( | ||
@Query("organizationId") organizationId: Long | ||
): ApiResult<ApiResponse<RunningRelayResponse>> | ||
} |
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
27 changes: 27 additions & 0 deletions
27
android/data/src/main/java/com/sixkids/data/model/response/RelayHistoryResponse.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,27 @@ | ||
package com.sixkids.data.model.response | ||
|
||
import com.sixkids.model.Relay | ||
import java.time.LocalDateTime | ||
|
||
data class RelayHistoryResponse( | ||
val page: Int, | ||
val size: Int, | ||
val last: Boolean, | ||
val relays: List<RelayResponse> | ||
) | ||
|
||
data class RelayResponse( | ||
val id : Long, | ||
val startTime : LocalDateTime = LocalDateTime.now(), | ||
val endTime : LocalDateTime = LocalDateTime.now(), | ||
val lastTurn : Int, | ||
val lastMemberName : String | ||
) | ||
|
||
internal fun RelayResponse.toModel() = Relay( | ||
id = id, | ||
startTime = startTime, | ||
endTime = endTime, | ||
lastTurn = lastTurn, | ||
lastMemberName = lastMemberName | ||
) |
22 changes: 22 additions & 0 deletions
22
android/data/src/main/java/com/sixkids/data/model/response/RunningRelayResponse.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,22 @@ | ||
package com.sixkids.data.model.response | ||
|
||
import com.sixkids.model.RunningRelay | ||
import java.time.LocalDateTime | ||
|
||
data class RunningRelayResponse( | ||
val id: Long, | ||
val startTime: LocalDateTime = LocalDateTime.now(), | ||
val currentMemberName : String, | ||
val currentTurn : Int, | ||
val totalTurn : Int, | ||
val myTurnStatus : Boolean | ||
) | ||
|
||
internal fun RunningRelayResponse.toModel() = RunningRelay( | ||
id = id, | ||
startTime = startTime, | ||
curMemberNickname = currentMemberName, | ||
doneMemberCount = currentTurn, | ||
totalMemberCount = totalTurn, | ||
myTurnStatus = myTurnStatus | ||
) |
38 changes: 38 additions & 0 deletions
38
android/data/src/main/java/com/sixkids/data/repository/relay/RelayRepositoryImpl.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,38 @@ | ||
package com.sixkids.data.repository.relay | ||
|
||
import androidx.paging.Pager | ||
import androidx.paging.PagingConfig | ||
import androidx.paging.PagingData | ||
import com.sixkids.data.api.RelayService | ||
import com.sixkids.data.repository.relay.remote.RelayHistoryPagingSource | ||
import com.sixkids.data.repository.relay.remote.RelayRemoteDataSource | ||
import com.sixkids.domain.repository.RelayRepository | ||
import com.sixkids.model.Relay | ||
import com.sixkids.model.RunningRelay | ||
import kotlinx.coroutines.flow.Flow | ||
import javax.inject.Inject | ||
|
||
class RelayRepositoryImpl @Inject constructor( | ||
private val relayService: RelayService, | ||
private val relayRemoteDataSource: RelayRemoteDataSource | ||
) : RelayRepository{ | ||
|
||
override suspend fun getRelayHistory( | ||
organizationId: Int, | ||
memberId: Int?, | ||
): Flow<PagingData<Relay>> = | ||
Pager( | ||
config = PagingConfig(RelayHistoryPagingSource.DEFAULT_SIZE), | ||
pagingSourceFactory = { | ||
RelayHistoryPagingSource( | ||
relayService, | ||
organizationId, | ||
memberId, | ||
) | ||
} | ||
).flow | ||
|
||
override suspend fun getRunningRelay(organizationId: Long): RunningRelay { | ||
return relayRemoteDataSource.getRunningRelay(organizationId) | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...d/data/src/main/java/com/sixkids/data/repository/relay/remote/RelayHistoryPagingSource.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 com.sixkids.data.repository.relay.remote | ||
|
||
import androidx.paging.PagingSource | ||
import androidx.paging.PagingState | ||
import com.sixkids.data.api.RelayService | ||
import com.sixkids.data.model.response.toModel | ||
import com.sixkids.model.Relay | ||
import javax.inject.Inject | ||
|
||
class RelayHistoryPagingSource @Inject constructor( | ||
private val relayService: RelayService, | ||
private val organizationId: Int, | ||
private val memberId: Int? = null, | ||
) : PagingSource<Int, Relay>() { | ||
override fun getRefreshKey(state: PagingState<Int, Relay>): Int? { | ||
return state.anchorPosition?.let { anchorPosition -> | ||
state.closestPageToPosition(anchorPosition)?.prevKey?.plus(1) | ||
?: state.closestPageToPosition(anchorPosition)?.nextKey?.minus(1) | ||
} | ||
} | ||
|
||
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, Relay> { | ||
val page = params.key ?: 0 | ||
return try { | ||
|
||
val response = relayService.getRelayHistory( | ||
organizationId, | ||
memberId, | ||
page, | ||
DEFAULT_SIZE | ||
) | ||
val challengeHistory = response.getOrThrow().data.relays.map { it.toModel() } | ||
|
||
LoadResult.Page( | ||
data = challengeHistory, | ||
prevKey = if (page == 0) null else page.minus(1), | ||
nextKey = if (challengeHistory.isEmpty()) null else page.plus(1) | ||
) | ||
} catch (e: Exception) { | ||
LoadResult.Error(e) | ||
} | ||
} | ||
|
||
companion object { | ||
const val DEFAULT_SIZE = 10 | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
android/data/src/main/java/com/sixkids/data/repository/relay/remote/RelayRemoteDataSource.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,7 @@ | ||
package com.sixkids.data.repository.relay.remote | ||
|
||
import com.sixkids.model.RunningRelay | ||
|
||
interface RelayRemoteDataSource { | ||
suspend fun getRunningRelay(organizationId: Long) : RunningRelay | ||
} |
14 changes: 14 additions & 0 deletions
14
.../data/src/main/java/com/sixkids/data/repository/relay/remote/RelayRemoteDataSourceImpl.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 com.sixkids.data.repository.relay.remote | ||
|
||
import com.sixkids.data.api.RelayService | ||
import com.sixkids.data.model.response.toModel | ||
import com.sixkids.model.RunningRelay | ||
import javax.inject.Inject | ||
|
||
class RelayRemoteDataSourceImpl @Inject constructor( | ||
private val relayService: RelayService | ||
) : RelayRemoteDataSource{ | ||
override suspend fun getRunningRelay(organizationId: Long) : RunningRelay = | ||
relayService.getRunningRelay(organizationId).getOrThrow().data.toModel() | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
android/domain/src/main/java/com/sixkids/domain/repository/RelayRepository.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 com.sixkids.domain.repository | ||
|
||
import androidx.paging.PagingData | ||
import com.sixkids.model.Relay | ||
import com.sixkids.model.RunningRelay | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
interface RelayRepository { | ||
suspend fun getRelayHistory( | ||
organizationId: Int, | ||
memberId: Int? | ||
): Flow<PagingData<Relay>> | ||
|
||
suspend fun getRunningRelay(organizationId: Long): RunningRelay | ||
} |
14 changes: 14 additions & 0 deletions
14
android/domain/src/main/java/com/sixkids/domain/usecase/relay/GetRelayHistoryUseCase.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 com.sixkids.domain.usecase.relay | ||
|
||
import com.sixkids.domain.repository.RelayRepository | ||
import javax.inject.Inject | ||
|
||
class GetRelayHistoryUseCase @Inject constructor( | ||
private val relayRepository: RelayRepository) | ||
{ | ||
|
||
suspend operator fun invoke( | ||
organizationId: Int, | ||
memberId: Int? = null | ||
) = relayRepository.getRelayHistory(organizationId, memberId) | ||
} |
12 changes: 12 additions & 0 deletions
12
android/domain/src/main/java/com/sixkids/domain/usecase/relay/GetRunningRelayUseCase.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,12 @@ | ||
package com.sixkids.domain.usecase.relay | ||
|
||
import com.sixkids.domain.repository.RelayRepository | ||
import javax.inject.Inject | ||
|
||
class GetRunningRelayUseCase @Inject constructor( | ||
private val relayRepository: RelayRepository | ||
){ | ||
suspend operator fun invoke(organizationId: Long) = runCatching { | ||
relayRepository.getRunningRelay(organizationId) | ||
} | ||
} |
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
Oops, something went wrong.