chore: add array contains matcher
[demos/example-siren] / provider / src / main / java / io / pactflow / example / sirenprovider / controllers / OrderController.java
index a51184a..b2f1d7f 100644 (file)
@@ -11,39 +11,43 @@ import org.springframework.web.bind.annotation.DeleteMapping;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.PutMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.Random;
+
 import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.afford;
 import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
 import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
 
 @RestController
 @ExposesResourceFor(Order.class)
+@RequestMapping(value = "/orders")
 public class OrderController {
 
-  @GetMapping("/orders")
-  public RepresentationModel<?> orders() {
-    Order order = new Order(1234L);
+  @GetMapping
+  public ResponseEntity<RepresentationModel<?>> orders() {
+    Order order = new Order(new Random().nextLong());
     Link selfLink = linkTo(methodOn(OrderController.class).order(order.getId())).withSelfRel()
       .andAffordance(afford(methodOn(OrderController.class).update(order.getId(), null)))
       .andAffordance(afford(methodOn(OrderController.class).delete(order.getId())));
     EntityModel<Order> model = EntityModel.of(order, selfLink);
     RepresentationModel<?> orders = CollectionModel.of(model);
     orders.add(linkTo(methodOn(OrderController.class).orders()).withSelfRel());
-    return orders;
+    return ResponseEntity.ok(orders);
   }
 
-  @GetMapping("/orders/{id}")
-  public EntityModel<Order> order(@PathVariable(value = "id", required = true) Long id) {
+  @GetMapping(value = "/{id}")
+  public ResponseEntity<EntityModel<Order>> order(@PathVariable(value = "id", required = true) Long id) {
     Order order = new Order(id);
     Link selfLink = linkTo(methodOn(OrderController.class).order(order.getId())).withSelfRel()
       .andAffordance(afford(methodOn(OrderController.class).update(order.getId(), null)))
       .andAffordance(afford(methodOn(OrderController.class).delete(order.getId())));
     EntityModel<Order> model = EntityModel.of(order, selfLink);
-    return model;
+    return ResponseEntity.ok(model);
   }
 
-  @PutMapping("/orders/{id}")
+  @PutMapping("/{id}")
   public EntityModel<Order> update(@PathVariable(value = "id", required = true) Long id, Order order) {
     Link selfLink = linkTo(methodOn(OrderController.class).order(order.getId())).withSelfRel()
       .andAffordance(afford(methodOn(OrderController.class).update(order.getId(), null)))
@@ -52,7 +56,7 @@ public class OrderController {
     return model;
   }
 
-  @DeleteMapping("/orders/{id}")
+  @DeleteMapping("/{id}")
   public ResponseEntity<Void> delete(@PathVariable(value = "id", required = true) Long id) {
     return ResponseEntity.ok().build();
   }