-
Notifications
You must be signed in to change notification settings - Fork 199
/
Copy pathOrderRestController.java
57 lines (46 loc) · 1.87 KB
/
OrderRestController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package kitchenpos.order.ui;
import kitchenpos.order.application.OrderService;
import kitchenpos.order.domain.Order;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.net.URI;
import java.util.List;
import java.util.UUID;
@RequestMapping("/api/orders")
@RestController
public class OrderRestController {
private final OrderService orderService;
public OrderRestController(final OrderService orderService) {
this.orderService = orderService;
}
@PostMapping
public ResponseEntity<Order> create(@RequestBody final Order request) {
final Order response = orderService.create(request);
return ResponseEntity.created(URI.create("/api/orders/" + response.getId()))
.body(response);
}
@PutMapping("/{orderId}/accept")
public ResponseEntity<Order> accept(@PathVariable final UUID orderId) {
return ResponseEntity.ok(orderService.accept(orderId));
}
@PutMapping("/{orderId}/serve")
public ResponseEntity<Order> serve(@PathVariable final UUID orderId) {
return ResponseEntity.ok(orderService.serve(orderId));
}
@PutMapping("/{orderId}/start-delivery")
public ResponseEntity<Order> startDelivery(@PathVariable final UUID orderId) {
return ResponseEntity.ok(orderService.startDelivery(orderId));
}
@PutMapping("/{orderId}/complete-delivery")
public ResponseEntity<Order> completeDelivery(@PathVariable final UUID orderId) {
return ResponseEntity.ok(orderService.completeDelivery(orderId));
}
@PutMapping("/{orderId}/complete")
public ResponseEntity<Order> complete(@PathVariable final UUID orderId) {
return ResponseEntity.ok(orderService.complete(orderId));
}
@GetMapping
public ResponseEntity<List<Order>> findAll() {
return ResponseEntity.ok(orderService.findAll());
}
}