Skip to content

Commit

Permalink
Fix not being able to send orders to SynQ (#36)
Browse files Browse the repository at this point in the history
Updates the data structure to better fit our use-cases. Also fixes an issue where we weren't able to create new orders within SynQ

* Remove ShippingAddress from SynqOrderPayload

* Fix default priority in test

* Remove unused nullable fields from Order Receiver

* Reintroduce ShippingAddress and remove customer from SynQ payload

* Make name required, update Swagger examples

* Fix test

* Apply suggestions from code review

Small text fixes

---------

Co-authored-by: Daniel Aaron Salwerowicz <[email protected]>
  • Loading branch information
anotheroneofthese and MormonJesus69420 authored Oct 1, 2024
1 parent c6789c6 commit caa5521
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ import org.springframework.web.server.ServerWebInputException
"owner": "NB",
"receiver": {
"name": "Doug Dimmadome",
"location": "Doug Dimmadome's office in the Dimmsdale Dimmadome",
"address": "Dimmsdale Dimmadome",
"city": "Dimmsdale",
"postalCode": "69-420",
"phoneNum": "+47 666 69 420"
"address": "Dimmsdale Dimmadome, 21st Ave. Texas"
},
"callbackUrl": "https://example.com/send/callback/here"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ import kotlin.jvm.Throws
"orderType": "LOAN",
"receiver": {
"name": "Doug Dimmadome",
"location": "Doug Dimmadome's office in the Dimmsdale Dimmadome",
"address": "Dimmsdale Dimmadome",
"city": "Dimmsdale",
"postalCode": "69-420",
"phoneNum": "+47 666 69 420"
"address": "Dimmsdale Dimmadome, 21st Ave. Texas"
},
"callbackUrl": "https://example.com/send/callback/here"
}
Expand Down
6 changes: 1 addition & 5 deletions src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,7 @@ data class Order(

data class Receiver(
val name: String,
val location: String,
val address: String?,
val city: String?,
val postalCode: String?,
val phoneNumber: String?
val address: String?
)

enum class Status {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package no.nb.mlt.wls.infrastructure.synq

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
Expand All @@ -21,8 +22,7 @@ data class SynqOrderPayload(
val priority: Int,
val owner: SynqOwner,
val orderLine: List<OrderLine>,
val customer: String? = null,
val shippingAddress: ShippingAddress? = null
val shippingAddress: ShippingAddress
) {
data class OrderLine(
@Min(1)
Expand All @@ -31,21 +31,6 @@ data class SynqOrderPayload(
val quantityOrdered: Double
)

data class ShippingAddress(
val address: Address?
) {
data class Address(
val contactPerson: String? = null,
val addressLine1: String? = null,
val city: String? = null,
val state: String? = null,
val postalCode: String? = null,
val country: String? = null,
val phoneNumber: String? = null,
val email: String? = null
)
}

enum class SynqOrderType(private val type: String) {
STANDARD("Standard");

Expand All @@ -56,6 +41,16 @@ data class SynqOrderPayload(
}
}

data class ShippingAddress(
val address: Address
) {
data class Address(
val contactPerson: String,
@JsonInclude(JsonInclude.Include.NON_NULL)
val addressLine1: String? = null
)
}

fun Order.toSynqPayload() =
SynqOrderPayload(
orderId = hostOrderId,
Expand All @@ -65,7 +60,7 @@ fun Order.toSynqPayload() =
// 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 = 1,
priority = 5,
owner = owner?.toSynqOwner() ?: SynqOwner.NB,
orderLine =
productLine.mapIndexed { index, it ->
Expand All @@ -75,19 +70,13 @@ fun Order.toSynqPayload() =
quantityOrdered = 1.0
)
},
customer = receiver.name,
shippingAddress = receiver.toShippingAddress()
)

fun Order.Receiver.toShippingAddress(): SynqOrderPayload.ShippingAddress =
SynqOrderPayload.ShippingAddress(
SynqOrderPayload.ShippingAddress.Address(
contactPerson = name,
addressLine1 = address,
city = city,
postalCode = postalCode,
phoneNumber = phoneNumber
)
shippingAddress =
ShippingAddress(
ShippingAddress.Address(
receiver.name,
receiver.address
)
)
)

fun Item.toSynqPayload() =
Expand Down
8 changes: 2 additions & 6 deletions src/test/kotlin/no/nb/mlt/wls/domain/WLSServiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class WLSServiceTest {
"12345",
listOf("mlt-420", "mlt-421"),
Order.Type.LOAN,
Order.Receiver("name", "location", null, null, null, null),
Order.Receiver("name", "address"),
"https://example.com"
)

Expand Down Expand Up @@ -344,11 +344,7 @@ class WLSServiceTest {
receiver =
Order.Receiver(
name = "Kåre",
address = "Kåres gate 1",
postalCode = "1234",
city = "Kåresby",
location = "Kåresplass",
phoneNumber = "99999999"
address = "Kåresplass"
),
callbackUrl = "http://callback.url/path"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,7 @@ class OrderControllerTest(
receiver =
Order.Receiver(
name = "name",
address = "address",
postalCode = "postalCode",
city = "city",
phoneNumber = "phoneNumber",
location = "location"
address = "address"
),
callbackUrl = "https://callbackUrl.com"
)
Expand All @@ -401,11 +397,7 @@ class OrderControllerTest(
receiver =
Order.Receiver(
name = "name",
address = "address",
postalCode = "postalCode",
city = "city",
phoneNumber = "phoneNumber",
location = "location"
address = "address"
),
callbackUrl = "https://callbackUrl.com"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import no.nb.mlt.wls.application.restapi.order.toOrder
import no.nb.mlt.wls.domain.model.HostName
import no.nb.mlt.wls.domain.model.Order
import no.nb.mlt.wls.domain.model.Owner
import no.nb.mlt.wls.infrastructure.synq.ShippingAddress
import no.nb.mlt.wls.infrastructure.synq.SynqOrderPayload
import no.nb.mlt.wls.infrastructure.synq.SynqOwner
import no.nb.mlt.wls.infrastructure.synq.toSynqPayload
Expand All @@ -26,11 +27,7 @@ class MongoOrderModelConversionTest {
receiver =
Order.Receiver(
name = "name",
address = "address",
postalCode = "postalCode",
city = "city",
phoneNumber = "phoneNumber",
location = "location"
address = "address"
),
callbackUrl = "callbackUrl"
)
Expand All @@ -46,11 +43,7 @@ class MongoOrderModelConversionTest {
receiver =
Order.Receiver(
name = "name",
address = "address",
postalCode = "postalCode",
city = "city",
phoneNumber = "phoneNumber",
location = "location"
address = "address"
),
callbackUrl = "callbackUrl"
)
Expand All @@ -61,9 +54,18 @@ class MongoOrderModelConversionTest {
orderType = SynqOrderPayload.SynqOrderType.STANDARD,
dispatchDate = LocalDateTime.now(),
orderDate = LocalDateTime.now(),
priority = 1,
priority = 5,
owner = SynqOwner.NB,
orderLine = listOf(SynqOrderPayload.OrderLine(1, "hostProductId", 1.0))
orderLine =
listOf(
SynqOrderPayload.OrderLine(1, "hostProductId", 1.0)
),
shippingAddress =
ShippingAddress(
ShippingAddress.Address(
"contactPerson"
)
)
)

@Test
Expand Down

0 comments on commit caa5521

Please sign in to comment.