Skip to content

Commit

Permalink
Merge pull request #39 from stslex/dev
Browse files Browse the repository at this point in the history
Refactor match models
  • Loading branch information
stslex authored May 2, 2024
2 parents 7b515a4 + 4e5ccf6 commit bb9aa04
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class MockMatchClientImpl : MatchClient {
description = it.description,
status = it.status,
participants = it.participants,
isCreator = it.isCreator,
creatorUuid = "creatorUuid",
coverUrl = "coverUrl",
expiresAt = it.expiresAt
)
},
Expand Down Expand Up @@ -70,10 +71,11 @@ class MockMatchClientImpl : MatchClient {
description = "description$index",
status = if (index % 2 == 0) MatchStatusResponse.PENDING else MatchStatusResponse.ACTIVE,
participants = createMatchUsers(index),
isCreator = index % 2 == 0,
creatorUuid = "creatorUuid",
createdAt = created,
updatedAt = updated,
expiresAt = expires,
coverUrl = "coverUrl"
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ data class MatchCreateRequest(
val expiresAt: String,
@SerialName("participants_uuid")
val participantsUuid: List<String>,
@SerialName("cover_url")
val coverUrl: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ data class MatchDetailResponse(
val status: MatchStatusResponse = MatchStatusResponse.PENDING,
@SerialName("participants")
val participants: List<MatchUserResponse>,
@SerialName("is_creator")
val isCreator: Boolean,
@SerialName("creator_uuid")
val creatorUuid: String,
@SerialName("created_at")
val createdAt: Long,
@SerialName("updated_at")
val updatedAt: Long,
@SerialName("expires_at")
val expiresAt: Long,
@SerialName("cover_url")
val coverUrl: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ data class MatchResponse(
val description: String,
@SerialName("status")
val status: MatchStatusResponse,
@SerialName("creator_uuid")
val creatorUuid: String,
@SerialName("participants")
val participants: List<MatchUserResponse>,
@SerialName("is_creator")
val isCreator: Boolean,
@SerialName("expires_at")
val expiresAt: Long,
@SerialName("cover_url")
val coverUrl: String,
) : PagingCoreItem
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import com.stslex.core.network.clients.match.model.response.MatchResponse
import com.stslex.core.network.clients.match.model.response.MatchStatusResponse
import com.stslex.core.network.clients.match.model.response.MatchUserResponse

internal suspend fun MatchResponse.toData() = MatchDataModel(
internal suspend fun MatchResponse.toData(
userUUID: String
) = MatchDataModel(
uuid = uuid,
title = title,
description = description,
status = status.toData(),
participants = participants.asyncMap { it.toData() },
isCreator = isCreator,
isCreator = userUUID == creatorUuid,
expiresAt = expiresAt,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ package com.stslex.feature.match.data.repository

import com.stslex.core.core.paging.PagingResponse
import com.stslex.core.core.paging.pagingMap
import com.stslex.core.database.store.UserStore
import com.stslex.core.network.clients.match.client.MatchClient
import com.stslex.core.network.model.PagingRequest
import com.stslex.feature.match.data.model.MatchDataModel
import com.stslex.feature.match.data.model.toData

class MatchRepositoryImpl(
private val client: MatchClient
private val client: MatchClient,
private val userStore: UserStore
) : MatchRepository {

override suspend fun getMatches(
Expand All @@ -25,5 +27,7 @@ class MatchRepositoryImpl(
query = query
)
)
.pagingMap { it.toData() }
.pagingMap {
it.toData(userUUID = userStore.uuid)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import com.stslex.feature.match.ui.store.MatchStoreImpl
import org.koin.dsl.module

val featureMatchModule = module {
factory<MatchRepository> { MatchRepositoryImpl(client = get()) }
factory<MatchRepository> {
MatchRepositoryImpl(
client = get(),
userStore = get()
)
}
factory<MatchInteractor> {
MatchInteractorImpl(
repository = get(),
Expand Down

0 comments on commit bb9aa04

Please sign in to comment.