refactor: move lesson 7 checkout orchestration into viewmodel
Build Android app / Build (push) Has been cancelled
Build iOS app / Build (push) Has been cancelled
Template Cleanup / Template Cleanup (push) Has been cancelled

This commit is contained in:
OpenClaw committed 2026-03-09 03:55:20 +08:00
1 parent a773ac7867
commit 0e5eff673b
3 files changed
+62 -152

No files matched your search

@@ -1,31 +1,4 @@
package com.example.minishop.checkout
import com.example.minishop.cart.CartRepository
import com.example.minishop.order.OrderRepository
data class CheckoutResult(
val success: Boolean,
val message: String
)
class CheckoutService(
private val cartRepository: CartRepository,
private val orderRepository: OrderRepository
) {
fun totalPrice(): Double {
return cartRepository.items().sumOf { item ->
item.price * item.quantity
}
}
fun checkout(): CheckoutResult {
val cartItems = cartRepository.items()
if (cartItems.isEmpty()) return CheckoutResult(false, "购物车为空")
val order = orderRepository.createOrder(cartItems)
?: return CheckoutResult(false, "创建订单失败")
cartRepository.clear()
return CheckoutResult(true, "下单成功,订单号:${order.orderId}")
}
}
@Deprecated("Lesson 7 moved checkout orchestration into ShopViewModel")
class CheckoutService