-
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.
* Remove @document as it will no longer use to store data in mongodb * Added new models * Link multiple models * Increment version of library
- Loading branch information
Showing
5 changed files
with
79 additions
and
11 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
13 changes: 7 additions & 6 deletions
13
src/main/kotlin/com/hrv/mart/orderlibrary/model/OrderRequest.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 |
---|---|---|
@@ -1,17 +1,18 @@ | ||
package com.hrv.mart.orderlibrary.model | ||
|
||
import com.hrv.mart.cartresponse.model.CartResponse | ||
import com.hrv.mart.orderlibrary.model.order.Order | ||
import com.hrv.mart.orderlibrary.model.order.ProductOrdered | ||
|
||
|
||
data class OrderRequest ( | ||
val userId: String, | ||
val products: List<CartResponse>, | ||
val price: Long | ||
) { | ||
fun getOrderResponse() = | ||
OrderResponse( | ||
userId=userId, | ||
products=products, | ||
price=price | ||
) | ||
fun getOrder() = | ||
Order.parseFrom(this) | ||
fun getProductOrdered(order: Order) = | ||
ProductOrdered.parseFrom(this, order) | ||
|
||
} |
24 changes: 20 additions & 4 deletions
24
src/main/kotlin/com/hrv/mart/orderlibrary/model/OrderResponse.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 |
---|---|---|
@@ -1,15 +1,31 @@ | ||
package com.hrv.mart.orderlibrary.model | ||
|
||
import com.hrv.mart.orderlibrary.model.Status | ||
import com.hrv.mart.cartresponse.model.CartResponse | ||
import org.springframework.data.mongodb.core.mapping.Document | ||
import com.hrv.mart.orderlibrary.model.order.Order | ||
import com.hrv.mart.orderlibrary.model.order.ProductOrdered | ||
import java.time.LocalDateTime | ||
|
||
@Document("Order") | ||
data class OrderResponse ( | ||
val userId: String, | ||
val products: List<CartResponse>, | ||
val price: Long, | ||
val status: Status = Status.PROCESS, | ||
val dateTimeOfOrder: LocalDateTime = LocalDateTime.now() | ||
) | ||
) { | ||
companion object { | ||
fun parseFrom (order: Order, productOrdered: List<ProductOrdered>) = | ||
OrderResponse( | ||
userId = order.userId, | ||
price = order.price, | ||
products = productOrdered | ||
.map { | ||
CartResponse( | ||
productId = it.productId, | ||
quantity = it.quantity | ||
) | ||
}, | ||
status = order.status, | ||
dateTimeOfOrder = order.dateTimeOfOrder | ||
) | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/kotlin/com/hrv/mart/orderlibrary/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,25 @@ | ||
package com.hrv.mart.orderlibrary.model.order | ||
|
||
import com.hrv.mart.orderlibrary.model.OrderRequest | ||
import com.hrv.mart.orderlibrary.model.Status | ||
import org.bson.types.ObjectId | ||
import org.springframework.data.mongodb.core.mapping.Document | ||
import java.time.LocalDateTime | ||
|
||
@Document("Order") | ||
data class Order ( | ||
val userId: String, | ||
val price: Long, | ||
// Params with default values | ||
val orderId: String=ObjectId.get().toString(), | ||
val status: Status = Status.PROCESS, | ||
val dateTimeOfOrder: LocalDateTime = LocalDateTime.now() | ||
) { | ||
companion object { | ||
fun parseFrom(orderRequest: OrderRequest) = | ||
Order( | ||
userId=orderRequest.userId, | ||
price = orderRequest.price | ||
) | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/kotlin/com/hrv/mart/orderlibrary/model/order/ProductOrdered.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,26 @@ | ||
package com.hrv.mart.orderlibrary.model.order | ||
|
||
import com.hrv.mart.orderlibrary.model.OrderRequest | ||
import org.springframework.data.mongodb.core.mapping.Document | ||
|
||
@Document("ProductOrdered") | ||
data class ProductOrdered ( | ||
val orderId: String, | ||
val productId: String, | ||
val quantity: Long, | ||
val userId: String | ||
) { | ||
companion object { | ||
fun parseFrom(orderRequest: OrderRequest, order: Order) = | ||
orderRequest | ||
.products | ||
.map {cartResponse -> | ||
ProductOrdered( | ||
userId = order.userId, | ||
productId = cartResponse.productId, | ||
quantity = cartResponse.quantity, | ||
orderId = order.orderId | ||
) | ||
} | ||
} | ||
} |