Skip to content

Commit

Permalink
Update use cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Maruchin1 committed Apr 21, 2023
1 parent 67309c7 commit 7dca7c3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package com.maruchin.domaindrivenandroid.domain.coupon

import com.maruchin.domaindrivenandroid.data.account.Account
import com.maruchin.domaindrivenandroid.data.coupon.Coupon
import com.maruchin.domaindrivenandroid.data.coupon.sampleCoupons

data class CollectableCoupon(val coupon: Coupon, val canCollect: Boolean)
data class CollectableCoupon(val coupon: Coupon, val canCollect: Boolean) {

constructor(coupon: Coupon, account: Account) : this(
coupon = coupon,
canCollect = account.canExchangePointsFor(coupon)
)
}

val sampleCollectableCoupons = listOf(
CollectableCoupon(coupon = sampleCoupons[2], canCollect = true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class GetAllCollectableCouponsUseCase @Inject constructor(
accountRepository.getLoggedInAccount().filterNotNull(),
couponsRepository.getAllCoupons()
) { account, allCoupons ->
allCoupons.sortedBy {
it.points
allCoupons.sortedBy { coupon ->
coupon.points
}.map { coupon ->
CollectableCoupon(coupon = coupon, canCollect = account.canExchangePointsFor(coupon))
CollectableCoupon(coupon, account)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ class GetCollectableCouponUseCase @Inject constructor(
accountRepository.getLoggedInAccount().filterNotNull(),
couponsRepository.getCoupon(couponId).filterNotNull(),
) { account, coupon ->
CollectableCoupon(
coupon = coupon,
canCollect = account.canExchangePointsFor(coupon)
)
CollectableCoupon(coupon, account)
}
}
}

0 comments on commit 7dca7c3

Please sign in to comment.