-
Notifications
You must be signed in to change notification settings - Fork 199
/
Copy pathProductRestController.java
37 lines (30 loc) · 1.2 KB
/
ProductRestController.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
package kitchenpos.product.ui;
import kitchenpos.product.application.ProductService;
import kitchenpos.product.domain.Product;
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/products")
@RestController
public class ProductRestController {
private final ProductService productService;
public ProductRestController(final ProductService productService) {
this.productService = productService;
}
@PostMapping
public ResponseEntity<Product> create(@RequestBody final Product request) {
final Product response = productService.create(request);
return ResponseEntity.created(URI.create("/api/products/" + response.getId()))
.body(response);
}
@PutMapping("/{productId}/price")
public ResponseEntity<Product> changePrice(@PathVariable final UUID productId, @RequestBody final Product request) {
return ResponseEntity.ok(productService.changePrice(productId, request));
}
@GetMapping
public ResponseEntity<List<Product>> findAll() {
return ResponseEntity.ok(productService.findAll());
}
}