aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/ru
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/ru')
-rw-r--r--src/main/java/ru/mrfoxygmfr/warehouse_accounting/http/controllers/OperationsController.java78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/main/java/ru/mrfoxygmfr/warehouse_accounting/http/controllers/OperationsController.java b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/http/controllers/OperationsController.java
new file mode 100644
index 0000000..f4acdd1
--- /dev/null
+++ b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/http/controllers/OperationsController.java
@@ -0,0 +1,78 @@
+package ru.mrfoxygmfr.warehouse_accounting.http.controllers;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import ru.mrfoxygmfr.warehouse_accounting.db.dao.*;
+import ru.mrfoxygmfr.warehouse_accounting.db.dao.specs.OperationSpecs;
+import ru.mrfoxygmfr.warehouse_accounting.db.models.*;
+
+import java.util.List;
+
+@Controller
+public class OperationsController {
+ @Autowired
+ private OperationDAO operationDAO;
+
+ @GetMapping(value = { "/", "/index", "/operations"})
+ public String operations(@RequestParam(name = "operationType", required = false) OperationType type,
+ @RequestParam(name = "operationStatus", required = false) OperationStatus status,
+ @RequestParam(name = "operationProductName", required = false) String productName,
+ @RequestParam(name = "operationPartnerName", required = false) String partnerName,
+ Model model) {
+ Specification<Operation> spec = Specification.where(null);
+ if (type != null) {
+ spec = spec.and(OperationSpecs.operationTypeEqual(type));
+ model.addAttribute("operationTypeFilter", type.toString());
+ }
+ if (status != null) {
+ spec = spec.and(OperationSpecs.operationStatusEqual(status));
+ model.addAttribute("operationStatusFilter", status.toString());
+ }
+ if (productName != null) {
+ spec = spec.and(OperationSpecs.operationProductsContainsLike(productName));
+ model.addAttribute("operationProductNameFilter", productName);
+ }
+ if (partnerName != null) {
+ spec = spec.and(OperationSpecs.operationPartnerNameLike(partnerName));
+ model.addAttribute("operationPartnerNameFilter", partnerName);
+ }
+ List<Operation> operations = operationDAO.findAll(spec);
+ model.addAttribute("operations", operations);
+ return "operations";
+ }
+
+ @GetMapping("operation")
+ public String operation(@RequestParam(name = "id") Integer id, Model model) {
+ Operation operation = operationDAO.findById(id).orElseThrow();
+ model.addAttribute("operation", operation);
+ return "operationEdit";
+ }
+
+ @PostMapping("operation")
+ public String operation(
+ @RequestParam(name = "id") Integer id,
+ @RequestParam(name = "type") String type,
+ @RequestParam(name = "status") String status,
+ @RequestParam(name = "partner_id") Integer partnerId,
+ @RequestParam(name = "responsible_id") Integer responsibleId,
+ Model model) {
+ Operation operation;
+ if (id != null) {
+ operation = operationDAO.findById(id).orElseThrow();
+ } else {
+ operation = new Operation();
+ }
+
+ return String.format("redirect:/operation?id=%d", operation.getId());
+ }
+
+ @GetMapping("newOperation")
+ public String newOperation(Model model) {
+ return "operationEdit";
+ }
+}