Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MLT-0045 Add Hostname on Order IDs for SynQ Orders #49

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,12 @@ class SynqController(
@RequestBody payload: SynqOrderPickingConfirmationPayload
) {
payload.validate()
// TODO - Migrate functionality to the Order domain model instead of handling it here
val hostIds: MutableMap<String, Double> = mutableMapOf()
val hostName = HostName.valueOf(payload.orderLine.first().hostName.uppercase())
if (!orderId.startsWith(hostName.toString())) {
TODO("Log this error, or throw an exception?")
}
payload.orderLine.map { orderLine ->
hostIds.put(
orderLine.productId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.fasterxml.jackson.annotation.JsonFormat
import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.annotation.JsonValue
import jakarta.validation.constraints.Min
import no.nb.mlt.wls.domain.model.Item
import no.nb.mlt.wls.domain.model.Order
import no.nb.mlt.wls.domain.model.Packaging
import no.nb.mlt.wls.infrastructure.synq.SynqProductPayload.SynqPackaging
Expand Down Expand Up @@ -53,15 +52,15 @@ data class ShippingAddress(

fun Order.toSynqPayload() =
SynqOrderPayload(
orderId = hostOrderId,
orderId = hostName.toString().uppercase() + "_" + hostOrderId,
anotheroneofthese marked this conversation as resolved.
Show resolved Hide resolved
orderType = orderType.toSynqOrderType(),
// When order should be dispatched, AFAIK it's not used by us as we don't receive orders in future
dispatchDate = LocalDateTime.now(),
// When order was made in SynQ, if we want to we can omit it and SynQ will set it to current date itself
orderDate = LocalDateTime.now(),
// TODO: we don't get it from API so we set it to 1, is other value more appropriate?
priority = 5,
owner = owner?.toSynqOwner() ?: SynqOwner.NB,
owner = owner.toSynqOwner(),
orderLine =
orderLine.mapIndexed { index, it ->
SynqOrderPayload.OrderLine(
Expand All @@ -79,18 +78,6 @@ fun Order.toSynqPayload() =
)
)

fun Item.toSynqPayload() =
SynqProductPayload(
productId = hostId,
owner = owner.toSynqOwner(),
barcode = SynqProductPayload.Barcode(hostId),
description = description,
productCategory = itemCategory,
productUom = SynqProductPayload.ProductUom(packaging.toSynqPackaging()),
confidential = false,
hostName = hostName.toString()
)

fun Packaging.toSynqPackaging(): SynqPackaging =
when (this) {
Packaging.NONE -> OBJ
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package no.nb.mlt.wls.infrastructure.synq

import no.nb.mlt.wls.domain.model.Item

data class SynqProductPayload(
val productId: String,
val owner: SynqOwner,
Expand All @@ -19,3 +21,15 @@ data class SynqProductPayload(

data class ProductUom(val uomId: SynqPackaging)
}

fun Item.toSynqPayload() =
SynqProductPayload(
productId = hostId,
owner = owner.toSynqOwner(),
barcode = SynqProductPayload.Barcode(hostId),
description = description,
productCategory = itemCategory,
productUom = SynqProductPayload.ProductUom(packaging.toSynqPackaging()),
confidential = false,
hostName = hostName.toString()
)
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class OrderModelConversionTest {

private val testSynqOrderPayload =
SynqOrderPayload(
orderId = "hostOrderId",
orderId = "AXIELL_hostOrderId",
orderType = SynqOrderPayload.SynqOrderType.STANDARD,
dispatchDate = LocalDateTime.now(),
orderDate = LocalDateTime.now(),
Expand Down