diff options
author | mrfoxygmfr <mrfoxygmfr@sch9.ru> | 2025-04-28 00:45:36 +0300 |
---|---|---|
committer | mrfoxygmfr <mrfoxygmfr@sch9.ru> | 2025-04-28 00:45:36 +0300 |
commit | facd0103437ffb50108113567d5fbb24487ffc81 (patch) | |
tree | 4f7c8fdd8501879cf5e8cec4c5cd5e24f94297cb /src/main/java/ru/mrfoxygmfr | |
parent | a7130c44ebccbb6df7b6c7481f35a10243e3f4a3 (diff) |
feat: implement storageSlots http controller + pages
Diffstat (limited to 'src/main/java/ru/mrfoxygmfr')
-rw-r--r-- | src/main/java/ru/mrfoxygmfr/warehouse_accounting/http/controllers/StorageSlotsController.java | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/src/main/java/ru/mrfoxygmfr/warehouse_accounting/http/controllers/StorageSlotsController.java b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/http/controllers/StorageSlotsController.java new file mode 100644 index 0000000..2a9b28e --- /dev/null +++ b/src/main/java/ru/mrfoxygmfr/warehouse_accounting/http/controllers/StorageSlotsController.java @@ -0,0 +1,96 @@ +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.StorageSlotSpecs; +import ru.mrfoxygmfr.warehouse_accounting.db.models.*; + +import java.util.List; + +@Controller +public class StorageSlotsController { + @Autowired + private StorageSlotDAO storageSlotDAO; + + @GetMapping("storageSlots") + public String storageSlots(@RequestParam(name = "storageSlotHeightLess", required = false) Integer heightLess, + @RequestParam(name = "storageSlotHeightGreater", required = false) Integer heightGreater, + @RequestParam(name = "storageSlotWidthLess", required = false) Integer widthLess, + @RequestParam(name = "storageSlotWidthGreater", required = false) Integer widthGreater, + @RequestParam(name = "storageSlotDepthLess", required = false) Integer depthLess, + @RequestParam(name = "storageSlotDepthGreater", required = false) Integer depthGreater, + Model model) { + Specification<StorageSlot> spec = Specification.where(null); + if (heightLess != null) { + spec = spec.and(StorageSlotSpecs.storageSlotHeightLess(heightLess)); + model.addAttribute("storageSlotHeightLessFilter", heightLess); + } + if (heightGreater != null) { + spec = spec.and(StorageSlotSpecs.storageSlotHeightGreater(heightGreater)); + model.addAttribute("storageSlotHeightGreaterFilter", heightGreater); + } + if (widthLess != null) { + spec = spec.and(StorageSlotSpecs.storageSlotWidthLess(widthLess)); + model.addAttribute("storageSlotWidthLessFilter", widthLess); + } + if (widthGreater != null) { + spec = spec.and(StorageSlotSpecs.storageSlotWidthGreater(widthGreater)); + model.addAttribute("storageSlotWidthGreaterFilter", widthGreater); + } + if (depthLess != null) { + spec = spec.and(StorageSlotSpecs.storageSlotDepthLess(depthLess)); + model.addAttribute("storageSlotDepthLessFilter", depthLess); + } + if (depthGreater != null) { + spec = spec.and(StorageSlotSpecs.storageSlotDepthGreater(depthGreater)); + model.addAttribute("storageSlotDepthGreaterFilter", depthGreater); + } + + List<StorageSlot> storageSlots = storageSlotDAO.findAll(spec); + model.addAttribute("storageSlots", storageSlots); + return "storageSlots"; + } + + @GetMapping("storageSlot") + public String storageSlot(@RequestParam(name = "id") Integer id, Model model) { + StorageSlot storageSlot = storageSlotDAO.findById(id).orElseThrow(); + model.addAttribute("storageSlot", storageSlot); + return "storageSlotEdit"; + } + + + @PostMapping("storageSlot") + public String storageSlot(@RequestParam(name = "storageSlotId") Integer id, + @RequestParam(name = "storageSlotLocation") String location, + @RequestParam(name = "storageSlotHeight") Integer height, + @RequestParam(name = "storageSlotWidth") Integer width, + @RequestParam(name = "storageSlotDepth") Integer depth) { + StorageSlot storageSlot; + if (id == -1) { + storageSlot = new StorageSlot(location, height, width, depth); + } else { + storageSlot = storageSlotDAO.findById(id).orElseThrow(); + storageSlot.setLocation(location); + storageSlot.setHeight(height); + storageSlot.setWidth(width); + storageSlot.setDepth(depth); + } + storageSlotDAO.save(storageSlot); + return "redirect:/storageSlots"; + } + + @GetMapping("newStorageSlot") + public String newStorageSlot(Model model) { + StorageSlot storageSlot = new StorageSlot(); + storageSlot.setId(-1); + model.addAttribute("storageSlot", storageSlot); + model.addAttribute("newItem", true); + return "storageSlotEdit"; + } +} |