From 082cedb45b544ced7b69086d23d566dfb00286ff Mon Sep 17 00:00:00 2001 From: Noah Bjerkli Aanonli Date: Thu, 28 Nov 2024 14:33:53 +0100 Subject: [PATCH 01/22] Change domain models to include Address and Contact Person Replaces Receiver --- .../hostapi/order/ApiOrderPayload.kt | 54 ++++--------------- .../hostapi/order/ApiUpdateOrderPayload.kt | 6 +-- .../no/nb/mlt/wls/domain/model/Order.kt | 48 +++++++++++++---- .../wls/domain/ports/inbound/CreateOrder.kt | 6 ++- .../callbacks/NotificationOrderPayload.kt | 11 ++-- .../repositories/order/MongoOrder.kt | 9 ++-- .../infrastructure/synq/SynqOrderPayload.kt | 5 +- 7 files changed, 73 insertions(+), 66 deletions(-) diff --git a/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiOrderPayload.kt b/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiOrderPayload.kt index 005a3d7a..bd727640 100644 --- a/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiOrderPayload.kt +++ b/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiOrderPayload.kt @@ -58,10 +58,11 @@ data class ApiOrderPayload( examples = ["LOAN", "DIGITIZATION"] ) val orderType: Order.Type, - @Schema( - description = "Who's the receiver of the material in the order." - ) - val receiver: Receiver, + // TODO - Swaggerdoc + val contactPerson: String, + // TODO - Swaggerdoc + // TODO - Should this use Order Address or custom DTO? + val address: Order.Address?, @Schema( description = "Callback URL for the order used to update the order information in the host system.", example = "https://example.com/send/callback/here" @@ -75,7 +76,8 @@ data class ApiOrderPayload( orderLine = orderLine.map { it.toCreateOrderItem() }, orderType = orderType, owner = owner, - receiver = receiver.toOrderReceiver(), + address = address, + contactPerson = contactPerson, callbackUrl = callbackUrl ) @@ -93,7 +95,7 @@ data class ApiOrderPayload( } orderLine.forEach(OrderLine::validate) - receiver.validate() + address?.validate() } private fun isValidUrl(url: String): Boolean { @@ -116,7 +118,8 @@ fun Order.toApiOrderPayload() = status = status, orderLine = orderLine.map { it.toApiOrderLine() }, orderType = orderType, - receiver = Receiver(receiver.name, receiver.address), + contactPerson = contactPerson, + address = address, callbackUrl = callbackUrl ) @@ -155,40 +158,3 @@ data class OrderLine( fun Order.OrderItem.toApiOrderLine() = OrderLine(hostId, status) -@Schema( - description = "Who's the receiver of the order.", - example = """ - { - "name": "Doug Dimmadome", - "address": "Dimmsdale Dimmadome, Apartment 420, 69th Ave. Texas" - } - """ -) -data class Receiver( - @Schema( - description = "Name of the receiver.", - example = "Doug Dimmadome" - ) - val name: String, - @Schema( - description = "Address of the receiver.", - example = "Dimmsdale Dimmadome, Apartment 420, 69th Ave. Texas", - required = false - ) - val address: String? -) { - fun toOrderReceiver() = Order.Receiver(name, address ?: "") - - @Throws(ValidationException::class) - fun validate() { - if (name.isBlank()) { - throw ValidationException("The order's receiver name is required, and can not be blank") - } - - if (address != null && address.isBlank()) { - throw ValidationException("The order's receiver address cannot be blank if provided") - } - } -} - -fun Order.Receiver.toReceiver() = Receiver(name, address) diff --git a/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiUpdateOrderPayload.kt b/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiUpdateOrderPayload.kt index 5d418364..5fbf5cb8 100644 --- a/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiUpdateOrderPayload.kt +++ b/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiUpdateOrderPayload.kt @@ -53,7 +53,8 @@ data class ApiUpdateOrderPayload( @Schema( description = "Who's the receiver of the material in the order." ) - val receiver: Receiver, + val contactPerson: String, + val address: Order.Address?, @Schema( description = "URL to send a callback to when the order is completed.", example = "https://example.com/send/callback/here" @@ -75,8 +76,7 @@ data class ApiUpdateOrderPayload( } orderLine.forEach(OrderLine::validate) - - receiver.validate() + address?.validate() } private fun isValidUrl(url: String): Boolean { diff --git a/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt b/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt index fe499508..b05fe1f6 100644 --- a/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt +++ b/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt @@ -13,7 +13,8 @@ data class Order( val orderLine: List, val orderType: Type, val owner: Owner, - val receiver: Receiver, + val address: Address?, + val contactPerson: String, val callbackUrl: String ) { private fun setOrderLines(listOfHostIds: List): Order { @@ -55,8 +56,8 @@ data class Order( .updateOrderStatusFromOrderLines() } - private fun setReceiver(receiver: Receiver): Order { - return this.copy(receiver = receiver) + private fun setContactPerson(contactPerson: String): Order { + return this.copy(contactPerson = contactPerson) } private fun setOrderType(orderType: Type): Order { @@ -98,14 +99,14 @@ data class Order( itemIds: List, callbackUrl: String, orderType: Type, - receiver: Receiver + contactPerson: String ): Order { throwIfInProgress() return this.setOrderLines(itemIds) .setCallbackUrl(callbackUrl) .setOrderType(orderType) - .setReceiver(receiver) + .setContactPerson(contactPerson) } /** @@ -153,10 +154,39 @@ data class Order( } } - data class Receiver( - val name: String, - val address: String? - ) + data class Address( + val name: String?, + val addressLine1: String?, + val addressLine2: String?, + val zipcode: String?, + val city: String?, + val state: String?, + ) { + fun validate() { + if (name?.isBlank() == true) { + throw ValidationException("Name must not be blank") + } + if (addressLine1?.isBlank() == true) { + throw ValidationException("Address line must not be blank") + } + if (addressLine2?.isBlank() == true) { + throw ValidationException("Address line must not be blank") + } + if (zipcode?.isBlank() == true) { + throw ValidationException("Zipcode can not be blank") + } + if (city?.isBlank() == true) { + throw ValidationException("City must not be blank") + } + // TODO - Validate State/Region/County? + } + + companion object { + fun create(): Address { + return Address(null, null, null, null, null, null) + } + } + } enum class Status { NOT_STARTED, diff --git a/src/main/kotlin/no/nb/mlt/wls/domain/ports/inbound/CreateOrder.kt b/src/main/kotlin/no/nb/mlt/wls/domain/ports/inbound/CreateOrder.kt index a6252b53..87d1309f 100644 --- a/src/main/kotlin/no/nb/mlt/wls/domain/ports/inbound/CreateOrder.kt +++ b/src/main/kotlin/no/nb/mlt/wls/domain/ports/inbound/CreateOrder.kt @@ -14,7 +14,8 @@ data class CreateOrderDTO( val orderLine: List, val orderType: Order.Type, val owner: Owner, - val receiver: Order.Receiver, + val contactPerson: String, + val address: Order.Address?, val callbackUrl: String ) { data class OrderItem( @@ -33,7 +34,8 @@ fun CreateOrderDTO.toOrder(): Order { }, orderType = orderType, owner = owner, - receiver = receiver, + contactPerson = contactPerson, + address = address, callbackUrl = callbackUrl ) } diff --git a/src/main/kotlin/no/nb/mlt/wls/infrastructure/callbacks/NotificationOrderPayload.kt b/src/main/kotlin/no/nb/mlt/wls/infrastructure/callbacks/NotificationOrderPayload.kt index a0c2d4ba..21b7f7b5 100644 --- a/src/main/kotlin/no/nb/mlt/wls/infrastructure/callbacks/NotificationOrderPayload.kt +++ b/src/main/kotlin/no/nb/mlt/wls/infrastructure/callbacks/NotificationOrderPayload.kt @@ -59,9 +59,13 @@ data class NotificationOrderPayload( ) val owner: Owner?, @Schema( - description = "Who's the receiver of the material in the order." + description = "The person to contact regarding matters about the order" ) - val receiver: Order.Receiver, + val contactPerson: String, + @Schema( + description = "The address of the receiver of the material in the order." + ) + val address: Order.Address?, @Schema( description = "Callback URL for the order used to update the order information in the host system.", example = "https://example.com/send/callback/here" @@ -77,6 +81,7 @@ fun Order.toNotificationOrderPayload() = orderLine = orderLine, orderType = orderType, owner = owner, - receiver = receiver, + contactPerson = contactPerson, + address = address, callbackUrl = callbackUrl ) diff --git a/src/main/kotlin/no/nb/mlt/wls/infrastructure/repositories/order/MongoOrder.kt b/src/main/kotlin/no/nb/mlt/wls/infrastructure/repositories/order/MongoOrder.kt index e2d306a7..acdbbab7 100644 --- a/src/main/kotlin/no/nb/mlt/wls/infrastructure/repositories/order/MongoOrder.kt +++ b/src/main/kotlin/no/nb/mlt/wls/infrastructure/repositories/order/MongoOrder.kt @@ -19,7 +19,8 @@ data class MongoOrder( val orderLine: List, val orderType: Order.Type, val owner: Owner, - val receiver: Order.Receiver, + val contactPerson: String, + val address: Order.Address?, val callbackUrl: String ) @@ -31,7 +32,8 @@ fun Order.toMongoOrder(): MongoOrder { orderLine = orderLine, orderType = orderType, owner = owner, - receiver = receiver, + contactPerson = contactPerson, + address = address, callbackUrl = callbackUrl ) } @@ -44,7 +46,8 @@ fun MongoOrder.toOrder(): Order { orderLine = orderLine, orderType = orderType, owner = owner, - receiver = receiver, + contactPerson = contactPerson, + address = address, callbackUrl = callbackUrl ) } diff --git a/src/main/kotlin/no/nb/mlt/wls/infrastructure/synq/SynqOrderPayload.kt b/src/main/kotlin/no/nb/mlt/wls/infrastructure/synq/SynqOrderPayload.kt index 80d62255..7ccabd23 100644 --- a/src/main/kotlin/no/nb/mlt/wls/infrastructure/synq/SynqOrderPayload.kt +++ b/src/main/kotlin/no/nb/mlt/wls/infrastructure/synq/SynqOrderPayload.kt @@ -40,6 +40,7 @@ data class SynqOrderPayload( } } +// TODO - Should this be expanded with more fields? data class ShippingAddress( val address: Address ) { @@ -71,8 +72,8 @@ fun Order.toSynqPayload() = shippingAddress = ShippingAddress( ShippingAddress.Address( - receiver.name, - receiver.address + contactPerson, + address?.addressLine1 ) ) ) From 9577f5aae321c5b6237eac05a68ef7d8995d7c2d Mon Sep 17 00:00:00 2001 From: Noah Bjerkli Aanonli Date: Thu, 28 Nov 2024 14:34:58 +0100 Subject: [PATCH 02/22] Update codebase to use new domain structure --- .../mlt/wls/application/hostapi/order/OrderController.kt | 3 ++- src/main/kotlin/no/nb/mlt/wls/domain/WLSService.kt | 5 +++-- .../no/nb/mlt/wls/domain/ports/inbound/UpdateOrder.kt | 3 ++- .../repositories/order/MongoOrderRepositoryAdapter.kt | 8 +++++--- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/OrderController.kt b/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/OrderController.kt index 7c90db6e..cb011e9e 100644 --- a/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/OrderController.kt +++ b/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/OrderController.kt @@ -254,7 +254,8 @@ class OrderController( hostOrderId = payload.hostOrderId, itemHostIds = payload.orderLine.map { it.hostId }, orderType = payload.orderType, - receiver = payload.receiver.toOrderReceiver(), + contactPerson = payload.contactPerson, + address = payload.address, callbackUrl = payload.callbackUrl ) diff --git a/src/main/kotlin/no/nb/mlt/wls/domain/WLSService.kt b/src/main/kotlin/no/nb/mlt/wls/domain/WLSService.kt index bdd7df41..baba7ca6 100644 --- a/src/main/kotlin/no/nb/mlt/wls/domain/WLSService.kt +++ b/src/main/kotlin/no/nb/mlt/wls/domain/WLSService.kt @@ -153,7 +153,8 @@ class WLSService( hostOrderId: String, itemHostIds: List, orderType: Order.Type, - receiver: Order.Receiver, + contactPerson: String, + address: Order.Address?, callbackUrl: String ): Order { val itemIds = itemHostIds.map { ItemId(hostName, it) } @@ -163,7 +164,7 @@ class WLSService( val order = getOrderOrThrow(hostName, hostOrderId) - val updatedOrder = order.updateOrder(itemHostIds, callbackUrl, orderType, receiver) + val updatedOrder = order.updateOrder(itemHostIds, callbackUrl, orderType, contactPerson) val result = storageSystemFacade.updateOrder(updatedOrder) return orderRepository.updateOrder(result) } diff --git a/src/main/kotlin/no/nb/mlt/wls/domain/ports/inbound/UpdateOrder.kt b/src/main/kotlin/no/nb/mlt/wls/domain/ports/inbound/UpdateOrder.kt index 1490e317..6c9a8e4a 100644 --- a/src/main/kotlin/no/nb/mlt/wls/domain/ports/inbound/UpdateOrder.kt +++ b/src/main/kotlin/no/nb/mlt/wls/domain/ports/inbound/UpdateOrder.kt @@ -12,7 +12,8 @@ interface UpdateOrder { hostOrderId: String, itemHostIds: List, orderType: Order.Type, - receiver: Order.Receiver, + contactPerson: String, + address: Order.Address?, callbackUrl: String ): Order } diff --git a/src/main/kotlin/no/nb/mlt/wls/infrastructure/repositories/order/MongoOrderRepositoryAdapter.kt b/src/main/kotlin/no/nb/mlt/wls/infrastructure/repositories/order/MongoOrderRepositoryAdapter.kt index 179d988a..b71d77a2 100644 --- a/src/main/kotlin/no/nb/mlt/wls/infrastructure/repositories/order/MongoOrderRepositoryAdapter.kt +++ b/src/main/kotlin/no/nb/mlt/wls/infrastructure/repositories/order/MongoOrderRepositoryAdapter.kt @@ -69,7 +69,8 @@ class MongoOrderRepositoryAdapter( order.orderLine, order.orderType, order.owner, - order.receiver, + order.contactPerson, + order.address, order.callbackUrl ) .timeout(Duration.ofSeconds(8)) @@ -115,7 +116,7 @@ interface OrderMongoRepository : ReactiveMongoRepository { ): Mono @Query("{hostName: ?0, hostOrderId: ?1}") - @Update("{'\$set':{status: ?2,orderLine: ?3,orderType: ?4,owner: ?5,receiver: ?6,callbackUrl: ?7}}") + @Update("{'\$set':{status: ?2,orderLine: ?3,orderType: ?4,owner: ?5,contactPerson: ?6,address: ?7, callbackUrl: ?8}}") fun findAndUpdateByHostNameAndHostOrderId( hostName: HostName, hostOrderId: String, @@ -123,7 +124,8 @@ interface OrderMongoRepository : ReactiveMongoRepository { orderLine: List, orderType: Order.Type, owner: Owner?, - receiver: Order.Receiver, + contactPerson: String, + address: Order.Address?, callbackUrl: String ): Mono } From cad6b98a756437c2263d3364bc2dfb608fb9ea80 Mon Sep 17 00:00:00 2001 From: Noah Bjerkli Aanonli Date: Thu, 28 Nov 2024 14:35:10 +0100 Subject: [PATCH 03/22] Update tests to use new domain models --- .../no/nb/mlt/wls/domain/WLSServiceTest.kt | 19 ++--- .../order/controller/OrderControllerTest.kt | 38 +++++++-- .../order/model/OrderModelConversionTest.kt | 79 +++++++++---------- .../order/model/OrderModelValidationTest.kt | 78 ++++-------------- .../wls/synq/controller/SynqControllerTest.kt | 11 ++- 5 files changed, 101 insertions(+), 124 deletions(-) diff --git a/src/test/kotlin/no/nb/mlt/wls/domain/WLSServiceTest.kt b/src/test/kotlin/no/nb/mlt/wls/domain/WLSServiceTest.kt index 5aa17ba0..e3729897 100644 --- a/src/test/kotlin/no/nb/mlt/wls/domain/WLSServiceTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/domain/WLSServiceTest.kt @@ -318,7 +318,8 @@ class WLSServiceTest { "12345", listOf("mlt-420", "mlt-421"), Order.Type.LOAN, - Order.Receiver("name", "address"), + "unreal person", + Order.Address.create(), "https://example.com" ) @@ -344,7 +345,8 @@ class WLSServiceTest { "12345", listOf("mlt-420", "mlt-421"), testOrder.orderType, - testOrder.receiver, + testOrder.contactPerson, + testOrder.address?: Order.Address.create(), testOrder.callbackUrl ) } @@ -367,7 +369,8 @@ class WLSServiceTest { "12345", listOf("mlt-420", "mlt-421"), testOrder.orderType, - testOrder.receiver, + testOrder.contactPerson, + testOrder.address, testOrder.callbackUrl ) } @@ -424,11 +427,8 @@ class WLSServiceTest { orderLine = listOf(), orderType = Order.Type.LOAN, owner = Owner.NB, - receiver = - Order.Receiver( - name = "Kåre", - address = "Kåresplass" - ), + contactPerson = "contactPerson", + address = Order.Address.create(), callbackUrl = "https://callback.com/order" ) @@ -456,7 +456,8 @@ class WLSServiceTest { orderLine = testOrder.orderLine.map { CreateOrderDTO.OrderItem(it.hostId) }, orderType = testOrder.orderType, owner = testOrder.owner, - receiver = testOrder.receiver, + contactPerson = testOrder.contactPerson, + address = testOrder.address, callbackUrl = testOrder.callbackUrl ) } diff --git a/src/test/kotlin/no/nb/mlt/wls/order/controller/OrderControllerTest.kt b/src/test/kotlin/no/nb/mlt/wls/order/controller/OrderControllerTest.kt index a49c1cbb..24b41076 100644 --- a/src/test/kotlin/no/nb/mlt/wls/order/controller/OrderControllerTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/order/controller/OrderControllerTest.kt @@ -12,7 +12,6 @@ import no.nb.mlt.wls.EnableTestcontainers import no.nb.mlt.wls.application.hostapi.ErrorMessage import no.nb.mlt.wls.application.hostapi.order.ApiOrderPayload import no.nb.mlt.wls.application.hostapi.order.OrderLine -import no.nb.mlt.wls.application.hostapi.order.Receiver import no.nb.mlt.wls.application.hostapi.order.toApiOrderPayload import no.nb.mlt.wls.domain.model.Environment import no.nb.mlt.wls.domain.model.HostName @@ -252,7 +251,7 @@ class OrderControllerTest( fun `updateOrder with valid payload updates order`() { val testPayload = duplicateOrderPayload.copy( - receiver = Receiver("newName", duplicateOrderPayload.receiver.address), + contactPerson = "new person", callbackUrl = "https://new-callback.com/order", orderLine = listOf(OrderLine("item-123", null)) ) @@ -275,7 +274,7 @@ class OrderControllerTest( orderLines?.map { it -> assertThat(testPayload.orderLine.contains(OrderLine(it.hostId, Order.OrderItem.Status.NOT_STARTED))) } - assertThat(response.responseBody?.receiver?.name).isEqualTo(testPayload.receiver.name) + assertThat(response.responseBody?.contactPerson).isEqualTo(testPayload.contactPerson) assertThat(response.responseBody?.callbackUrl).isEqualTo(testPayload.callbackUrl) } } @@ -465,7 +464,15 @@ class OrderControllerTest( status = Order.Status.NOT_STARTED, orderLine = listOf(OrderLine("item-123", Order.OrderItem.Status.NOT_STARTED)), orderType = Order.Type.LOAN, - receiver = Receiver(name = "name", address = "address"), + address = Order.Address( + name = "name", + addressLine1 = "addressLine1", + addressLine2 = "addressLine2", + zipcode = "zipcode", + city = "city", + state = "state" + ), + contactPerson = "named person", callbackUrl = "https://callback.com/order" ) @@ -480,7 +487,15 @@ class OrderControllerTest( status = Order.Status.NOT_STARTED, orderLine = listOf(OrderLine("item-456", Order.OrderItem.Status.NOT_STARTED)), orderType = Order.Type.LOAN, - receiver = Receiver(name = "name", address = "address"), + address = Order.Address( + name = "name", + addressLine1 = "addressLine1", + addressLine2 = "addressLine2", + zipcode = "zipcode", + city = "city", + state = "state" + ), + contactPerson = "named person", callbackUrl = "https://callback.com/order" ) @@ -492,7 +507,15 @@ class OrderControllerTest( orderLine = listOf(Order.OrderItem("item-123", Order.OrderItem.Status.NOT_STARTED)), orderType = Order.Type.LOAN, owner = Owner.NB, - receiver = Order.Receiver(name = "name", address = "address"), + address = Order.Address( + name = "name", + addressLine1 = "addressLine1", + addressLine2 = "addressLine2", + zipcode = "zipcode", + city = "city", + state = "state" + ), + contactPerson = "named person", callbackUrl = "https://callback.com/order" ) @@ -539,7 +562,8 @@ class OrderControllerTest( orderLine = orderLine.map { it.toOrderItem() }, orderType = orderType, owner = Owner.NB, - receiver = receiver.toOrderReceiver(), + address = address, + contactPerson = contactPerson, callbackUrl = callbackUrl ) } diff --git a/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelConversionTest.kt b/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelConversionTest.kt index 41fa9a26..c96fa8b8 100644 --- a/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelConversionTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelConversionTest.kt @@ -2,10 +2,8 @@ package no.nb.mlt.wls.order.model import no.nb.mlt.wls.application.hostapi.order.ApiOrderPayload import no.nb.mlt.wls.application.hostapi.order.OrderLine -import no.nb.mlt.wls.application.hostapi.order.Receiver import no.nb.mlt.wls.application.hostapi.order.toApiOrderLine import no.nb.mlt.wls.application.hostapi.order.toApiOrderPayload -import no.nb.mlt.wls.application.hostapi.order.toReceiver import no.nb.mlt.wls.domain.model.HostName import no.nb.mlt.wls.domain.model.Order import no.nb.mlt.wls.domain.model.Owner @@ -28,7 +26,15 @@ class OrderModelConversionTest { status = null, orderLine = listOf(), orderType = Order.Type.LOAN, - receiver = Receiver(name = "name", address = "address"), + contactPerson = "contactPerson", + address = Order.Address( + name = "name", + addressLine1 = "address", + addressLine2 = "street", + zipcode = "zipcode", + city = "city", + state = "state" + ), callbackUrl = "callbackUrl" ) @@ -40,10 +46,15 @@ class OrderModelConversionTest { orderLine = listOf(Order.OrderItem("hostItemId", Order.OrderItem.Status.NOT_STARTED)), orderType = Order.Type.LOAN, owner = Owner.NB, - receiver = - Order.Receiver( + contactPerson = "contactPerson", + address = + Order.Address( name = "name", - address = "address" + addressLine1 = "address", + addressLine2 = "street", + zipcode = "zipcode", + city = "city", + state = "state" ), callbackUrl = "callbackUrl" ) @@ -76,7 +87,15 @@ class OrderModelConversionTest { orderLine = listOf(Order.OrderItem("hostItemId", Order.OrderItem.Status.NOT_STARTED)), orderType = Order.Type.LOAN, owner = Owner.NB, - receiver = Order.Receiver(name = "name", address = "address"), + address = Order.Address( + name = "name", + addressLine1 = "address", + addressLine2 = "street", + city = "city", + state = "state", + zipcode = "zipcode", + ), + contactPerson = "contactPerson", callbackUrl = "callbackUrl" ) @@ -89,7 +108,8 @@ class OrderModelConversionTest { assertThat(payload.status).isEqualTo(testOrder.status) assertThat(payload.orderLine[0].hostId).isEqualTo(testOrder.orderLine[0].hostId) assertThat(payload.orderType).isEqualTo(testOrder.orderType) - assertThat(payload.receiver.name).isEqualTo(testOrder.receiver.name) + assertThat(payload.contactPerson).isEqualTo(testOrder.contactPerson) + assertThat(payload.address).isEqualTo(testOrder.address) assertThat(payload.callbackUrl).isEqualTo(testOrder.callbackUrl) } @@ -103,7 +123,8 @@ class OrderModelConversionTest { assertThat(mongoOrder.orderLine[0].hostId).isEqualTo(testOrder.orderLine[0].hostId) assertThat(mongoOrder.orderType).isEqualTo(testOrder.orderType) assertThat(mongoOrder.owner).isEqualTo(testOrder.owner) - assertThat(mongoOrder.receiver.name).isEqualTo(testOrder.receiver.name) + assertThat(mongoOrder.contactPerson).isEqualTo(testOrder.contactPerson) + assertThat(mongoOrder.address).isEqualTo(testOrder.address) assertThat(mongoOrder.callbackUrl).isEqualTo(testOrder.callbackUrl) } @@ -129,7 +150,7 @@ class OrderModelConversionTest { assertThat(testNotificationOrderPayload.orderLine[0].hostId).isEqualTo(testOrderNotification.orderLine[0].hostId) assertThat(testNotificationOrderPayload.orderType).isEqualTo(testOrderNotification.orderType) assertThat(testNotificationOrderPayload.owner).isEqualTo(testOrderNotification.owner) - assertThat(testNotificationOrderPayload.receiver.name).isEqualTo(testOrderNotification.receiver.name) + assertThat(testNotificationOrderPayload.address).isEqualTo(testOrderNotification.address) assertThat(testNotificationOrderPayload.callbackUrl).isEqualTo(testOrderNotification.callbackUrl) } @@ -142,7 +163,8 @@ class OrderModelConversionTest { assertThat(order.status).isEqualTo(Order.Status.NOT_STARTED) assertThat(order.orderLine).isEqualTo(testApiOrderPayload.orderLine) assertThat(order.orderType).isEqualTo(testApiOrderPayload.orderType) - assertThat(order.receiver.name).isEqualTo(testApiOrderPayload.receiver.name) + assertThat(order.contactPerson).isEqualTo(testApiOrderPayload.contactPerson) + assertThat(order.address).isEqualTo(testApiOrderPayload.address) assertThat(order.callbackUrl).isEqualTo(testApiOrderPayload.callbackUrl) } @@ -185,37 +207,7 @@ class OrderModelConversionTest { assertThat(orderLine.status).isEqualTo(testOrderItem.status) } - private val testReceiver = - Receiver( - name = "name", - address = "address" - ) - - private val testOrderReceiver = - Order.Receiver( - name = "name", - address = "address" - ) - - @Test - fun `Receiver converts to OrderReceiver`() { - val orderReceiver = testReceiver.toOrderReceiver() - - assertThat(orderReceiver.name).isEqualTo(testReceiver.name) - assertThat(orderReceiver.address).isEqualTo(testReceiver.address) - - val orderReceiver2 = testReceiver.copy(address = null).toOrderReceiver() - - assertThat(orderReceiver2.address).isEqualTo("") - } - - @Test - fun `OrderReceiver converts to Receiver`() { - val receiver = testOrderReceiver.toReceiver() - - assertThat(receiver.name).isEqualTo(testOrderReceiver.name) - assertThat(receiver.address).isEqualTo(testOrderReceiver.address) - } + // TODO - Add tests for converting addresses between Order and payloads private fun ApiOrderPayload.toOrder() = Order( @@ -225,7 +217,8 @@ class OrderModelConversionTest { orderLine = orderLine.map { it.toOrderItem() }, orderType = orderType, owner = Owner.NB, - receiver = receiver.toOrderReceiver(), + contactPerson = contactPerson, + address = address, callbackUrl = callbackUrl ) } diff --git a/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelValidationTest.kt b/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelValidationTest.kt index 997c158c..41d90a07 100644 --- a/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelValidationTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelValidationTest.kt @@ -3,7 +3,6 @@ package no.nb.mlt.wls.order.model import no.nb.mlt.wls.application.hostapi.order.ApiOrderPayload import no.nb.mlt.wls.application.hostapi.order.ApiUpdateOrderPayload import no.nb.mlt.wls.application.hostapi.order.OrderLine -import no.nb.mlt.wls.application.hostapi.order.Receiver import no.nb.mlt.wls.domain.model.HostName import no.nb.mlt.wls.domain.model.Order import no.nb.mlt.wls.domain.ports.inbound.ValidationException @@ -35,44 +34,10 @@ class OrderModelValidationTest { } // ///////////////////////////////////////////////////////////////////////////// -// //////////////////////////////// Receiver /////////////////////////////////// +// ///////////////////////////////// Address /////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////// - @Test - fun `valid receiver should pass validation`() { - thenCode(validReceiver::validate).doesNotThrowAnyException() - } - - @Test - fun `receiver with no address should pass validation`() { - val receiver = validReceiver.copy(address = null) - - thenCode(receiver::validate).doesNotThrowAnyException() - } - - @Test - fun `receiver with blank name should fail validation`() { - val receiver = validReceiver.copy(name = "") - - val thrown = catchThrowable(receiver::validate) - - then(thrown) - .isNotNull() - .isInstanceOf(ValidationException::class.java) - .hasMessageContaining("name") - } - - @Test - fun `receiver with blank address should fail validation`() { - val receiver = validReceiver.copy(address = "") - - val thrown = catchThrowable(receiver::validate) - - then(thrown) - .isNotNull() - .isInstanceOf(ValidationException::class.java) - .hasMessageContaining("address") - } + // TODO - Add Address field tests // ///////////////////////////////////////////////////////////////////////////// // ////////////////////////////////// Order //////////////////////////////////// @@ -131,17 +96,7 @@ class OrderModelValidationTest { .hasMessageContaining("order line's") } - @Test - fun `order with invalid receiver should fail validation`() { - val order = validOrder.copy(receiver = Receiver(name = "", address = null)) - - val thrown = catchThrowable(order::validate) - - then(thrown) - .isNotNull() - .isInstanceOf(ValidationException::class.java) - .hasMessageContaining("name") - } + // TODO - Test for address // ///////////////////////////////////////////////////////////////////////////// // /////////////////////////////// OrderUpdate // ////////////////////////////// @@ -200,17 +155,7 @@ class OrderModelValidationTest { .hasMessageContaining("order line's") } - @Test - fun `update order with invalid receiver should fail validation`() { - val order = validUpdateOrderPayload.copy(receiver = Receiver(name = "", address = null)) - - val thrown = catchThrowable(order::validate) - - then(thrown) - .isNotNull() - .isInstanceOf(ValidationException::class.java) - .hasMessageContaining("receiver name") - } + // TODO - Test Address // ///////////////////////////////////////////////////////////////////////////// // //////////////////////////////// Test Help ////////////////////////////////// @@ -218,7 +163,14 @@ class OrderModelValidationTest { val validOrderLine = OrderLine("item-123", Order.OrderItem.Status.NOT_STARTED) - val validReceiver = Receiver(name = "name", address = "address") + val validAddress = Order.Address( + name = "real name", + addressLine1 = "real street", + addressLine2 = null, + zipcode = "12345-WA", + city = "england", + state = "cornwall", + ) val validOrder = ApiOrderPayload( @@ -227,7 +179,8 @@ class OrderModelValidationTest { status = Order.Status.NOT_STARTED, orderLine = listOf(validOrderLine), orderType = Order.Type.LOAN, - receiver = validReceiver, + address = validAddress, + contactPerson = "contactPerson", callbackUrl = "https://callback.com/order" ) @@ -237,7 +190,8 @@ class OrderModelValidationTest { hostOrderId = "order-123", orderLine = listOf(validOrderLine), orderType = Order.Type.LOAN, - receiver = validReceiver, + contactPerson = "contactPerson", + address = validAddress, callbackUrl = "https://callback.com/order" ) } diff --git a/src/test/kotlin/no/nb/mlt/wls/synq/controller/SynqControllerTest.kt b/src/test/kotlin/no/nb/mlt/wls/synq/controller/SynqControllerTest.kt index a16ae7f9..4a6ccd6c 100644 --- a/src/test/kotlin/no/nb/mlt/wls/synq/controller/SynqControllerTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/synq/controller/SynqControllerTest.kt @@ -391,10 +391,15 @@ class SynqControllerTest( orderLine = listOf(Order.OrderItem(item1.hostId, Order.OrderItem.Status.NOT_STARTED)), orderType = Order.Type.LOAN, owner = Owner.NB, - receiver = - Order.Receiver( + contactPerson = "contactPerson", + address = + Order.Address( name = "name", - address = "address" + addressLine1 = "addressLine1", + null, + null, + null, + null ), callbackUrl = "https://callback.com/order" ) From 4c96bef943ba0e5d9e718185788685eb50450b10 Mon Sep 17 00:00:00 2001 From: Noah Bjerkli Aanonli Date: Thu, 28 Nov 2024 15:20:57 +0100 Subject: [PATCH 04/22] Checkstyle --- .../hostapi/order/ApiOrderPayload.kt | 1 - .../no/nb/mlt/wls/domain/model/Order.kt | 2 +- .../no/nb/mlt/wls/domain/WLSServiceTest.kt | 2 +- .../order/controller/OrderControllerTest.kt | 51 ++++++++++--------- .../order/model/OrderModelConversionTest.kt | 34 +++++++------ .../order/model/OrderModelValidationTest.kt | 17 ++++--- 6 files changed, 56 insertions(+), 51 deletions(-) diff --git a/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiOrderPayload.kt b/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiOrderPayload.kt index bd727640..47d94f7c 100644 --- a/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiOrderPayload.kt +++ b/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiOrderPayload.kt @@ -157,4 +157,3 @@ data class OrderLine( } fun Order.OrderItem.toApiOrderLine() = OrderLine(hostId, status) - diff --git a/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt b/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt index b05fe1f6..f7c5e1c4 100644 --- a/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt +++ b/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt @@ -160,7 +160,7 @@ data class Order( val addressLine2: String?, val zipcode: String?, val city: String?, - val state: String?, + val state: String? ) { fun validate() { if (name?.isBlank() == true) { diff --git a/src/test/kotlin/no/nb/mlt/wls/domain/WLSServiceTest.kt b/src/test/kotlin/no/nb/mlt/wls/domain/WLSServiceTest.kt index e3729897..1aad1127 100644 --- a/src/test/kotlin/no/nb/mlt/wls/domain/WLSServiceTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/domain/WLSServiceTest.kt @@ -346,7 +346,7 @@ class WLSServiceTest { listOf("mlt-420", "mlt-421"), testOrder.orderType, testOrder.contactPerson, - testOrder.address?: Order.Address.create(), + testOrder.address ?: Order.Address.create(), testOrder.callbackUrl ) } diff --git a/src/test/kotlin/no/nb/mlt/wls/order/controller/OrderControllerTest.kt b/src/test/kotlin/no/nb/mlt/wls/order/controller/OrderControllerTest.kt index 24b41076..7afabd1a 100644 --- a/src/test/kotlin/no/nb/mlt/wls/order/controller/OrderControllerTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/order/controller/OrderControllerTest.kt @@ -464,14 +464,15 @@ class OrderControllerTest( status = Order.Status.NOT_STARTED, orderLine = listOf(OrderLine("item-123", Order.OrderItem.Status.NOT_STARTED)), orderType = Order.Type.LOAN, - address = Order.Address( - name = "name", - addressLine1 = "addressLine1", - addressLine2 = "addressLine2", - zipcode = "zipcode", - city = "city", - state = "state" - ), + address = + Order.Address( + name = "name", + addressLine1 = "addressLine1", + addressLine2 = "addressLine2", + zipcode = "zipcode", + city = "city", + state = "state" + ), contactPerson = "named person", callbackUrl = "https://callback.com/order" ) @@ -487,14 +488,15 @@ class OrderControllerTest( status = Order.Status.NOT_STARTED, orderLine = listOf(OrderLine("item-456", Order.OrderItem.Status.NOT_STARTED)), orderType = Order.Type.LOAN, - address = Order.Address( - name = "name", - addressLine1 = "addressLine1", - addressLine2 = "addressLine2", - zipcode = "zipcode", - city = "city", - state = "state" - ), + address = + Order.Address( + name = "name", + addressLine1 = "addressLine1", + addressLine2 = "addressLine2", + zipcode = "zipcode", + city = "city", + state = "state" + ), contactPerson = "named person", callbackUrl = "https://callback.com/order" ) @@ -507,14 +509,15 @@ class OrderControllerTest( orderLine = listOf(Order.OrderItem("item-123", Order.OrderItem.Status.NOT_STARTED)), orderType = Order.Type.LOAN, owner = Owner.NB, - address = Order.Address( - name = "name", - addressLine1 = "addressLine1", - addressLine2 = "addressLine2", - zipcode = "zipcode", - city = "city", - state = "state" - ), + address = + Order.Address( + name = "name", + addressLine1 = "addressLine1", + addressLine2 = "addressLine2", + zipcode = "zipcode", + city = "city", + state = "state" + ), contactPerson = "named person", callbackUrl = "https://callback.com/order" ) diff --git a/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelConversionTest.kt b/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelConversionTest.kt index c96fa8b8..45deed2c 100644 --- a/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelConversionTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelConversionTest.kt @@ -27,14 +27,15 @@ class OrderModelConversionTest { orderLine = listOf(), orderType = Order.Type.LOAN, contactPerson = "contactPerson", - address = Order.Address( - name = "name", - addressLine1 = "address", - addressLine2 = "street", - zipcode = "zipcode", - city = "city", - state = "state" - ), + address = + Order.Address( + name = "name", + addressLine1 = "address", + addressLine2 = "street", + zipcode = "zipcode", + city = "city", + state = "state" + ), callbackUrl = "callbackUrl" ) @@ -87,14 +88,15 @@ class OrderModelConversionTest { orderLine = listOf(Order.OrderItem("hostItemId", Order.OrderItem.Status.NOT_STARTED)), orderType = Order.Type.LOAN, owner = Owner.NB, - address = Order.Address( - name = "name", - addressLine1 = "address", - addressLine2 = "street", - city = "city", - state = "state", - zipcode = "zipcode", - ), + address = + Order.Address( + name = "name", + addressLine1 = "address", + addressLine2 = "street", + city = "city", + state = "state", + zipcode = "zipcode" + ), contactPerson = "contactPerson", callbackUrl = "callbackUrl" ) diff --git a/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelValidationTest.kt b/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelValidationTest.kt index 41d90a07..70b539b2 100644 --- a/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelValidationTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelValidationTest.kt @@ -163,14 +163,15 @@ class OrderModelValidationTest { val validOrderLine = OrderLine("item-123", Order.OrderItem.Status.NOT_STARTED) - val validAddress = Order.Address( - name = "real name", - addressLine1 = "real street", - addressLine2 = null, - zipcode = "12345-WA", - city = "england", - state = "cornwall", - ) + val validAddress = + Order.Address( + name = "real name", + addressLine1 = "real street", + addressLine2 = null, + zipcode = "12345-WA", + city = "england", + state = "cornwall" + ) val validOrder = ApiOrderPayload( From 129e1902f19cfe6811b87779f5f8d5be4706d317 Mon Sep 17 00:00:00 2001 From: Noah Bjerkli Aanonli Date: Fri, 29 Nov 2024 08:59:26 +0100 Subject: [PATCH 05/22] Add tests for address Removes companion helper function (create) A test for converting address for OrderModel was not added, since they use the exact same type --- .../no/nb/mlt/wls/domain/model/Order.kt | 16 ++----- .../no/nb/mlt/wls/domain/WLSServiceTest.kt | 10 ++-- .../order/model/OrderModelConversionTest.kt | 2 - .../order/model/OrderModelValidationTest.kt | 46 +++++++++++++++++-- 4 files changed, 55 insertions(+), 19 deletions(-) diff --git a/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt b/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt index f7c5e1c4..84b949a0 100644 --- a/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt +++ b/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt @@ -164,28 +164,22 @@ data class Order( ) { fun validate() { if (name?.isBlank() == true) { - throw ValidationException("Name must not be blank") + throw ValidationException("Invalid address: name must not be blank") } if (addressLine1?.isBlank() == true) { - throw ValidationException("Address line must not be blank") + throw ValidationException("Invalid address: address line must not be blank") } if (addressLine2?.isBlank() == true) { - throw ValidationException("Address line must not be blank") + throw ValidationException("Invalid address: address line must not be blank") } if (zipcode?.isBlank() == true) { - throw ValidationException("Zipcode can not be blank") + throw ValidationException("Invalid address: zipcode must not be blank") } if (city?.isBlank() == true) { - throw ValidationException("City must not be blank") + throw ValidationException("Invalid address: city must not be blank") } // TODO - Validate State/Region/County? } - - companion object { - fun create(): Address { - return Address(null, null, null, null, null, null) - } - } } enum class Status { diff --git a/src/test/kotlin/no/nb/mlt/wls/domain/WLSServiceTest.kt b/src/test/kotlin/no/nb/mlt/wls/domain/WLSServiceTest.kt index 1aad1127..84abf212 100644 --- a/src/test/kotlin/no/nb/mlt/wls/domain/WLSServiceTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/domain/WLSServiceTest.kt @@ -319,7 +319,7 @@ class WLSServiceTest { listOf("mlt-420", "mlt-421"), Order.Type.LOAN, "unreal person", - Order.Address.create(), + createOrderAddress(), "https://example.com" ) @@ -346,7 +346,7 @@ class WLSServiceTest { listOf("mlt-420", "mlt-421"), testOrder.orderType, testOrder.contactPerson, - testOrder.address ?: Order.Address.create(), + testOrder.address ?: createOrderAddress(), testOrder.callbackUrl ) } @@ -428,7 +428,7 @@ class WLSServiceTest { orderType = Order.Type.LOAN, owner = Owner.NB, contactPerson = "contactPerson", - address = Order.Address.create(), + address = createOrderAddress(), callbackUrl = "https://callback.com/order" ) @@ -460,4 +460,8 @@ class WLSServiceTest { address = testOrder.address, callbackUrl = testOrder.callbackUrl ) + + fun createOrderAddress(): Order.Address { + return Order.Address(null, null, null, null, null, null) + } } diff --git a/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelConversionTest.kt b/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelConversionTest.kt index 45deed2c..ca544175 100644 --- a/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelConversionTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelConversionTest.kt @@ -209,8 +209,6 @@ class OrderModelConversionTest { assertThat(orderLine.status).isEqualTo(testOrderItem.status) } - // TODO - Add tests for converting addresses between Order and payloads - private fun ApiOrderPayload.toOrder() = Order( hostName = hostName, diff --git a/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelValidationTest.kt b/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelValidationTest.kt index 70b539b2..92038df2 100644 --- a/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelValidationTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelValidationTest.kt @@ -37,7 +37,28 @@ class OrderModelValidationTest { // ///////////////////////////////// Address /////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////// - // TODO - Add Address field tests + @Test + fun `valid address should pass validation`() { + thenCode(validAddress::validate).doesNotThrowAnyException() + } + + @Test + fun `address with blank fields should fail validation`() { + val invalidAddress = validAddress.copy(name = "") + val invalidCityAddress = validAddress.copy(city = "") + + val error = catchThrowable(invalidAddress::validate) + then(error) + .isNotNull() + .isInstanceOf(ValidationException::class.java) + .hasMessageContaining("name must not") + + val anotherError = catchThrowable(invalidCityAddress::validate) + then(anotherError) + .isNotNull() + .isInstanceOf(ValidationException::class.java) + .hasMessageContaining("city must not") + } // ///////////////////////////////////////////////////////////////////////////// // ////////////////////////////////// Order //////////////////////////////////// @@ -96,7 +117,17 @@ class OrderModelValidationTest { .hasMessageContaining("order line's") } - // TODO - Test for address + @Test + fun `order with invalid address should fail validation`() { + val order = validOrder.copy(address = validAddress.copy(name = "")) + + val thrown = catchThrowable(order::validate) + + then(thrown) + .isNotNull() + .isInstanceOf(ValidationException::class.java) + .hasMessageContaining("Invalid address") + } // ///////////////////////////////////////////////////////////////////////////// // /////////////////////////////// OrderUpdate // ////////////////////////////// @@ -155,8 +186,17 @@ class OrderModelValidationTest { .hasMessageContaining("order line's") } - // TODO - Test Address + @Test + fun `update order with invalid address should fail validation`() { + val order = validUpdateOrderPayload.copy(address = validAddress.copy(name = "")) + val thrown = catchThrowable(order::validate) + + then(thrown) + .isNotNull() + .isInstanceOf(ValidationException::class.java) + .hasMessageContaining("address") + } // ///////////////////////////////////////////////////////////////////////////// // //////////////////////////////// Test Help ////////////////////////////////// // ///////////////////////////////////////////////////////////////////////////// From 9b6ed6b86da4a2828f263089b7e062f05f81c57b Mon Sep 17 00:00:00 2001 From: Noah Bjerkli Aanonli Date: Fri, 29 Nov 2024 10:47:51 +0100 Subject: [PATCH 06/22] Add SwaggerDoc and TODO --- .../hostapi/order/ApiOrderPayload.kt | 30 +++++++++++++++---- .../no/nb/mlt/wls/domain/model/Order.kt | 1 + 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiOrderPayload.kt b/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiOrderPayload.kt index 47d94f7c..ce3ad476 100644 --- a/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiOrderPayload.kt +++ b/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiOrderPayload.kt @@ -24,9 +24,13 @@ import java.net.URI ], "orderType": "LOAN", "owner": "NB", - "receiver": { - "name": "Doug Dimmadome", - "address": "Dimmsdale Dimmadome, 21st Ave. Texas" + "contactPerson": "Hermes the Great", + "address": { + "name": "Nasjonalbibliotekaren", + "addressLine1": "Henrik Ibsens gate 110", + "city": "Oslo", + "country": "Norway", + "zipcode": "0255" }, "callbackUrl": "https://example.com/send/callback/here" } @@ -58,10 +62,24 @@ data class ApiOrderPayload( examples = ["LOAN", "DIGITIZATION"] ) val orderType: Order.Type, - // TODO - Swaggerdoc + @Schema( + description = "The name of the person to contact with manners related to this order", + example = "Hermes" + ) val contactPerson: String, - // TODO - Swaggerdoc - // TODO - Should this use Order Address or custom DTO? + // TODO - Should this use custom DTO? + @Schema( + description = "The delivery address of this order", + example = """ + "address": { + "name": "Nasjonalbibliotekaren", + "addressLine1": "Henrik Ibsens gate 110", + "city": "Oslo", + "country": "Norway", + "zipcode": "0255" + } + """ + ) val address: Order.Address?, @Schema( description = "Callback URL for the order used to update the order information in the host system.", diff --git a/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt b/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt index 84b949a0..0c4da682 100644 --- a/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt +++ b/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt @@ -154,6 +154,7 @@ data class Order( } } + // TODO - Add country field data class Address( val name: String?, val addressLine1: String?, From 69acc95cd8beeeee70e3aedd49678bda60463d0b Mon Sep 17 00:00:00 2001 From: Noah Bjerkli Aanonli Date: Fri, 29 Nov 2024 13:50:42 +0100 Subject: [PATCH 07/22] Add Country to Order.Address --- .../hostapi/order/ApiUpdateOrderPayload.kt | 12 ++++++++++++ src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt | 7 +++++-- .../kotlin/no/nb/mlt/wls/domain/WLSServiceTest.kt | 2 +- .../mlt/wls/order/controller/OrderControllerTest.kt | 9 ++++++--- .../mlt/wls/order/model/OrderModelConversionTest.kt | 9 ++++++--- .../mlt/wls/order/model/OrderModelValidationTest.kt | 3 ++- .../nb/mlt/wls/synq/controller/SynqControllerTest.kt | 1 + 7 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiUpdateOrderPayload.kt b/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiUpdateOrderPayload.kt index 5fbf5cb8..506d12f8 100644 --- a/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiUpdateOrderPayload.kt +++ b/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiUpdateOrderPayload.kt @@ -54,6 +54,18 @@ data class ApiUpdateOrderPayload( description = "Who's the receiver of the material in the order." ) val contactPerson: String, + @Schema( + description = "The delivery address of the order", + example = """ + "address": { + "name": "Nasjonalbibliotekaren", + "addressLine1": "Henrik Ibsens gate 110", + "city": "Oslo", + "country": "Norway", + "zipcode": "0255" + } + """ + ) val address: Order.Address?, @Schema( description = "URL to send a callback to when the order is completed.", diff --git a/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt b/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt index 0c4da682..77d80598 100644 --- a/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt +++ b/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt @@ -154,14 +154,14 @@ data class Order( } } - // TODO - Add country field data class Address( val name: String?, val addressLine1: String?, val addressLine2: String?, val zipcode: String?, val city: String?, - val state: String? + val state: String?, + val country: String? ) { fun validate() { if (name?.isBlank() == true) { @@ -179,6 +179,9 @@ data class Order( if (city?.isBlank() == true) { throw ValidationException("Invalid address: city must not be blank") } + if (country?.isBlank() == true) { + throw ValidationException("Invalid address: country must not be blank") + } // TODO - Validate State/Region/County? } } diff --git a/src/test/kotlin/no/nb/mlt/wls/domain/WLSServiceTest.kt b/src/test/kotlin/no/nb/mlt/wls/domain/WLSServiceTest.kt index 84abf212..984c3065 100644 --- a/src/test/kotlin/no/nb/mlt/wls/domain/WLSServiceTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/domain/WLSServiceTest.kt @@ -462,6 +462,6 @@ class WLSServiceTest { ) fun createOrderAddress(): Order.Address { - return Order.Address(null, null, null, null, null, null) + return Order.Address(null, null, null, null, null, null, null) } } diff --git a/src/test/kotlin/no/nb/mlt/wls/order/controller/OrderControllerTest.kt b/src/test/kotlin/no/nb/mlt/wls/order/controller/OrderControllerTest.kt index 7afabd1a..01a883c2 100644 --- a/src/test/kotlin/no/nb/mlt/wls/order/controller/OrderControllerTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/order/controller/OrderControllerTest.kt @@ -471,7 +471,8 @@ class OrderControllerTest( addressLine2 = "addressLine2", zipcode = "zipcode", city = "city", - state = "state" + state = "state", + country = "country" ), contactPerson = "named person", callbackUrl = "https://callback.com/order" @@ -495,7 +496,8 @@ class OrderControllerTest( addressLine2 = "addressLine2", zipcode = "zipcode", city = "city", - state = "state" + state = "state", + country = "country" ), contactPerson = "named person", callbackUrl = "https://callback.com/order" @@ -516,7 +518,8 @@ class OrderControllerTest( addressLine2 = "addressLine2", zipcode = "zipcode", city = "city", - state = "state" + state = "state", + country = "country" ), contactPerson = "named person", callbackUrl = "https://callback.com/order" diff --git a/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelConversionTest.kt b/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelConversionTest.kt index ca544175..79c10cb2 100644 --- a/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelConversionTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelConversionTest.kt @@ -34,7 +34,8 @@ class OrderModelConversionTest { addressLine2 = "street", zipcode = "zipcode", city = "city", - state = "state" + state = "state", + country = "country" ), callbackUrl = "callbackUrl" ) @@ -55,7 +56,8 @@ class OrderModelConversionTest { addressLine2 = "street", zipcode = "zipcode", city = "city", - state = "state" + state = "state", + country = "country" ), callbackUrl = "callbackUrl" ) @@ -95,7 +97,8 @@ class OrderModelConversionTest { addressLine2 = "street", city = "city", state = "state", - zipcode = "zipcode" + zipcode = "zipcode", + country = "country" ), contactPerson = "contactPerson", callbackUrl = "callbackUrl" diff --git a/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelValidationTest.kt b/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelValidationTest.kt index 92038df2..b3c2ac44 100644 --- a/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelValidationTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelValidationTest.kt @@ -210,7 +210,8 @@ class OrderModelValidationTest { addressLine2 = null, zipcode = "12345-WA", city = "england", - state = "cornwall" + state = "cornwall", + country = "london" ) val validOrder = diff --git a/src/test/kotlin/no/nb/mlt/wls/synq/controller/SynqControllerTest.kt b/src/test/kotlin/no/nb/mlt/wls/synq/controller/SynqControllerTest.kt index 4a6ccd6c..c749d9f3 100644 --- a/src/test/kotlin/no/nb/mlt/wls/synq/controller/SynqControllerTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/synq/controller/SynqControllerTest.kt @@ -399,6 +399,7 @@ class SynqControllerTest( null, null, null, + null, null ), callbackUrl = "https://callback.com/order" From a4f385bb9ead8915e6413a6ac631e9b0fed2d381 Mon Sep 17 00:00:00 2001 From: Noah Bjerkli Aanonli Date: Fri, 29 Nov 2024 14:17:22 +0100 Subject: [PATCH 08/22] Update schemas with address --- docker/mongo/mongo-init.js | 10 ++++++++-- .../hostapi/order/ApiUpdateOrderPayload.kt | 11 ++++++++--- .../callbacks/NotificationOrderPayload.kt | 10 ++++++++-- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/docker/mongo/mongo-init.js b/docker/mongo/mongo-init.js index 18b73e87..cde2990b 100644 --- a/docker/mongo/mongo-init.js +++ b/docker/mongo/mongo-init.js @@ -55,9 +55,15 @@ db.orders.insertOne({ ], "orderType": "LOAN", "owner": "NB", - "receiver": { + "contactPerson": "MLT Team", + "address": { "name": "Doug Doug", - "address": "Somewhere in the United States" + "addressLine1": "Somewhere", + "addressLine2": "Behind a cardboard box", + "city": "Las Vegas", + "country": "United States", + "state": "Texas", + "zipcode": "TX-55415" }, "callbackUrl": "https://example.com/send/callback/here", "_class": "no.nb.mlt.wls.infrastructure.repositories.order.MongoOrder" diff --git a/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiUpdateOrderPayload.kt b/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiUpdateOrderPayload.kt index 506d12f8..23601c29 100644 --- a/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiUpdateOrderPayload.kt +++ b/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiUpdateOrderPayload.kt @@ -21,10 +21,15 @@ import kotlin.jvm.Throws } ], "orderType": "LOAN", - "receiver": { + "contactPerson": "MLT Team", + "address": { "name": "Doug Dimmadome", - "address": "Dimmsdale Dimmadome, 21st Ave. Texas" - }, + "addressLine1": "Dimmsdale Dimmadome", + "addressLine2": "21st Texan Ave.", + "city": "Dimmsdale", + "country": "United States", + "state": "California", + "zipcode": "CA-55415" "callbackUrl": "https://example.com/send/callback/here" } """ diff --git a/src/main/kotlin/no/nb/mlt/wls/infrastructure/callbacks/NotificationOrderPayload.kt b/src/main/kotlin/no/nb/mlt/wls/infrastructure/callbacks/NotificationOrderPayload.kt index 21b7f7b5..3e8d29c6 100644 --- a/src/main/kotlin/no/nb/mlt/wls/infrastructure/callbacks/NotificationOrderPayload.kt +++ b/src/main/kotlin/no/nb/mlt/wls/infrastructure/callbacks/NotificationOrderPayload.kt @@ -20,9 +20,15 @@ import no.nb.mlt.wls.domain.model.Owner ], "orderType": "LOAN", "owner": "NB", - "receiver": { + "contactPerson": "MLT Team", + "address": { "name": "Doug Dimmadome", - "address": "Dimmsdale Dimmadome, 21st Ave. Texas" + "addressLine1": "Dimmsdale Dimmadome", + "addressLine2": "21st Texan Ave.", + "city": "Dimmsdale", + "country": "United States", + "state": "California", + "zipcode": "CA-55415" }, "callbackUrl": "https://example.com/send/callback/here" } From dafc04af64ed37f71ec5d50cfce9fcd22fdaa8a0 Mon Sep 17 00:00:00 2001 From: Noah Bjerkli Aanonli Date: Fri, 29 Nov 2024 14:42:53 +0100 Subject: [PATCH 09/22] Actually allow updating address --- src/main/kotlin/no/nb/mlt/wls/domain/WLSService.kt | 9 ++++++++- src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/no/nb/mlt/wls/domain/WLSService.kt b/src/main/kotlin/no/nb/mlt/wls/domain/WLSService.kt index baba7ca6..3cffadfd 100644 --- a/src/main/kotlin/no/nb/mlt/wls/domain/WLSService.kt +++ b/src/main/kotlin/no/nb/mlt/wls/domain/WLSService.kt @@ -164,7 +164,14 @@ class WLSService( val order = getOrderOrThrow(hostName, hostOrderId) - val updatedOrder = order.updateOrder(itemHostIds, callbackUrl, orderType, contactPerson) + val updatedOrder = + order.updateOrder( + itemHostIds, + callbackUrl, + orderType, + address ?: order.address, + contactPerson + ) val result = storageSystemFacade.updateOrder(updatedOrder) return orderRepository.updateOrder(result) } diff --git a/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt b/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt index 77d80598..e078c9f9 100644 --- a/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt +++ b/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt @@ -1,5 +1,6 @@ package no.nb.mlt.wls.domain.model +import no.nb.mlt.wls.domain.model.Order.Address import no.nb.mlt.wls.domain.model.Order.OrderItem.Status.FAILED import no.nb.mlt.wls.domain.model.Order.OrderItem.Status.PICKED import no.nb.mlt.wls.domain.ports.inbound.IllegalOrderStateException @@ -99,6 +100,7 @@ data class Order( itemIds: List, callbackUrl: String, orderType: Type, + address: Address?, contactPerson: String ): Order { throwIfInProgress() @@ -106,9 +108,12 @@ data class Order( return this.setOrderLines(itemIds) .setCallbackUrl(callbackUrl) .setOrderType(orderType) + .setAddress(address) .setContactPerson(contactPerson) } + private fun setAddress(address: Address?): Order = this.copy(address = address ?: createOrderAddress()) + /** * Delete the order as long as it is possible. * @@ -203,3 +208,5 @@ data class Order( fun Order.OrderItem.isPickedOrFailed(): Boolean { return this.status == PICKED || this.status == FAILED } + +fun createOrderAddress(): Order.Address = Address(null, null, null, null, null, null, null) From c16a472495976bcee04a9dcb3a3df78ab84c4f6e Mon Sep 17 00:00:00 2001 From: Noah Bjerkli Aanonli Date: Fri, 29 Nov 2024 14:43:13 +0100 Subject: [PATCH 10/22] Validate State --- src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt b/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt index e078c9f9..60d217ec 100644 --- a/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt +++ b/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt @@ -184,10 +184,12 @@ data class Order( if (city?.isBlank() == true) { throw ValidationException("Invalid address: city must not be blank") } + if (state?.isBlank() == true) { + throw ValidationException("Invalid address: state must not be blank") + } if (country?.isBlank() == true) { throw ValidationException("Invalid address: country must not be blank") } - // TODO - Validate State/Region/County? } } From 59eed75620e11b6ab502aed31fc1cb78b4aecfec Mon Sep 17 00:00:00 2001 From: Noah Bjerkli Aanonli Date: Fri, 29 Nov 2024 14:46:46 +0100 Subject: [PATCH 11/22] Send shipping address to SynQ --- .../infrastructure/synq/SynqOrderPayload.kt | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/no/nb/mlt/wls/infrastructure/synq/SynqOrderPayload.kt b/src/main/kotlin/no/nb/mlt/wls/infrastructure/synq/SynqOrderPayload.kt index 7ccabd23..d9d0cc8a 100644 --- a/src/main/kotlin/no/nb/mlt/wls/infrastructure/synq/SynqOrderPayload.kt +++ b/src/main/kotlin/no/nb/mlt/wls/infrastructure/synq/SynqOrderPayload.kt @@ -40,14 +40,19 @@ data class SynqOrderPayload( } } -// TODO - Should this be expanded with more fields? data class ShippingAddress( val address: Address ) { + // TODO - Should all the fields here be annotated? data class Address( val contactPerson: String, @JsonInclude(JsonInclude.Include.NON_NULL) - val addressLine1: String? = null + val addressLine1: String? = null, + val addressLine2: String? = null, + val city: String? = null, + val state: String? = null, + val country: String? = null, + val postalCode: String? = null ) } @@ -72,8 +77,13 @@ fun Order.toSynqPayload() = shippingAddress = ShippingAddress( ShippingAddress.Address( - contactPerson, - address?.addressLine1 + contactPerson = contactPerson, + addressLine1 = address?.addressLine1, + addressLine2 = address?.addressLine2, + city = address?.city, + state = address?.state, + country = address?.country, + postalCode = address?.zipcode ) ) ) From 3f726f2d77a142c0198d2158184dbd2131e801b4 Mon Sep 17 00:00:00 2001 From: Noah Bjerkli Aanonli Date: Fri, 29 Nov 2024 15:21:31 +0100 Subject: [PATCH 12/22] Rename Order.Address State -> Region --- docker/mongo/mongo-init.js | 2 +- .../wls/application/hostapi/order/ApiUpdateOrderPayload.kt | 5 ++++- src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt | 6 +++--- .../no/nb/mlt/wls/infrastructure/synq/SynqOrderPayload.kt | 2 +- .../no/nb/mlt/wls/order/controller/OrderControllerTest.kt | 6 +++--- .../no/nb/mlt/wls/order/model/OrderModelConversionTest.kt | 6 +++--- .../no/nb/mlt/wls/order/model/OrderModelValidationTest.kt | 2 +- 7 files changed, 16 insertions(+), 13 deletions(-) diff --git a/docker/mongo/mongo-init.js b/docker/mongo/mongo-init.js index cde2990b..f3d0eb2b 100644 --- a/docker/mongo/mongo-init.js +++ b/docker/mongo/mongo-init.js @@ -62,7 +62,7 @@ db.orders.insertOne({ "addressLine2": "Behind a cardboard box", "city": "Las Vegas", "country": "United States", - "state": "Texas", + "region": "Texas", "zipcode": "TX-55415" }, "callbackUrl": "https://example.com/send/callback/here", diff --git a/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiUpdateOrderPayload.kt b/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiUpdateOrderPayload.kt index 23601c29..6eed1e78 100644 --- a/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiUpdateOrderPayload.kt +++ b/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiUpdateOrderPayload.kt @@ -60,7 +60,10 @@ data class ApiUpdateOrderPayload( ) val contactPerson: String, @Schema( - description = "The delivery address of the order", + description = """ + The delivery address of the order. + If delivering to a country with states (I.E. the United States), include the state name in the region. + """, example = """ "address": { "name": "Nasjonalbibliotekaren", diff --git a/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt b/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt index 60d217ec..0b7e3af4 100644 --- a/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt +++ b/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt @@ -165,7 +165,7 @@ data class Order( val addressLine2: String?, val zipcode: String?, val city: String?, - val state: String?, + val region: String?, val country: String? ) { fun validate() { @@ -184,8 +184,8 @@ data class Order( if (city?.isBlank() == true) { throw ValidationException("Invalid address: city must not be blank") } - if (state?.isBlank() == true) { - throw ValidationException("Invalid address: state must not be blank") + if (region?.isBlank() == true) { + throw ValidationException("Invalid address: region must not be blank") } if (country?.isBlank() == true) { throw ValidationException("Invalid address: country must not be blank") diff --git a/src/main/kotlin/no/nb/mlt/wls/infrastructure/synq/SynqOrderPayload.kt b/src/main/kotlin/no/nb/mlt/wls/infrastructure/synq/SynqOrderPayload.kt index d9d0cc8a..1cc6029e 100644 --- a/src/main/kotlin/no/nb/mlt/wls/infrastructure/synq/SynqOrderPayload.kt +++ b/src/main/kotlin/no/nb/mlt/wls/infrastructure/synq/SynqOrderPayload.kt @@ -81,7 +81,7 @@ fun Order.toSynqPayload() = addressLine1 = address?.addressLine1, addressLine2 = address?.addressLine2, city = address?.city, - state = address?.state, + state = address?.region, country = address?.country, postalCode = address?.zipcode ) diff --git a/src/test/kotlin/no/nb/mlt/wls/order/controller/OrderControllerTest.kt b/src/test/kotlin/no/nb/mlt/wls/order/controller/OrderControllerTest.kt index 01a883c2..24c9869c 100644 --- a/src/test/kotlin/no/nb/mlt/wls/order/controller/OrderControllerTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/order/controller/OrderControllerTest.kt @@ -471,7 +471,7 @@ class OrderControllerTest( addressLine2 = "addressLine2", zipcode = "zipcode", city = "city", - state = "state", + region = "region", country = "country" ), contactPerson = "named person", @@ -496,7 +496,7 @@ class OrderControllerTest( addressLine2 = "addressLine2", zipcode = "zipcode", city = "city", - state = "state", + region = "region", country = "country" ), contactPerson = "named person", @@ -518,7 +518,7 @@ class OrderControllerTest( addressLine2 = "addressLine2", zipcode = "zipcode", city = "city", - state = "state", + region = "region", country = "country" ), contactPerson = "named person", diff --git a/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelConversionTest.kt b/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelConversionTest.kt index 79c10cb2..2d042cc3 100644 --- a/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelConversionTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelConversionTest.kt @@ -34,7 +34,7 @@ class OrderModelConversionTest { addressLine2 = "street", zipcode = "zipcode", city = "city", - state = "state", + region = "region", country = "country" ), callbackUrl = "callbackUrl" @@ -56,7 +56,7 @@ class OrderModelConversionTest { addressLine2 = "street", zipcode = "zipcode", city = "city", - state = "state", + region = "region", country = "country" ), callbackUrl = "callbackUrl" @@ -96,7 +96,7 @@ class OrderModelConversionTest { addressLine1 = "address", addressLine2 = "street", city = "city", - state = "state", + region = "region", zipcode = "zipcode", country = "country" ), diff --git a/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelValidationTest.kt b/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelValidationTest.kt index b3c2ac44..7f801d7c 100644 --- a/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelValidationTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelValidationTest.kt @@ -210,7 +210,7 @@ class OrderModelValidationTest { addressLine2 = null, zipcode = "12345-WA", city = "england", - state = "cornwall", + region = "cornwall", country = "london" ) From 7608cbb38d160392b06ce2b1a0ac8c5ddc149ef3 Mon Sep 17 00:00:00 2001 From: Noah Bjerkli Aanonli Date: Fri, 29 Nov 2024 15:29:46 +0100 Subject: [PATCH 13/22] Rename Order.Address Zipcode -> Postcode Also rename a few remaining "state" entries --- docker/mongo/mongo-init.js | 2 +- .../nb/mlt/wls/application/hostapi/order/ApiOrderPayload.kt | 4 ++-- .../wls/application/hostapi/order/ApiUpdateOrderPayload.kt | 6 +++--- src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt | 6 +++--- .../infrastructure/callbacks/NotificationOrderPayload.kt | 4 ++-- .../no/nb/mlt/wls/infrastructure/synq/SynqOrderPayload.kt | 2 +- .../no/nb/mlt/wls/order/controller/OrderControllerTest.kt | 6 +++--- .../no/nb/mlt/wls/order/model/OrderModelConversionTest.kt | 6 +++--- .../no/nb/mlt/wls/order/model/OrderModelValidationTest.kt | 2 +- 9 files changed, 19 insertions(+), 19 deletions(-) diff --git a/docker/mongo/mongo-init.js b/docker/mongo/mongo-init.js index f3d0eb2b..6426eb51 100644 --- a/docker/mongo/mongo-init.js +++ b/docker/mongo/mongo-init.js @@ -63,7 +63,7 @@ db.orders.insertOne({ "city": "Las Vegas", "country": "United States", "region": "Texas", - "zipcode": "TX-55415" + "postcode": "TX-55415" }, "callbackUrl": "https://example.com/send/callback/here", "_class": "no.nb.mlt.wls.infrastructure.repositories.order.MongoOrder" diff --git a/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiOrderPayload.kt b/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiOrderPayload.kt index ce3ad476..f7eade03 100644 --- a/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiOrderPayload.kt +++ b/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiOrderPayload.kt @@ -30,7 +30,7 @@ import java.net.URI "addressLine1": "Henrik Ibsens gate 110", "city": "Oslo", "country": "Norway", - "zipcode": "0255" + "postcode": "0255" }, "callbackUrl": "https://example.com/send/callback/here" } @@ -76,7 +76,7 @@ data class ApiOrderPayload( "addressLine1": "Henrik Ibsens gate 110", "city": "Oslo", "country": "Norway", - "zipcode": "0255" + "postcode": "0255" } """ ) diff --git a/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiUpdateOrderPayload.kt b/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiUpdateOrderPayload.kt index 6eed1e78..a7714faa 100644 --- a/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiUpdateOrderPayload.kt +++ b/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiUpdateOrderPayload.kt @@ -28,8 +28,8 @@ import kotlin.jvm.Throws "addressLine2": "21st Texan Ave.", "city": "Dimmsdale", "country": "United States", - "state": "California", - "zipcode": "CA-55415" + "region": "California", + "postcode": "CA-55415" "callbackUrl": "https://example.com/send/callback/here" } """ @@ -70,7 +70,7 @@ data class ApiUpdateOrderPayload( "addressLine1": "Henrik Ibsens gate 110", "city": "Oslo", "country": "Norway", - "zipcode": "0255" + "postcode": "0255" } """ ) diff --git a/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt b/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt index 0b7e3af4..6fa8789f 100644 --- a/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt +++ b/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt @@ -163,7 +163,7 @@ data class Order( val name: String?, val addressLine1: String?, val addressLine2: String?, - val zipcode: String?, + val postcode: String?, val city: String?, val region: String?, val country: String? @@ -178,8 +178,8 @@ data class Order( if (addressLine2?.isBlank() == true) { throw ValidationException("Invalid address: address line must not be blank") } - if (zipcode?.isBlank() == true) { - throw ValidationException("Invalid address: zipcode must not be blank") + if (postcode?.isBlank() == true) { + throw ValidationException("Invalid address: postcode must not be blank") } if (city?.isBlank() == true) { throw ValidationException("Invalid address: city must not be blank") diff --git a/src/main/kotlin/no/nb/mlt/wls/infrastructure/callbacks/NotificationOrderPayload.kt b/src/main/kotlin/no/nb/mlt/wls/infrastructure/callbacks/NotificationOrderPayload.kt index 3e8d29c6..2b6b92a7 100644 --- a/src/main/kotlin/no/nb/mlt/wls/infrastructure/callbacks/NotificationOrderPayload.kt +++ b/src/main/kotlin/no/nb/mlt/wls/infrastructure/callbacks/NotificationOrderPayload.kt @@ -27,8 +27,8 @@ import no.nb.mlt.wls.domain.model.Owner "addressLine2": "21st Texan Ave.", "city": "Dimmsdale", "country": "United States", - "state": "California", - "zipcode": "CA-55415" + "region": "California", + "postcode": "CA-55415" }, "callbackUrl": "https://example.com/send/callback/here" } diff --git a/src/main/kotlin/no/nb/mlt/wls/infrastructure/synq/SynqOrderPayload.kt b/src/main/kotlin/no/nb/mlt/wls/infrastructure/synq/SynqOrderPayload.kt index 1cc6029e..b802f3bb 100644 --- a/src/main/kotlin/no/nb/mlt/wls/infrastructure/synq/SynqOrderPayload.kt +++ b/src/main/kotlin/no/nb/mlt/wls/infrastructure/synq/SynqOrderPayload.kt @@ -83,7 +83,7 @@ fun Order.toSynqPayload() = city = address?.city, state = address?.region, country = address?.country, - postalCode = address?.zipcode + postalCode = address?.postcode ) ) ) diff --git a/src/test/kotlin/no/nb/mlt/wls/order/controller/OrderControllerTest.kt b/src/test/kotlin/no/nb/mlt/wls/order/controller/OrderControllerTest.kt index 24c9869c..a593558b 100644 --- a/src/test/kotlin/no/nb/mlt/wls/order/controller/OrderControllerTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/order/controller/OrderControllerTest.kt @@ -469,7 +469,7 @@ class OrderControllerTest( name = "name", addressLine1 = "addressLine1", addressLine2 = "addressLine2", - zipcode = "zipcode", + postcode = "postcode", city = "city", region = "region", country = "country" @@ -494,7 +494,7 @@ class OrderControllerTest( name = "name", addressLine1 = "addressLine1", addressLine2 = "addressLine2", - zipcode = "zipcode", + postcode = "postcode", city = "city", region = "region", country = "country" @@ -516,7 +516,7 @@ class OrderControllerTest( name = "name", addressLine1 = "addressLine1", addressLine2 = "addressLine2", - zipcode = "zipcode", + postcode = "postcode", city = "city", region = "region", country = "country" diff --git a/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelConversionTest.kt b/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelConversionTest.kt index 2d042cc3..0e0be0ea 100644 --- a/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelConversionTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelConversionTest.kt @@ -32,7 +32,7 @@ class OrderModelConversionTest { name = "name", addressLine1 = "address", addressLine2 = "street", - zipcode = "zipcode", + postcode = "postcode", city = "city", region = "region", country = "country" @@ -54,7 +54,7 @@ class OrderModelConversionTest { name = "name", addressLine1 = "address", addressLine2 = "street", - zipcode = "zipcode", + postcode = "postcode", city = "city", region = "region", country = "country" @@ -97,7 +97,7 @@ class OrderModelConversionTest { addressLine2 = "street", city = "city", region = "region", - zipcode = "zipcode", + postcode = "postcode", country = "country" ), contactPerson = "contactPerson", diff --git a/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelValidationTest.kt b/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelValidationTest.kt index 7f801d7c..74dc340c 100644 --- a/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelValidationTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelValidationTest.kt @@ -208,7 +208,7 @@ class OrderModelValidationTest { name = "real name", addressLine1 = "real street", addressLine2 = null, - zipcode = "12345-WA", + postcode = "12345-WA", city = "england", region = "cornwall", country = "london" From 68823dd76c9b22b261ce5174eb9b92b7c85930a1 Mon Sep 17 00:00:00 2001 From: Noah Bjerkli Aanonli Date: Mon, 2 Dec 2024 08:59:56 +0100 Subject: [PATCH 14/22] Introduce note field in domain model --- .../wls/application/hostapi/order/ApiOrderPayload.kt | 7 +++++++ .../hostapi/order/ApiUpdateOrderPayload.kt | 5 +++++ .../wls/application/hostapi/order/OrderController.kt | 1 + src/main/kotlin/no/nb/mlt/wls/domain/WLSService.kt | 12 +++++++----- src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt | 7 +++++++ .../nb/mlt/wls/domain/ports/inbound/CreateOrder.kt | 2 ++ .../nb/mlt/wls/domain/ports/inbound/UpdateOrder.kt | 1 + .../infrastructure/repositories/order/MongoOrder.kt | 3 +++ 8 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiOrderPayload.kt b/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiOrderPayload.kt index f7eade03..dc4ce015 100644 --- a/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiOrderPayload.kt +++ b/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiOrderPayload.kt @@ -67,6 +67,11 @@ data class ApiOrderPayload( example = "Hermes" ) val contactPerson: String, + @Schema( + description = "Any notes about the order", + example = "This is required in four weeks time" + ) + val note: String?, // TODO - Should this use custom DTO? @Schema( description = "The delivery address of this order", @@ -96,6 +101,7 @@ data class ApiOrderPayload( owner = owner, address = address, contactPerson = contactPerson, + note = note, callbackUrl = callbackUrl ) @@ -138,6 +144,7 @@ fun Order.toApiOrderPayload() = orderType = orderType, contactPerson = contactPerson, address = address, + note = note, callbackUrl = callbackUrl ) diff --git a/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiUpdateOrderPayload.kt b/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiUpdateOrderPayload.kt index a7714faa..b4716bf9 100644 --- a/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiUpdateOrderPayload.kt +++ b/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiUpdateOrderPayload.kt @@ -75,6 +75,11 @@ data class ApiUpdateOrderPayload( """ ) val address: Order.Address?, + @Schema( + description = "Any notes about the order", + example = "This is required in four weeks time" + ) + val note: String?, @Schema( description = "URL to send a callback to when the order is completed.", example = "https://example.com/send/callback/here" diff --git a/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/OrderController.kt b/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/OrderController.kt index cb011e9e..c2e0414b 100644 --- a/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/OrderController.kt +++ b/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/OrderController.kt @@ -256,6 +256,7 @@ class OrderController( orderType = payload.orderType, contactPerson = payload.contactPerson, address = payload.address, + note = payload.note, callbackUrl = payload.callbackUrl ) diff --git a/src/main/kotlin/no/nb/mlt/wls/domain/WLSService.kt b/src/main/kotlin/no/nb/mlt/wls/domain/WLSService.kt index 3cffadfd..58461dbc 100644 --- a/src/main/kotlin/no/nb/mlt/wls/domain/WLSService.kt +++ b/src/main/kotlin/no/nb/mlt/wls/domain/WLSService.kt @@ -155,6 +155,7 @@ class WLSService( orderType: Order.Type, contactPerson: String, address: Order.Address?, + note: String?, callbackUrl: String ): Order { val itemIds = itemHostIds.map { ItemId(hostName, it) } @@ -166,11 +167,12 @@ class WLSService( val updatedOrder = order.updateOrder( - itemHostIds, - callbackUrl, - orderType, - address ?: order.address, - contactPerson + itemIds = itemHostIds, + callbackUrl = callbackUrl, + orderType = orderType, + address = address ?: order.address, + note = note, + contactPerson = contactPerson ) val result = storageSystemFacade.updateOrder(updatedOrder) return orderRepository.updateOrder(result) diff --git a/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt b/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt index 6fa8789f..9b1c88b2 100644 --- a/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt +++ b/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt @@ -16,6 +16,7 @@ data class Order( val owner: Owner, val address: Address?, val contactPerson: String, + val note: String?, val callbackUrl: String ) { private fun setOrderLines(listOfHostIds: List): Order { @@ -101,6 +102,7 @@ data class Order( callbackUrl: String, orderType: Type, address: Address?, + note: String?, contactPerson: String ): Order { throwIfInProgress() @@ -109,9 +111,14 @@ data class Order( .setCallbackUrl(callbackUrl) .setOrderType(orderType) .setAddress(address) + .setNote(note) .setContactPerson(contactPerson) } + private fun setNote(note: String?): Order { + return this.copy(note = note) + } + private fun setAddress(address: Address?): Order = this.copy(address = address ?: createOrderAddress()) /** diff --git a/src/main/kotlin/no/nb/mlt/wls/domain/ports/inbound/CreateOrder.kt b/src/main/kotlin/no/nb/mlt/wls/domain/ports/inbound/CreateOrder.kt index 87d1309f..3fbf5841 100644 --- a/src/main/kotlin/no/nb/mlt/wls/domain/ports/inbound/CreateOrder.kt +++ b/src/main/kotlin/no/nb/mlt/wls/domain/ports/inbound/CreateOrder.kt @@ -16,6 +16,7 @@ data class CreateOrderDTO( val owner: Owner, val contactPerson: String, val address: Order.Address?, + val note: String?, val callbackUrl: String ) { data class OrderItem( @@ -36,6 +37,7 @@ fun CreateOrderDTO.toOrder(): Order { owner = owner, contactPerson = contactPerson, address = address, + note = note, callbackUrl = callbackUrl ) } diff --git a/src/main/kotlin/no/nb/mlt/wls/domain/ports/inbound/UpdateOrder.kt b/src/main/kotlin/no/nb/mlt/wls/domain/ports/inbound/UpdateOrder.kt index 6c9a8e4a..dfee16d3 100644 --- a/src/main/kotlin/no/nb/mlt/wls/domain/ports/inbound/UpdateOrder.kt +++ b/src/main/kotlin/no/nb/mlt/wls/domain/ports/inbound/UpdateOrder.kt @@ -14,6 +14,7 @@ interface UpdateOrder { orderType: Order.Type, contactPerson: String, address: Order.Address?, + note: String?, callbackUrl: String ): Order } diff --git a/src/main/kotlin/no/nb/mlt/wls/infrastructure/repositories/order/MongoOrder.kt b/src/main/kotlin/no/nb/mlt/wls/infrastructure/repositories/order/MongoOrder.kt index acdbbab7..ca74ced2 100644 --- a/src/main/kotlin/no/nb/mlt/wls/infrastructure/repositories/order/MongoOrder.kt +++ b/src/main/kotlin/no/nb/mlt/wls/infrastructure/repositories/order/MongoOrder.kt @@ -21,6 +21,7 @@ data class MongoOrder( val owner: Owner, val contactPerson: String, val address: Order.Address?, + val note: String?, val callbackUrl: String ) @@ -34,6 +35,7 @@ fun Order.toMongoOrder(): MongoOrder { owner = owner, contactPerson = contactPerson, address = address, + note = note, callbackUrl = callbackUrl ) } @@ -48,6 +50,7 @@ fun MongoOrder.toOrder(): Order { owner = owner, contactPerson = contactPerson, address = address, + note = note, callbackUrl = callbackUrl ) } From 58285e3148312524af40f03f990d8b540daa80f9 Mon Sep 17 00:00:00 2001 From: Noah Bjerkli Aanonli Date: Mon, 2 Dec 2024 12:39:29 +0100 Subject: [PATCH 15/22] Update tests to include notes --- .../kotlin/no/nb/mlt/wls/domain/WLSServiceTest.kt | 13 +++++++++---- .../mlt/wls/order/controller/OrderControllerTest.kt | 4 ++++ .../mlt/wls/order/model/OrderModelConversionTest.kt | 9 ++++++--- .../mlt/wls/order/model/OrderModelValidationTest.kt | 6 ++++-- .../mlt/wls/synq/controller/SynqControllerTest.kt | 3 ++- 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/test/kotlin/no/nb/mlt/wls/domain/WLSServiceTest.kt b/src/test/kotlin/no/nb/mlt/wls/domain/WLSServiceTest.kt index 984c3065..da3ff1e8 100644 --- a/src/test/kotlin/no/nb/mlt/wls/domain/WLSServiceTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/domain/WLSServiceTest.kt @@ -207,7 +207,7 @@ class WLSServiceTest { val cut = WLSService(itemRepoMock, orderRepoMock, storageSystemRepoMock, inventoryNotifierMock) runTest { - val order = cut.createOrder(testOrder.toCreateOrderDTO()) + val order = cut.createOrder(createOrderDTO) assertThat(order).isEqualTo(expectedOrder) @@ -226,7 +226,7 @@ class WLSServiceTest { runTest { val order = cut.createOrder( - testOrder.toCreateOrderDTO().copy(callbackUrl = "https://newurl.com") + createOrderDTO.copy(callbackUrl = "https://newurl.com") ) assertThat(order).isEqualTo(testOrder) @@ -245,7 +245,7 @@ class WLSServiceTest { val cut = WLSService(itemRepoMock, orderRepoMock, storageSystemRepoMock, inventoryNotifierMock) runTest { assertThrows { - cut.createOrder(testOrder.toCreateOrderDTO()) + cut.createOrder(createOrderDTO) } coVerify(exactly = 0) { orderRepoMock.createOrder(any()) } coVerify(exactly = 0) { storageSystemRepoMock.createOrder(any()) } @@ -320,6 +320,7 @@ class WLSServiceTest { Order.Type.LOAN, "unreal person", createOrderAddress(), + "note", "https://example.com" ) @@ -347,6 +348,7 @@ class WLSServiceTest { testOrder.orderType, testOrder.contactPerson, testOrder.address ?: createOrderAddress(), + testOrder.note, testOrder.callbackUrl ) } @@ -371,6 +373,7 @@ class WLSServiceTest { testOrder.orderType, testOrder.contactPerson, testOrder.address, + testOrder.note, testOrder.callbackUrl ) } @@ -429,6 +432,7 @@ class WLSServiceTest { owner = Owner.NB, contactPerson = "contactPerson", address = createOrderAddress(), + note = "note", callbackUrl = "https://callback.com/order" ) @@ -449,7 +453,7 @@ class WLSServiceTest { "Somewhere nice" ) - private fun Order.toCreateOrderDTO() = + private val createOrderDTO = CreateOrderDTO( hostName = testOrder.hostName, hostOrderId = testOrder.hostOrderId, @@ -458,6 +462,7 @@ class WLSServiceTest { owner = testOrder.owner, contactPerson = testOrder.contactPerson, address = testOrder.address, + note = testOrder.note, callbackUrl = testOrder.callbackUrl ) diff --git a/src/test/kotlin/no/nb/mlt/wls/order/controller/OrderControllerTest.kt b/src/test/kotlin/no/nb/mlt/wls/order/controller/OrderControllerTest.kt index a593558b..116c797e 100644 --- a/src/test/kotlin/no/nb/mlt/wls/order/controller/OrderControllerTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/order/controller/OrderControllerTest.kt @@ -475,6 +475,7 @@ class OrderControllerTest( country = "country" ), contactPerson = "named person", + note = "note", callbackUrl = "https://callback.com/order" ) @@ -500,6 +501,7 @@ class OrderControllerTest( country = "country" ), contactPerson = "named person", + note = "note", callbackUrl = "https://callback.com/order" ) @@ -522,6 +524,7 @@ class OrderControllerTest( country = "country" ), contactPerson = "named person", + note = "note", callbackUrl = "https://callback.com/order" ) @@ -570,6 +573,7 @@ class OrderControllerTest( owner = Owner.NB, address = address, contactPerson = contactPerson, + note = note, callbackUrl = callbackUrl ) } diff --git a/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelConversionTest.kt b/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelConversionTest.kt index 0e0be0ea..01c61aec 100644 --- a/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelConversionTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelConversionTest.kt @@ -37,7 +37,8 @@ class OrderModelConversionTest { region = "region", country = "country" ), - callbackUrl = "callbackUrl" + callbackUrl = "callbackUrl", + note = "note" ) private val testOrder = @@ -59,7 +60,8 @@ class OrderModelConversionTest { region = "region", country = "country" ), - callbackUrl = "callbackUrl" + callbackUrl = "callbackUrl", + note = "note" ) private val testSynqOrderPayload = @@ -222,6 +224,7 @@ class OrderModelConversionTest { owner = Owner.NB, contactPerson = contactPerson, address = address, - callbackUrl = callbackUrl + callbackUrl = callbackUrl, + note = note ) } diff --git a/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelValidationTest.kt b/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelValidationTest.kt index 74dc340c..a2a42dbe 100644 --- a/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelValidationTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelValidationTest.kt @@ -223,7 +223,8 @@ class OrderModelValidationTest { orderType = Order.Type.LOAN, address = validAddress, contactPerson = "contactPerson", - callbackUrl = "https://callback.com/order" + callbackUrl = "https://callback.com/order", + note = "note" ) val validUpdateOrderPayload = @@ -234,6 +235,7 @@ class OrderModelValidationTest { orderType = Order.Type.LOAN, contactPerson = "contactPerson", address = validAddress, - callbackUrl = "https://callback.com/order" + callbackUrl = "https://callback.com/order", + note = "note" ) } diff --git a/src/test/kotlin/no/nb/mlt/wls/synq/controller/SynqControllerTest.kt b/src/test/kotlin/no/nb/mlt/wls/synq/controller/SynqControllerTest.kt index c749d9f3..97744af5 100644 --- a/src/test/kotlin/no/nb/mlt/wls/synq/controller/SynqControllerTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/synq/controller/SynqControllerTest.kt @@ -402,7 +402,8 @@ class SynqControllerTest( null, null ), - callbackUrl = "https://callback.com/order" + callbackUrl = "https://callback.com/order", + note = "note" ) private val orderStatusUpdatePayload = From 369e255469b91aba2e7b3acac6c9b3a61a15695d Mon Sep 17 00:00:00 2001 From: Noah Bjerkli Aanonli Date: Mon, 2 Dec 2024 13:01:08 +0100 Subject: [PATCH 16/22] Update Swagger schemas --- .../no/nb/mlt/wls/application/hostapi/order/ApiOrderPayload.kt | 1 + .../mlt/wls/application/hostapi/order/ApiUpdateOrderPayload.kt | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiOrderPayload.kt b/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiOrderPayload.kt index dc4ce015..8547576f 100644 --- a/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiOrderPayload.kt +++ b/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiOrderPayload.kt @@ -32,6 +32,7 @@ import java.net.URI "country": "Norway", "postcode": "0255" }, + "note": "Handle with care", "callbackUrl": "https://example.com/send/callback/here" } """ diff --git a/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiUpdateOrderPayload.kt b/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiUpdateOrderPayload.kt index b4716bf9..7e147732 100644 --- a/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiUpdateOrderPayload.kt +++ b/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiUpdateOrderPayload.kt @@ -30,6 +30,8 @@ import kotlin.jvm.Throws "country": "United States", "region": "California", "postcode": "CA-55415" + }, + "note": "Handle with care", "callbackUrl": "https://example.com/send/callback/here" } """ From 1fd0c49a88a8379a0c54a4c0cc21e37178e13527 Mon Sep 17 00:00:00 2001 From: Noah Bjerkli Aanonli Date: Mon, 2 Dec 2024 14:13:13 +0100 Subject: [PATCH 17/22] Rename Order.Address name -> recipient --- docker/mongo/mongo-init.js | 2 +- .../mlt/wls/application/hostapi/order/ApiOrderPayload.kt | 4 ++-- .../application/hostapi/order/ApiUpdateOrderPayload.kt | 4 ++-- src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt | 8 ++++---- .../infrastructure/callbacks/NotificationOrderPayload.kt | 2 +- .../no/nb/mlt/wls/order/controller/OrderControllerTest.kt | 6 +++--- .../no/nb/mlt/wls/order/model/OrderModelConversionTest.kt | 6 +++--- .../no/nb/mlt/wls/order/model/OrderModelValidationTest.kt | 8 ++++---- .../no/nb/mlt/wls/synq/controller/SynqControllerTest.kt | 2 +- 9 files changed, 21 insertions(+), 21 deletions(-) diff --git a/docker/mongo/mongo-init.js b/docker/mongo/mongo-init.js index 6426eb51..8c0fb2a4 100644 --- a/docker/mongo/mongo-init.js +++ b/docker/mongo/mongo-init.js @@ -57,7 +57,7 @@ db.orders.insertOne({ "owner": "NB", "contactPerson": "MLT Team", "address": { - "name": "Doug Doug", + "recipient": "Doug Doug", "addressLine1": "Somewhere", "addressLine2": "Behind a cardboard box", "city": "Las Vegas", diff --git a/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiOrderPayload.kt b/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiOrderPayload.kt index 8547576f..1b69640d 100644 --- a/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiOrderPayload.kt +++ b/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiOrderPayload.kt @@ -26,7 +26,7 @@ import java.net.URI "owner": "NB", "contactPerson": "Hermes the Great", "address": { - "name": "Nasjonalbibliotekaren", + "recipient": "Nasjonalbibliotekaren", "addressLine1": "Henrik Ibsens gate 110", "city": "Oslo", "country": "Norway", @@ -78,7 +78,7 @@ data class ApiOrderPayload( description = "The delivery address of this order", example = """ "address": { - "name": "Nasjonalbibliotekaren", + "recipient": "Nasjonalbibliotekaren", "addressLine1": "Henrik Ibsens gate 110", "city": "Oslo", "country": "Norway", diff --git a/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiUpdateOrderPayload.kt b/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiUpdateOrderPayload.kt index 7e147732..da57f081 100644 --- a/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiUpdateOrderPayload.kt +++ b/src/main/kotlin/no/nb/mlt/wls/application/hostapi/order/ApiUpdateOrderPayload.kt @@ -23,7 +23,7 @@ import kotlin.jvm.Throws "orderType": "LOAN", "contactPerson": "MLT Team", "address": { - "name": "Doug Dimmadome", + "recipient": "Doug Dimmadome", "addressLine1": "Dimmsdale Dimmadome", "addressLine2": "21st Texan Ave.", "city": "Dimmsdale", @@ -68,7 +68,7 @@ data class ApiUpdateOrderPayload( """, example = """ "address": { - "name": "Nasjonalbibliotekaren", + "recipient": "Nasjonalbibliotekaren", "addressLine1": "Henrik Ibsens gate 110", "city": "Oslo", "country": "Norway", diff --git a/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt b/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt index 9b1c88b2..0367a03a 100644 --- a/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt +++ b/src/main/kotlin/no/nb/mlt/wls/domain/model/Order.kt @@ -167,7 +167,7 @@ data class Order( } data class Address( - val name: String?, + val recipient: String?, val addressLine1: String?, val addressLine2: String?, val postcode: String?, @@ -176,8 +176,8 @@ data class Order( val country: String? ) { fun validate() { - if (name?.isBlank() == true) { - throw ValidationException("Invalid address: name must not be blank") + if (recipient?.isBlank() == true) { + throw ValidationException("Invalid address: recipient must not be blank") } if (addressLine1?.isBlank() == true) { throw ValidationException("Invalid address: address line must not be blank") @@ -218,4 +218,4 @@ fun Order.OrderItem.isPickedOrFailed(): Boolean { return this.status == PICKED || this.status == FAILED } -fun createOrderAddress(): Order.Address = Address(null, null, null, null, null, null, null) +fun createOrderAddress(): Address = Address(null, null, null, null, null, null, null) diff --git a/src/main/kotlin/no/nb/mlt/wls/infrastructure/callbacks/NotificationOrderPayload.kt b/src/main/kotlin/no/nb/mlt/wls/infrastructure/callbacks/NotificationOrderPayload.kt index 2b6b92a7..4b02d547 100644 --- a/src/main/kotlin/no/nb/mlt/wls/infrastructure/callbacks/NotificationOrderPayload.kt +++ b/src/main/kotlin/no/nb/mlt/wls/infrastructure/callbacks/NotificationOrderPayload.kt @@ -22,7 +22,7 @@ import no.nb.mlt.wls.domain.model.Owner "owner": "NB", "contactPerson": "MLT Team", "address": { - "name": "Doug Dimmadome", + "recipient": "Doug Dimmadome", "addressLine1": "Dimmsdale Dimmadome", "addressLine2": "21st Texan Ave.", "city": "Dimmsdale", diff --git a/src/test/kotlin/no/nb/mlt/wls/order/controller/OrderControllerTest.kt b/src/test/kotlin/no/nb/mlt/wls/order/controller/OrderControllerTest.kt index 116c797e..162b460b 100644 --- a/src/test/kotlin/no/nb/mlt/wls/order/controller/OrderControllerTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/order/controller/OrderControllerTest.kt @@ -466,7 +466,7 @@ class OrderControllerTest( orderType = Order.Type.LOAN, address = Order.Address( - name = "name", + recipient = "recipient", addressLine1 = "addressLine1", addressLine2 = "addressLine2", postcode = "postcode", @@ -492,7 +492,7 @@ class OrderControllerTest( orderType = Order.Type.LOAN, address = Order.Address( - name = "name", + recipient = "recipient", addressLine1 = "addressLine1", addressLine2 = "addressLine2", postcode = "postcode", @@ -515,7 +515,7 @@ class OrderControllerTest( owner = Owner.NB, address = Order.Address( - name = "name", + recipient = "recipient", addressLine1 = "addressLine1", addressLine2 = "addressLine2", postcode = "postcode", diff --git a/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelConversionTest.kt b/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelConversionTest.kt index 01c61aec..9ea13d50 100644 --- a/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelConversionTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelConversionTest.kt @@ -29,7 +29,7 @@ class OrderModelConversionTest { contactPerson = "contactPerson", address = Order.Address( - name = "name", + recipient = "recipient", addressLine1 = "address", addressLine2 = "street", postcode = "postcode", @@ -52,7 +52,7 @@ class OrderModelConversionTest { contactPerson = "contactPerson", address = Order.Address( - name = "name", + recipient = "recipient", addressLine1 = "address", addressLine2 = "street", postcode = "postcode", @@ -94,7 +94,7 @@ class OrderModelConversionTest { owner = Owner.NB, address = Order.Address( - name = "name", + recipient = "recipient", addressLine1 = "address", addressLine2 = "street", city = "city", diff --git a/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelValidationTest.kt b/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelValidationTest.kt index a2a42dbe..5c101d49 100644 --- a/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelValidationTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelValidationTest.kt @@ -44,7 +44,7 @@ class OrderModelValidationTest { @Test fun `address with blank fields should fail validation`() { - val invalidAddress = validAddress.copy(name = "") + val invalidAddress = validAddress.copy(recipient = "") val invalidCityAddress = validAddress.copy(city = "") val error = catchThrowable(invalidAddress::validate) @@ -119,7 +119,7 @@ class OrderModelValidationTest { @Test fun `order with invalid address should fail validation`() { - val order = validOrder.copy(address = validAddress.copy(name = "")) + val order = validOrder.copy(address = validAddress.copy(recipient = "")) val thrown = catchThrowable(order::validate) @@ -188,7 +188,7 @@ class OrderModelValidationTest { @Test fun `update order with invalid address should fail validation`() { - val order = validUpdateOrderPayload.copy(address = validAddress.copy(name = "")) + val order = validUpdateOrderPayload.copy(address = validAddress.copy(recipient = "")) val thrown = catchThrowable(order::validate) @@ -205,7 +205,7 @@ class OrderModelValidationTest { val validAddress = Order.Address( - name = "real name", + recipient = "real name", addressLine1 = "real street", addressLine2 = null, postcode = "12345-WA", diff --git a/src/test/kotlin/no/nb/mlt/wls/synq/controller/SynqControllerTest.kt b/src/test/kotlin/no/nb/mlt/wls/synq/controller/SynqControllerTest.kt index 97744af5..261bc955 100644 --- a/src/test/kotlin/no/nb/mlt/wls/synq/controller/SynqControllerTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/synq/controller/SynqControllerTest.kt @@ -394,7 +394,7 @@ class SynqControllerTest( contactPerson = "contactPerson", address = Order.Address( - name = "name", + recipient = "recipient", addressLine1 = "addressLine1", null, null, From 0663f60f0a225b17ae7273948df4df7b9d87bbc0 Mon Sep 17 00:00:00 2001 From: Noah Bjerkli Aanonli Date: Mon, 2 Dec 2024 14:16:01 +0100 Subject: [PATCH 18/22] Fix test --- .../no/nb/mlt/wls/order/model/OrderModelValidationTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelValidationTest.kt b/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelValidationTest.kt index 5c101d49..e9a2145c 100644 --- a/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelValidationTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelValidationTest.kt @@ -51,7 +51,7 @@ class OrderModelValidationTest { then(error) .isNotNull() .isInstanceOf(ValidationException::class.java) - .hasMessageContaining("name must not") + .hasMessageContaining("recipient must not") val anotherError = catchThrowable(invalidCityAddress::validate) then(anotherError) From b36926cca5142288417bcf960a19c7780cc8f7f0 Mon Sep 17 00:00:00 2001 From: Noah Bjerkli Aanonli Date: Thu, 5 Dec 2024 09:15:50 +0100 Subject: [PATCH 19/22] Note that notes in not(e)ifications are noted now --- .../infrastructure/callbacks/NotificationOrderPayload.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/kotlin/no/nb/mlt/wls/infrastructure/callbacks/NotificationOrderPayload.kt b/src/main/kotlin/no/nb/mlt/wls/infrastructure/callbacks/NotificationOrderPayload.kt index 4b02d547..f1e807ea 100644 --- a/src/main/kotlin/no/nb/mlt/wls/infrastructure/callbacks/NotificationOrderPayload.kt +++ b/src/main/kotlin/no/nb/mlt/wls/infrastructure/callbacks/NotificationOrderPayload.kt @@ -72,6 +72,11 @@ data class NotificationOrderPayload( description = "The address of the receiver of the material in the order." ) val address: Order.Address?, + @Schema( + description = "Any notes about the order", + example = "This is required in four weeks time" + ) + val note: String?, @Schema( description = "Callback URL for the order used to update the order information in the host system.", example = "https://example.com/send/callback/here" @@ -89,5 +94,6 @@ fun Order.toNotificationOrderPayload() = owner = owner, contactPerson = contactPerson, address = address, + note = note, callbackUrl = callbackUrl ) From 90642c6181d0855a0886d42cfec11313d3844c5e Mon Sep 17 00:00:00 2001 From: Noah Bjerkli Aanonli Date: Thu, 5 Dec 2024 09:16:50 +0100 Subject: [PATCH 20/22] Only include shipping address if not null --- .../no/nb/mlt/wls/infrastructure/synq/SynqOrderPayload.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/no/nb/mlt/wls/infrastructure/synq/SynqOrderPayload.kt b/src/main/kotlin/no/nb/mlt/wls/infrastructure/synq/SynqOrderPayload.kt index b802f3bb..d81a0582 100644 --- a/src/main/kotlin/no/nb/mlt/wls/infrastructure/synq/SynqOrderPayload.kt +++ b/src/main/kotlin/no/nb/mlt/wls/infrastructure/synq/SynqOrderPayload.kt @@ -43,15 +43,19 @@ data class SynqOrderPayload( data class ShippingAddress( val address: Address ) { - // TODO - Should all the fields here be annotated? data class Address( val contactPerson: String, @JsonInclude(JsonInclude.Include.NON_NULL) val addressLine1: String? = null, + @JsonInclude(JsonInclude.Include.NON_NULL) val addressLine2: String? = null, + @JsonInclude(JsonInclude.Include.NON_NULL) val city: String? = null, + @JsonInclude(JsonInclude.Include.NON_NULL) val state: String? = null, + @JsonInclude(JsonInclude.Include.NON_NULL) val country: String? = null, + @JsonInclude(JsonInclude.Include.NON_NULL) val postalCode: String? = null ) } From 429f62c32b463080e404dd15568f61941504d3cc Mon Sep 17 00:00:00 2001 From: Noah Bjerkli Aanonli Date: Thu, 5 Dec 2024 09:18:39 +0100 Subject: [PATCH 21/22] Improve tests, make linter happy --- docker/compose.yaml | 8 ++++---- .../no/nb/mlt/wls/order/model/OrderModelConversionTest.kt | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/docker/compose.yaml b/docker/compose.yaml index fcd8b24e..e6597b45 100644 --- a/docker/compose.yaml +++ b/docker/compose.yaml @@ -8,7 +8,7 @@ services: MONGO_INITDB_ROOT_PASSWORD: toor MONGO_INITDB_DATABASE: wls ports: - - 27017:27017 + - "27017:27017" volumes: - ./mongo/mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro @@ -18,7 +18,7 @@ services: image: mongo-express:1.0.2 restart: always ports: - - 8081:8081 + - "8081:8081" depends_on: - mongo-db environment: @@ -41,7 +41,7 @@ services: KEYCLOAK_ADMIN: root KEYCLOAK_ADMIN_PASSWORD: toor ports: - - 8082:8080 + - "8082:8080" command: start-dev --import-realm volumes: - ./keycloak/import:/opt/keycloak/data/import @@ -50,4 +50,4 @@ services: image: harbor.nb.no/mlt/dummy-synq:main restart: always ports: - - 8181:8181 + - "8181:8181" diff --git a/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelConversionTest.kt b/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelConversionTest.kt index 9ea13d50..14c5f1fd 100644 --- a/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelConversionTest.kt +++ b/src/test/kotlin/no/nb/mlt/wls/order/model/OrderModelConversionTest.kt @@ -103,6 +103,7 @@ class OrderModelConversionTest { country = "country" ), contactPerson = "contactPerson", + note = "note", callbackUrl = "callbackUrl" ) From 65d621f5ddff0ec84c3e0c38abd1ada615561555 Mon Sep 17 00:00:00 2001 From: Noah Bjerkli Aanonli Date: Tue, 10 Dec 2024 15:31:44 +0100 Subject: [PATCH 22/22] Update Address -> SynQ differently WLS -> SynQ - contactPerson -> Contact Person - recipient -> Address Line 1 - addressLine1 -> Address Line 2 - addressLine2 -> Address Line 3 --- .../no/nb/mlt/wls/infrastructure/synq/SynqOrderPayload.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/no/nb/mlt/wls/infrastructure/synq/SynqOrderPayload.kt b/src/main/kotlin/no/nb/mlt/wls/infrastructure/synq/SynqOrderPayload.kt index d81a0582..6288bb3a 100644 --- a/src/main/kotlin/no/nb/mlt/wls/infrastructure/synq/SynqOrderPayload.kt +++ b/src/main/kotlin/no/nb/mlt/wls/infrastructure/synq/SynqOrderPayload.kt @@ -50,6 +50,8 @@ data class ShippingAddress( @JsonInclude(JsonInclude.Include.NON_NULL) val addressLine2: String? = null, @JsonInclude(JsonInclude.Include.NON_NULL) + val addressLine3: String? = null, + @JsonInclude(JsonInclude.Include.NON_NULL) val city: String? = null, @JsonInclude(JsonInclude.Include.NON_NULL) val state: String? = null, @@ -82,8 +84,9 @@ fun Order.toSynqPayload() = ShippingAddress( ShippingAddress.Address( contactPerson = contactPerson, - addressLine1 = address?.addressLine1, - addressLine2 = address?.addressLine2, + addressLine1 = address?.recipient, + addressLine2 = address?.addressLine1, + addressLine3 = address?.addressLine2, city = address?.city, state = address?.region, country = address?.country,