From f602164928a4f5d7d93b54755538365578c9e4e5 Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Mon, 24 Apr 2023 22:22:33 +0400 Subject: [PATCH] lab 4 controllers done --- .../controller/ComponentController.java | 12 +++--- .../repair/controller/FavorController.java | 12 +++--- .../repair/controller/OrderController.java | 42 +++++++++++++++++++ 3 files changed, 54 insertions(+), 12 deletions(-) diff --git a/src/main/java/ru/ulstu/is/sbapp/repair/controller/ComponentController.java b/src/main/java/ru/ulstu/is/sbapp/repair/controller/ComponentController.java index add3806..a572e2f 100644 --- a/src/main/java/ru/ulstu/is/sbapp/repair/controller/ComponentController.java +++ b/src/main/java/ru/ulstu/is/sbapp/repair/controller/ComponentController.java @@ -14,31 +14,31 @@ public class ComponentController { this.componentService = productService; } @PostMapping - public ComponentDTO addProduct(@RequestBody @Valid ComponentDTO componentDTO) { + public ComponentDTO addComponent(@RequestBody @Valid ComponentDTO componentDTO) { return new ComponentDTO(componentService.addComponent(componentDTO)); } @PutMapping("/{id}") - public ComponentDTO updateProduct(@PathVariable Long id,@RequestBody @Valid ComponentDTO componentDTO) { + public ComponentDTO updateComponent(@PathVariable Long id,@RequestBody @Valid ComponentDTO componentDTO) { return new ComponentDTO(componentService.updateComponent(id,componentDTO)); } @DeleteMapping("/{id}") - public ComponentDTO removeProduct(@PathVariable Long id) { + public ComponentDTO removeComponent(@PathVariable Long id) { return new ComponentDTO(componentService.deleteComponent(id)); } @DeleteMapping - public void removeAllProducts() { + public void removeAllComponents() { componentService.deleteAllComponent(); } @GetMapping("/{id}") - public ComponentDTO findProduct(@PathVariable Long id) { + public ComponentDTO findComponent(@PathVariable Long id) { return new ComponentDTO(componentService.findComponent(id)); } @GetMapping - public List findAllProduct() { + public List findAllComponents() { return componentService.findAllComponent() .stream() .map(ComponentDTO::new) diff --git a/src/main/java/ru/ulstu/is/sbapp/repair/controller/FavorController.java b/src/main/java/ru/ulstu/is/sbapp/repair/controller/FavorController.java index fb64c06..e9f4aae 100644 --- a/src/main/java/ru/ulstu/is/sbapp/repair/controller/FavorController.java +++ b/src/main/java/ru/ulstu/is/sbapp/repair/controller/FavorController.java @@ -14,31 +14,31 @@ public class FavorController { this.favorService = favorService; } @PostMapping - public FavorDTO addProduct(@RequestBody @Valid FavorDTO favorDTO) { + public FavorDTO addFavor(@RequestBody @Valid FavorDTO favorDTO) { return new FavorDTO(favorService.addFavor(favorDTO)); } @PutMapping("/{id}") - public FavorDTO updateProduct(@PathVariable Long id,@RequestBody @Valid FavorDTO favorDTO) { + public FavorDTO updateFavor(@PathVariable Long id,@RequestBody @Valid FavorDTO favorDTO) { return new FavorDTO(favorService.updateFavor(id,favorDTO)); } @DeleteMapping("/{id}") - public FavorDTO removeProduct(@PathVariable Long id) { + public FavorDTO removeFavor(@PathVariable Long id) { return new FavorDTO(favorService.deleteFavor(id)); } @DeleteMapping - public void removeAllProducts() { + public void removeAllFavors() { favorService.deleteAllFavor(); } @GetMapping("/{id}") - public FavorDTO findProduct(@PathVariable Long id) { + public FavorDTO findFavor(@PathVariable Long id) { return new FavorDTO(favorService.findFavor(id)); } @GetMapping - public List findAllProduct() { + public List findAllFavors() { return favorService.findAllFavor() .stream() .map(FavorDTO::new) diff --git a/src/main/java/ru/ulstu/is/sbapp/repair/controller/OrderController.java b/src/main/java/ru/ulstu/is/sbapp/repair/controller/OrderController.java index f9a8be7..b10a35a 100644 --- a/src/main/java/ru/ulstu/is/sbapp/repair/controller/OrderController.java +++ b/src/main/java/ru/ulstu/is/sbapp/repair/controller/OrderController.java @@ -1,4 +1,46 @@ package ru.ulstu.is.sbapp.repair.controller; +import org.springframework.web.bind.annotation.*; +import javax.validation.Valid; +import ru.ulstu.is.sbapp.repair.service.OrderService; +import java.util.List; + +@RestController +@RequestMapping("/component") public class OrderController { + private final OrderService orderService; + public OrderController(OrderService productService){ + this.orderService = productService; + } + @PostMapping + public OrderDTO addOrder(@RequestBody @Valid OrderDTO orderDTO) { + return new OrderDTO(orderService.addOrder(orderDTO)); + } + + @PutMapping("/{id}") + public OrderDTO updateOrder(@PathVariable Long id,@RequestBody @Valid OrderDTO orderDTO) { + return new OrderDTO(orderService.updateOrder(id,orderDTO)); + } + + @DeleteMapping("/{id}") + public OrderDTO removeOrder(@PathVariable Long id) { + return new OrderDTO(orderService.deleteOrder(id)); + } + + @DeleteMapping + public void removeAllOrders() { + orderService.deleteAllOrder(); + } + + @GetMapping("/{id}") + public OrderDTO findOrder(@PathVariable Long id) { + return new OrderDTO(orderService.findOrder(id)); + } + @GetMapping + public List findAllOrders() { + return orderService.findAllOrders() + .stream() + .map(OrderDTO::new) + .toList(); + } }