-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feature:#127 거래 내역 화면 구현
- Loading branch information
Showing
30 changed files
with
611 additions
and
20 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
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
17 changes: 17 additions & 0 deletions
17
data/src/main/java/com/gta/data/repository/TransactionRepositoryImpl.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,17 @@ | ||
package com.gta.data.repository | ||
|
||
import com.gta.data.source.TransactionDataSource | ||
import com.gta.domain.model.SimpleReservation | ||
import com.gta.domain.repository.TransactionRepository | ||
import kotlinx.coroutines.flow.first | ||
import javax.inject.Inject | ||
|
||
class TransactionRepositoryImpl @Inject constructor(private val transactionDataSource: TransactionDataSource) : TransactionRepository { | ||
override suspend fun getYourCarTransactions(uid: String): List<SimpleReservation> { | ||
return transactionDataSource.getYourCarTransactions(uid).first() | ||
} | ||
|
||
override suspend fun getMyCarTransactions(uid: String): List<SimpleReservation> { | ||
return transactionDataSource.getMyCarTransactions(uid).first() | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
data/src/main/java/com/gta/data/source/TransactionDataSource.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,43 @@ | ||
package com.gta.data.source | ||
|
||
import com.google.firebase.firestore.FirebaseFirestore | ||
import com.gta.domain.model.Reservation | ||
import com.gta.domain.model.SimpleReservation | ||
import com.gta.domain.model.toSimpleReservation | ||
import kotlinx.coroutines.channels.awaitClose | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.callbackFlow | ||
import javax.inject.Inject | ||
|
||
class TransactionDataSource @Inject constructor(private val fireStore: FirebaseFirestore) { | ||
|
||
fun getYourCarTransactions(uid: String): Flow<List<SimpleReservation>> = callbackFlow { | ||
fireStore.collection("reservations").whereEqualTo("lenderId", uid).get().addOnCompleteListener { | ||
if (it.isSuccessful) { | ||
it.result.map { snapshot -> | ||
snapshot.toObject(Reservation::class.java).toSimpleReservation(snapshot.id) | ||
}.also { result -> | ||
trySend(result) | ||
} | ||
} else { | ||
trySend(emptyList()) | ||
} | ||
} | ||
awaitClose() | ||
} | ||
|
||
fun getMyCarTransactions(uid: String): Flow<List<SimpleReservation>> = callbackFlow { | ||
fireStore.collection("reservations").whereEqualTo("ownerId", uid).get().addOnCompleteListener { | ||
if (it.isSuccessful) { | ||
it.result.map { snapshot -> | ||
snapshot.toObject(Reservation::class.java).toSimpleReservation(snapshot.id) | ||
}.also { result -> | ||
trySend(result) | ||
} | ||
} else { | ||
trySend(emptyList()) | ||
} | ||
} | ||
awaitClose() | ||
} | ||
} |
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
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,9 @@ | ||
package com.gta.domain.model | ||
|
||
data class Transaction( | ||
val reservationId: String = "", | ||
val reservationState: ReservationState = ReservationState.PENDING, | ||
val reservationDate: AvailableDate = AvailableDate(), | ||
val carModel: String = "", | ||
val thumbnailImg: String = "" | ||
) |
8 changes: 8 additions & 0 deletions
8
domain/src/main/java/com/gta/domain/repository/TransactionRepository.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,8 @@ | ||
package com.gta.domain.repository | ||
|
||
import com.gta.domain.model.SimpleReservation | ||
|
||
interface TransactionRepository { | ||
suspend fun getYourCarTransactions(uid: String): List<SimpleReservation> | ||
suspend fun getMyCarTransactions(uid: String): List<SimpleReservation> | ||
} |
37 changes: 37 additions & 0 deletions
37
domain/src/main/java/com/gta/domain/usecase/transaction/GetTransactionsUseCase.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,37 @@ | ||
package com.gta.domain.usecase.transaction | ||
|
||
import com.gta.domain.model.Transaction | ||
import com.gta.domain.model.toTransaction | ||
import com.gta.domain.repository.CarRepository | ||
import com.gta.domain.repository.TransactionRepository | ||
import kotlinx.coroutines.flow.first | ||
import javax.inject.Inject | ||
|
||
class GetTransactionsUseCase @Inject constructor( | ||
private val carRepository: CarRepository, | ||
private val transactionRepository: TransactionRepository | ||
) { | ||
private val tradingCondition = | ||
{ transaction: Transaction -> transaction.reservationState.state >= 0 } | ||
private val completedCondition = | ||
{ transaction: Transaction -> transaction.reservationState.state < 0 } | ||
|
||
suspend operator fun invoke( | ||
uid: String, | ||
isLender: Boolean, | ||
isTrading: Boolean | ||
): List<Transaction> { | ||
val transactions = if (isLender) { | ||
transactionRepository.getYourCarTransactions(uid) | ||
} else { | ||
transactionRepository.getMyCarTransactions(uid) | ||
} | ||
|
||
val filterCondition = if (isTrading) tradingCondition else completedCondition | ||
|
||
return transactions.map { reservation -> | ||
val simpleCar = carRepository.getSimpleCar(reservation.carId).first() | ||
reservation.toTransaction(simpleCar) | ||
}.filter(filterCondition) | ||
} | ||
} |
3 changes: 0 additions & 3 deletions
3
presentation/src/main/java/com/gta/presentation/model/EmptyModel.kt
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
presentation/src/main/java/com/gta/presentation/model/TransactionState.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,9 @@ | ||
package com.gta.presentation.model | ||
|
||
import android.os.Parcelable | ||
import kotlinx.parcelize.Parcelize | ||
|
||
@Parcelize | ||
enum class TransactionState : Parcelable { | ||
TRADING, COMPLETED | ||
} |
9 changes: 9 additions & 0 deletions
9
presentation/src/main/java/com/gta/presentation/model/TransactionUserState.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,9 @@ | ||
package com.gta.presentation.model | ||
|
||
import android.os.Parcelable | ||
import kotlinx.parcelize.Parcelize | ||
|
||
@Parcelize | ||
enum class TransactionUserState : Parcelable { | ||
LENDER, OWNER | ||
} |
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
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
Oops, something went wrong.