From 856b38ace75ffe1c7e96b6dc8a356ae9818684bc Mon Sep 17 00:00:00 2001 From: parap Date: Mon, 22 May 2023 03:43:31 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D1=82=D1=80=D0=BE=D0=BB?= =?UTF-8?q?=D0=BB=D0=B5=D1=80=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dbms/controllers/ClientController.java | 51 +++++++++++++++++++ .../org/dbms/controllers/DataController.java | 50 ++++++++++++++++++ .../dbms/controllers/DriverController.java | 36 +++++++++++++ .../org/dbms/controllers/OrderController.java | 41 +++++++++++++++ 4 files changed, 178 insertions(+) create mode 100644 src/main/java/org/dbms/controllers/ClientController.java create mode 100644 src/main/java/org/dbms/controllers/DataController.java create mode 100644 src/main/java/org/dbms/controllers/DriverController.java create mode 100644 src/main/java/org/dbms/controllers/OrderController.java diff --git a/src/main/java/org/dbms/controllers/ClientController.java b/src/main/java/org/dbms/controllers/ClientController.java new file mode 100644 index 0000000..7a1b6ff --- /dev/null +++ b/src/main/java/org/dbms/controllers/ClientController.java @@ -0,0 +1,51 @@ +package org.dbms.controllers; + +import org.dbms.dto.ClientLoginDto; +import org.dbms.dto.ClientSignupDto; +import org.dbms.dto.DriverDTO; +import org.dbms.exceptions.UserExistsException; +import org.dbms.searchModels.DriverSearch; +import org.dbms.service.ClientService; +import org.dbms.storageImpl.ClientStorage; +import org.dbms.storageImpl.DriverStorage; +import org.springframework.web.bind.annotation.*; + + +import javax.servlet.http.HttpServletResponse; +import javax.validation.Valid; +import java.util.List; +import java.util.stream.Collectors; + +@RestController +public class ClientController { + private final ClientService clientService; + + public ClientController(ClientService clientService) { + this.clientService = clientService; + } + + @PostMapping("/client") + public String createUser(@RequestBody @Valid ClientSignupDto client, HttpServletResponse response) { + String res = ""; + + try { + res = clientService.signup(client); + } catch(UserExistsException err) { + response.setStatus(403); + return "Пользователь уже существует"; + } + + return res; + } + + @PostMapping("/login") + public String login(@RequestBody @Valid ClientLoginDto client, HttpServletResponse response) { + if(clientService.login(client)) { + return "success"; + } else { + response.setStatus(403); + return "Неверный логин или пароль"; + } + } +} +; \ No newline at end of file diff --git a/src/main/java/org/dbms/controllers/DataController.java b/src/main/java/org/dbms/controllers/DataController.java new file mode 100644 index 0000000..1abc418 --- /dev/null +++ b/src/main/java/org/dbms/controllers/DataController.java @@ -0,0 +1,50 @@ +package org.dbms.controllers; + +import org.dbms.data.DataGenerator; +import org.dbms.data.DataPerform; +import org.dbms.dto.DriverDTO; +import org.dbms.searchModels.DriverSearch; +import org.dbms.service.DriverService; +import org.dbms.storageImpl.DriverStorage; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.stream.Collectors; + +@RestController +public class DataController { + private DataGenerator dataGenerator; + private DataPerform dataPerform; + public DataController(DataGenerator dataGenerator, DataPerform dataPerform) { + this.dataGenerator = dataGenerator; + this.dataPerform = dataPerform; + } + + @GetMapping("/generate-data") + public String getDriversCount() { + dataGenerator.generate(); + return "success"; + } + + @GetMapping("/test-select") + public String testSelect() { + return dataPerform.select() + ""; + } + + + @GetMapping("/test-insert") + public String testInsert() { + return dataPerform.insert(1000) + ""; + } + + @GetMapping("/test-update") + public String testUpdate() { + return dataPerform.update(1000) + ""; + } + + @GetMapping("/test-delete") + public String testDelete() { + return dataPerform.delete() + ""; + } + +} diff --git a/src/main/java/org/dbms/controllers/DriverController.java b/src/main/java/org/dbms/controllers/DriverController.java new file mode 100644 index 0000000..7e212d5 --- /dev/null +++ b/src/main/java/org/dbms/controllers/DriverController.java @@ -0,0 +1,36 @@ +package org.dbms.controllers; + +import org.dbms.dto.DriverDTO; +import org.dbms.searchModels.DriverSearch; +import org.dbms.service.DriverService; +import org.dbms.storageImpl.DriverStorage; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.stream.Collectors; + +@RestController +public class DriverController { + private final DriverService driverService; + + public DriverController(DriverService driverService) { + this.driverService = driverService; + } + + @GetMapping("/drivers") + public List getDrivers(@RequestParam(defaultValue = "-1") int expFrom, + @RequestParam(defaultValue = "-1") int expTo, + @RequestParam(defaultValue = "-1") int size, + @RequestParam(defaultValue = "-1") int page) { + + return driverService.getFilteredPage(expFrom, expTo, size, page).stream().map(DriverDTO::new).toList(); + } + + @GetMapping("/drivers/pages-count") + public int getDriversCount(@RequestParam(defaultValue = "-1") int expFrom, + @RequestParam(defaultValue = "-1") int expTo, + @RequestParam(defaultValue = "-1") int size) { + + return driverService.getFilteredCount(expFrom, expTo, size); + } +} diff --git a/src/main/java/org/dbms/controllers/OrderController.java b/src/main/java/org/dbms/controllers/OrderController.java new file mode 100644 index 0000000..383565c --- /dev/null +++ b/src/main/java/org/dbms/controllers/OrderController.java @@ -0,0 +1,41 @@ +package org.dbms.controllers; + +import org.dbms.dto.ClientLoginDto; +import org.dbms.dto.ClientSignupDto; +import org.dbms.dto.CreateOrderDTO; +import org.dbms.dto.OrderDTO; +import org.dbms.exceptions.UserExistsException; +import org.dbms.service.ClientService; +import org.dbms.service.OrderService; +import org.springframework.web.bind.annotation.*; + + +import javax.servlet.http.HttpServletResponse; +import javax.validation.Valid; +import java.util.List; + +@RestController +public class OrderController { + private final OrderService orderService; + + public OrderController(OrderService orderService) { + this.orderService = orderService; + } + + @GetMapping("/orders") + public List getOrders(@RequestParam String login, @RequestParam int size, @RequestParam int page) { + return orderService.getOrdersPageByClient(login, size, page).stream().map(OrderDTO::new).toList(); + } + + @PostMapping("/orders") + public String makeOrder(@RequestBody @Valid CreateOrderDTO order) { + orderService.createOrder(order); + return "success"; + } + + @GetMapping("/orders/pages-count") + public int getPagesCount(@RequestParam String login, @RequestParam int size) { + return orderService.getPagesCount(login, size); + } +} +; \ No newline at end of file