Skip to content

Commit fb29b12

Browse files
ndido98Giacomo Cavalieri
authored andcommitted
fix(client-orders)!: make api restful
1 parent 7ff601b commit fb29b12

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

client-orders/src/main/scala/dev/atedeg/mdm/clientorders/api/endpoints/Endpoints.scala

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import dev.atedeg.mdm.clientorders.api.*
1212
import dev.atedeg.mdm.clientorders.api.repositories.*
1313
import dev.atedeg.mdm.clientorders.api.services.*
1414
import dev.atedeg.mdm.clientorders.dto.*
15+
import dev.atedeg.mdm.products.dto.*
1516
import dev.atedeg.mdm.utils.monads.*
1617

1718
object OrdersEndpoints:
@@ -27,6 +28,7 @@ object OrdersEndpoints:
2728
.in(jsonBody[OrderReceivedDTO].description("The order that needs to be placed"))
2829
.out(stringBody.description("The ID assigned to the placed order"))
2930
.errorOut(stringBody)
31+
.description("Creates a new order.")
3032

3133
val newOrderRoute: HttpRoutes[IO] = Http4sServerInterpreter[IO]().toRoutes(
3234
newOrderEndpoint.serverLogic { o =>
@@ -36,29 +38,42 @@ object OrdersEndpoints:
3638
)
3739

3840
@SuppressWarnings(Array("org.wartremover.warts.Any"))
39-
val palletizeProductForOrderEndpoint: PublicEndpoint[ProductPalletizedForOrderDTO, String, Unit, Any] =
40-
endpoint.post
41-
.in("order" / "palletize")
42-
.in(jsonBody[ProductPalletizedForOrderDTO].description("The product and quantity palletized for the given order"))
41+
val palletizeProductForOrderEndpoint: PublicEndpoint[(String, ProductWithQuantityDTO), String, Unit, Any] =
42+
endpoint.put
43+
.in("order")
44+
.in(
45+
path[String]
46+
.description("The ID of the order for which the product needs to be palletized")
47+
.name("order-id"),
48+
)
49+
.in("palletize")
50+
.in(jsonBody[ProductWithQuantityDTO].description("The product and quantity palletized for the given order"))
4351
.errorOut(stringBody)
52+
.description("Palletize a product for the given order.")
4453

4554
val palletizeProductForOrderRoute: HttpRoutes[IO] = Http4sServerInterpreter[IO]().toRoutes(
46-
palletizeProductForOrderEndpoint.serverLogic { p =>
47-
val action: ServerAction[Configuration, String, Unit] = productPalletizedForOrderHandler(p)
55+
palletizeProductForOrderEndpoint.serverLogic { case (orderID, ProductWithQuantityDTO(quantity, product)) =>
56+
val action: ServerAction[Configuration, String, Unit] =
57+
productPalletizedForOrderHandler(ProductPalletizedForOrderDTO(orderID, quantity, product))
4858
action.value.run(configuration)
4959
},
5060
)
5161

5262
@SuppressWarnings(Array("org.wartremover.warts.Any"))
53-
val orderCompletedEndpoint: PublicEndpoint[OrderCompletedDTO, String, Unit, Any] =
54-
endpoint.post
55-
.in("order" / "complete")
56-
.in(jsonBody[OrderCompletedDTO].description("The ID of the order that has been completed"))
63+
val orderCompletedEndpoint: PublicEndpoint[String, String, Unit, Any] =
64+
endpoint.put
65+
.in("order")
66+
.in(
67+
path[String]
68+
.description("The ID of the order that has been completed")
69+
.name("order-id"),
70+
)
71+
.in("complete")
5772
.errorOut(stringBody)
5873

5974
val orderCompletedRoute: HttpRoutes[IO] = Http4sServerInterpreter[IO]().toRoutes(
6075
orderCompletedEndpoint.serverLogic { o =>
61-
val action: ServerAction[Configuration, String, Unit] = orderCompletedHandler(o)
76+
val action: ServerAction[Configuration, String, Unit] = orderCompletedHandler(OrderCompletedDTO(o))
6277
action.value.run(configuration)
6378
},
6479
)

client-orders/src/main/scala/dev/atedeg/mdm/clientorders/dto/DTOs.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ final case class LocationDTO(latitude: Double, longitude: Double)
4242
object OrderReceivedDTO:
4343
given DTO[OrderReceived, OrderReceivedDTO] = productTypeDTO
4444

45+
final case class ProductWithQuantityDTO(quantity: Int, product: ProductDTO)
46+
4547
final case class ProductPalletizedForOrderDTO(orderID: String, quantity: Int, product: ProductDTO)
4648
object ProductPalletizedForOrderDTO:
4749
given DTO[ProductPalletizedForOrder, ProductPalletizedForOrderDTO] = productTypeDTO

0 commit comments

Comments
 (0)