-
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.
- Loading branch information
1 parent
171a3aa
commit fe596ec
Showing
11 changed files
with
488 additions
and
0 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
70 changes: 70 additions & 0 deletions
70
OrderProcessingAPI/src/main/kotlin/com/blazc/model/order/Order.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,70 @@ | ||
package com.blazc.model.order | ||
|
||
import com.blazc.OrderGrpc | ||
import com.blazc.model.payment.PaymentType | ||
import com.blazc.utils.DateFormatter | ||
import org.bson.types.ObjectId | ||
import java.time.LocalDateTime | ||
|
||
data class Order ( | ||
var id: ObjectId? = null, | ||
var sellerId: ObjectId? = null, | ||
var deliveryPersonId: ObjectId? = null, | ||
var address: String, | ||
var customerName: String, | ||
var items: List<OrderItem>, | ||
var status: OrderStatus, | ||
var orderDate: LocalDateTime, | ||
var paymentType: PaymentType, | ||
var totalPrice: Int | ||
) { | ||
|
||
constructor() : this( | ||
id = ObjectId(), | ||
sellerId = ObjectId(), | ||
deliveryPersonId = ObjectId(), | ||
address = "", | ||
customerName = "", | ||
items = emptyList(), | ||
status = OrderStatus.PENDING, | ||
orderDate = LocalDateTime.now(), | ||
paymentType = PaymentType.CASH, | ||
totalPrice = 0 | ||
) | ||
|
||
companion object { | ||
fun fromGrpc(order: OrderGrpc.Order): Order { | ||
return Order( | ||
id = ObjectId(order.id), | ||
sellerId = ObjectId(order.sellerId), | ||
deliveryPersonId = ObjectId(order.deliveryPersonId), | ||
address = order.address, | ||
customerName = order.customerName, | ||
items = order.itemsList.map { | ||
OrderItem.fromGrpc(it) | ||
}, | ||
status = OrderStatus.fromGrpc(order.status), | ||
orderDate = DateFormatter.toLocalDateTime(order.orderDate), | ||
paymentType = PaymentType.fromGrpc(order.paymentType), | ||
totalPrice = order.totalPrice | ||
) | ||
} | ||
|
||
fun toGrpc(order: Order): OrderGrpc.Order { | ||
return OrderGrpc.Order.newBuilder() | ||
.setId(order.id.toString()) | ||
.setSellerId(order.sellerId.toString()) | ||
.setDeliveryPersonId(order.deliveryPersonId.toString()) | ||
.setAddress(order.address) | ||
.setCustomerName(order.customerName) | ||
.addAllItems(order.items.map { | ||
OrderItem.toGrpc(it) | ||
}) | ||
.setStatus(OrderStatus.toGrpc(order.status)) | ||
.setOrderDate(DateFormatter.toString(order.orderDate)) | ||
.setPaymentType(PaymentType.toGrpc(order.paymentType)) | ||
.setTotalPrice(order.totalPrice) | ||
.build() | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
OrderProcessingAPI/src/main/kotlin/com/blazc/model/order/OrderItem.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,40 @@ | ||
package com.blazc.model.order | ||
|
||
import com.blazc.OrderGrpc | ||
import com.blazc.model.product.Product | ||
import org.bson.types.ObjectId | ||
|
||
data class OrderItem( | ||
var id: ObjectId? = null, | ||
var product: Product, | ||
var quantity: Int, | ||
var price: Int | ||
) { | ||
|
||
constructor() : this( | ||
id = ObjectId(), | ||
product = Product(), | ||
quantity = 0, | ||
price = 0 | ||
) | ||
|
||
companion object { | ||
fun fromGrpc(orderItem: OrderGrpc.OrderItem): OrderItem { | ||
return OrderItem( | ||
id = ObjectId(orderItem.id), | ||
product = Product.fromGrpc(orderItem.product), | ||
quantity = orderItem.quantity, | ||
price = orderItem.price | ||
) | ||
} | ||
|
||
fun toGrpc(orderItem: OrderItem): OrderGrpc.OrderItem { | ||
return OrderGrpc.OrderItem.newBuilder() | ||
.setId(orderItem.id.toString()) | ||
.setProduct(Product.toGrpc(orderItem.product)) | ||
.setQuantity(orderItem.quantity) | ||
.setPrice(orderItem.price) | ||
.build() | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
OrderProcessingAPI/src/main/kotlin/com/blazc/model/order/OrderStatus.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.blazc.model.order | ||
|
||
import com.blazc.OrderGrpc | ||
|
||
enum class OrderStatus { | ||
PENDING, | ||
PREPARING, | ||
READY_FOR_PICKUP, | ||
DELIVERING, | ||
DELIVERED, | ||
CANCELLED; | ||
|
||
companion object { | ||
fun fromGrpc(status: OrderGrpc.OrderStatus): OrderStatus { | ||
return when (status) { | ||
OrderGrpc.OrderStatus.PENDING -> PENDING | ||
OrderGrpc.OrderStatus.PREPARING -> PREPARING | ||
OrderGrpc.OrderStatus.READY_FOR_PICKUP -> READY_FOR_PICKUP | ||
OrderGrpc.OrderStatus.DELIVERING -> DELIVERING | ||
OrderGrpc.OrderStatus.DELIVERED -> DELIVERED | ||
OrderGrpc.OrderStatus.CANCELLED -> CANCELLED | ||
OrderGrpc.OrderStatus.UNRECOGNIZED -> PENDING | ||
} | ||
} | ||
|
||
fun toGrpc(status: OrderStatus): OrderGrpc.OrderStatus { | ||
return when (status) { | ||
PENDING -> OrderGrpc.OrderStatus.PENDING | ||
PREPARING -> OrderGrpc.OrderStatus.PREPARING | ||
READY_FOR_PICKUP -> OrderGrpc.OrderStatus.READY_FOR_PICKUP | ||
DELIVERING -> OrderGrpc.OrderStatus.DELIVERING | ||
DELIVERED -> OrderGrpc.OrderStatus.DELIVERED | ||
CANCELLED -> OrderGrpc.OrderStatus.CANCELLED | ||
} | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
OrderProcessingAPI/src/main/kotlin/com/blazc/model/payment/PaymentType.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,25 @@ | ||
package com.blazc.model.payment | ||
|
||
import com.blazc.OrderGrpc | ||
|
||
enum class PaymentType { | ||
CREDIT_CARD, | ||
CASH; | ||
|
||
companion object { | ||
fun fromGrpc(type: OrderGrpc.PaymentType): PaymentType { | ||
return when (type) { | ||
OrderGrpc.PaymentType.CREDIT_CARD -> PaymentType.CREDIT_CARD | ||
OrderGrpc.PaymentType.CASH -> PaymentType.CASH | ||
OrderGrpc.PaymentType.UNRECOGNIZED -> PaymentType.CASH | ||
} | ||
} | ||
|
||
fun toGrpc(type: PaymentType): OrderGrpc.PaymentType { | ||
return when (type) { | ||
PaymentType.CREDIT_CARD -> OrderGrpc.PaymentType.CREDIT_CARD | ||
PaymentType.CASH -> OrderGrpc.PaymentType.CASH | ||
} | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
OrderProcessingAPI/src/main/kotlin/com/blazc/model/product/Product.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,36 @@ | ||
package com.blazc.model.product | ||
|
||
import com.blazc.OrderGrpc | ||
import org.bson.types.ObjectId | ||
|
||
|
||
data class Product( | ||
var id: ObjectId? = null, | ||
var name: String, | ||
var price: Int // 100 = 1 | ||
) { | ||
|
||
constructor() : this( | ||
id = ObjectId(), | ||
name = "", | ||
price = 0 | ||
) | ||
|
||
companion object { | ||
fun fromGrpc(productGrpc: OrderGrpc.Product): Product { | ||
return Product( | ||
id = ObjectId(productGrpc.id), | ||
name = productGrpc.name, | ||
price = productGrpc.price | ||
) | ||
} | ||
|
||
fun toGrpc(product: Product): OrderGrpc.Product { | ||
return OrderGrpc.Product.newBuilder() | ||
.setId(product.id.toString()) | ||
.setName(product.name) | ||
.setPrice(product.price) | ||
.build() | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
OrderProcessingAPI/src/main/kotlin/com/blazc/repository/OrderRepository.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,19 @@ | ||
package com.blazc.repository | ||
|
||
import com.blazc.model.order.Order | ||
import io.quarkus.mongodb.panache.PanacheMongoRepository | ||
import jakarta.enterprise.context.ApplicationScoped | ||
import org.bson.types.ObjectId | ||
|
||
@ApplicationScoped | ||
class OrderRepository : PanacheMongoRepository<Order> { | ||
|
||
fun findAllBySellerId(sellerId: ObjectId): List<Order> { | ||
return find("sellerId", sellerId).list() | ||
} | ||
|
||
fun findAllByDeliveryPersonId(deliveryPersonId: ObjectId): List<Order> { | ||
return find("deliveryPersonId", deliveryPersonId).list() | ||
} | ||
|
||
} |
Oops, something went wrong.