From 1faa719f920fb5d4f602e4ac837c03a8083ae4a7 Mon Sep 17 00:00:00 2001 From: Zyzf Date: Tue, 25 Apr 2023 09:54:52 +0400 Subject: [PATCH] final --- frontend/src/components/Computers.vue | 176 ++++++++++++++++++ frontend/src/components/Modal.vue | 12 +- frontend/src/components/Monitors.vue | 71 +++++++ frontend/src/main.js | 6 +- frontend/src/mixins/CatalogMixins.js | 2 +- frontend/src/models/Car.js | 47 ----- frontend/src/models/Client.js | 45 ----- frontend/src/models/Computer.js | 12 +- frontend/src/models/Driver.js | 54 ------ frontend/src/models/Order.js | 92 --------- frontend/src/models/PickUpPoint.js | 21 --- .../controller/ComputerController.java | 10 + .../yan/computer/service/ComputerService.java | 29 +++ .../monitor/controller/MonitorController.java | 8 + .../yan/monitor/service/MonitorService.java | 23 ++- 15 files changed, 340 insertions(+), 268 deletions(-) create mode 100644 frontend/src/components/Computers.vue create mode 100644 frontend/src/components/Monitors.vue delete mode 100644 frontend/src/models/Car.js delete mode 100644 frontend/src/models/Client.js delete mode 100644 frontend/src/models/Driver.js delete mode 100644 frontend/src/models/Order.js delete mode 100644 frontend/src/models/PickUpPoint.js diff --git a/frontend/src/components/Computers.vue b/frontend/src/components/Computers.vue new file mode 100644 index 0000000..e386058 --- /dev/null +++ b/frontend/src/components/Computers.vue @@ -0,0 +1,176 @@ + + + \ No newline at end of file diff --git a/frontend/src/components/Modal.vue b/frontend/src/components/Modal.vue index f12c004..335e71a 100644 --- a/frontend/src/components/Modal.vue +++ b/frontend/src/components/Modal.vue @@ -57,7 +57,11 @@ \ No newline at end of file + .modal-show { + display: block; + } + + .modal-content { + width: max-content; + } + \ No newline at end of file diff --git a/frontend/src/components/Monitors.vue b/frontend/src/components/Monitors.vue new file mode 100644 index 0000000..ab8975c --- /dev/null +++ b/frontend/src/components/Monitors.vue @@ -0,0 +1,71 @@ + + + \ No newline at end of file diff --git a/frontend/src/main.js b/frontend/src/main.js index b668244..dd66326 100644 --- a/frontend/src/main.js +++ b/frontend/src/main.js @@ -3,10 +3,14 @@ import { createRouter, createWebHistory } from 'vue-router' import './style.css' import App from './App.vue' import Cabinets from './components/Cabinets.vue' +import Computers from './components/Computers.vue' +import Monitors from './components/Monitors.vue' const routes = [ { path: '/', redirect: '/cabinets' }, - { path: '/cabinets', component: Cabinets, meta: { label: 'Кабинеты' }} + { path: '/cabinets', component: Cabinets, meta: { label: 'Кабинеты' } }, + { path: '/computers', component: Computers, meta: { label: 'Компьютеры' } }, + { path: '/monitors', component: Monitors, meta: { label: 'Мониторы' } } ] const router = createRouter({ diff --git a/frontend/src/mixins/CatalogMixins.js b/frontend/src/mixins/CatalogMixins.js index f2198c1..4b493d2 100644 --- a/frontend/src/mixins/CatalogMixins.js +++ b/frontend/src/mixins/CatalogMixins.js @@ -63,7 +63,7 @@ const CatalogMixin = { }, saveItem() { if (!this.isEdit) { - DataService.create(this.dataUrl, this.data) + DataService.create(this.dataUrl + "/", this.data) .then(() => { this.getItems(); }); diff --git a/frontend/src/models/Car.js b/frontend/src/models/Car.js deleted file mode 100644 index 8794e1d..0000000 --- a/frontend/src/models/Car.js +++ /dev/null @@ -1,47 +0,0 @@ -export default class Car { - constructor(data) { - this._id = data?.id; - this._gosNumber = data?.gosNumber; - this._vin = data?.vin; - this._driver = data?.driver; - this._driverId = data?.driver.id; - } - - get id() { - return this._id; - } - - get gosNumber() { - return this._gosNumber; - } - - set gosNumber(value) { - if (typeof value !== 'string' || value === null || value.length == 0) { - throw 'New gos number value ' + value + ' is not a string or empty'; - } - this._gosNumber = value; - } - - get vin() { - return this._vin; - } - - set vin(value) { - if (typeof value !== 'string' || value === null || value.length == 0) { - throw 'New vin value ' + value + ' is not a string or empty'; - } - this._vin = value; - } - - get driverId() { - return this._driverId; - } - - set driverId(value) { - this._driverId = value; - } - - get driverName() { - return this.driver?.name; - } -} \ No newline at end of file diff --git a/frontend/src/models/Client.js b/frontend/src/models/Client.js deleted file mode 100644 index 86f54b9..0000000 --- a/frontend/src/models/Client.js +++ /dev/null @@ -1,45 +0,0 @@ -export default class Student { - constructor(data) { - this._id = data?.id; - this._name = data?.name; - this._phone = data?.phone; - this._email = data?.email; - } - - get id() { - return this._id; - } - - get name() { - return this._name; - } - - set name(value) { - if (typeof value !== 'string' || value === null || value.length == 0) { - throw 'New name value ' + value + ' is not a string or empty'; - } - this._name = value; - } - - get phone() { - return this._phone; - } - - set phone(value) { - if (typeof value !== 'string' || value === null || value.length == 0) { - throw 'New phone value ' + value + ' is not a string or empty'; - } - this._phone = value; - } - - get email() { - return this._email; - } - - set email(value) { - if (typeof value !== 'string' || value === null || value.length == 0) { - throw 'New email value ' + value + ' is not a string or empty'; - } - this._email = value; - } -} \ No newline at end of file diff --git a/frontend/src/models/Computer.js b/frontend/src/models/Computer.js index 8a40d73..599d00c 100644 --- a/frontend/src/models/Computer.js +++ b/frontend/src/models/Computer.js @@ -57,7 +57,15 @@ export default class Computer { this._cabinetId = value; } - get cabinetNumber() { - return this._cabinet?.numer; + get cabinet() { + return this._cabinet; + } + + set cabinet(data) { + this._cabinet = data; + } + + get cabinetNum() { + return this._cabinet?.number; } } \ No newline at end of file diff --git a/frontend/src/models/Driver.js b/frontend/src/models/Driver.js deleted file mode 100644 index 43727d1..0000000 --- a/frontend/src/models/Driver.js +++ /dev/null @@ -1,54 +0,0 @@ -export default class Driver { - constructor(data) { - this._id = data?.id; - this._name = data?.name; - this._birthday = data?.birthday; - this._phone = data?.phone; - this._email = data?.email; - } - - get id() { - return this._id; - } - - get name() { - return this._name; - } - - set name(value) { - if (typeof value !== 'string' || value === null || value.length == 0) { - throw 'New name value ' + value + ' is not a string or empty'; - } - this._name = value; - } - - get birthday() { - return this._age; - } - - set birthday(value) { - this._birthday = value; - } - - get phone() { - return this._phone; - } - - set phone(value) { - if (typeof value !== 'string' || value === null || value.length == 0) { - throw 'New phone value ' + value + ' is not a string or empty'; - } - this._phone = value; - } - - get email() { - return this._email; - } - - set email(value) { - if (typeof value !== 'string' || value === null || value.length == 0) { - throw 'New email value ' + value + ' is not a string or empty'; - } - this._email = value; - } -} \ No newline at end of file diff --git a/frontend/src/models/Order.js b/frontend/src/models/Order.js deleted file mode 100644 index 6cb001a..0000000 --- a/frontend/src/models/Order.js +++ /dev/null @@ -1,92 +0,0 @@ -export default class Order { - constructor(data) { - this._id = data?.id; - this._value = data?.value; - this._status = data?.status; - this._date = data?.date.split('T')[0]; - this._client = data?.client; - this._clientId = data?.client.id; - this._sourcePickUpPoint = data?.sourcePickUpPoint; - this._sourcePickUpPointId = data?.sourcePickUpPoint.id; - this._destPickUpPoint = data?.destPickUpPoint; - this._destPickUpPointId = data?.destPickUpPoint?.id; - this._car = data?.car; - this._carId = data?.car.id; - } - - get id() { - return this._id; - } - - get value() { - return this._value; - } - - set value(data) { - this._value = data; - } - - get status() { - return this._status; - } - - set status(data) { - this._status = data; - } - - get date() { - return this._date; - } - - set date(data) { - this._date = data; - } - - get clientId() { - return this._clientId; - } - - set clientId(value) { - this._clientId = value; - } - - get clientName() { - return this._client?.name; - } - - get sourcePickUpPointId() { - return this._sourcePickUpPointId; - } - - set sourcePickUpPointId(value) { - this._sourcePickUpPointId = value; - } - - get sourcePickUpPointAddress() { - return this._sourcePickUpPoint?.address; - } - - get destPickUpPointId() { - return this._destPickUpPointId; - } - - set destPickUpPointId(value) { - this._destPickUpPointId = value; - } - - get destPickUpPointAddress() { - return this._destPickUpPoint?.address; - } - - get carId() { - return this._carId; - } - - set carId(value) { - this._carId = value; - } - - get carNumber() { - return this._car?.gosNumber; - } -} \ No newline at end of file diff --git a/frontend/src/models/PickUpPoint.js b/frontend/src/models/PickUpPoint.js deleted file mode 100644 index 652ddeb..0000000 --- a/frontend/src/models/PickUpPoint.js +++ /dev/null @@ -1,21 +0,0 @@ -export default class PickUpPoint { - constructor(data) { - this._id = data?.id; - this._address = data?.address; - } - - get id() { - return this._id; - } - - get address() { - return this._address; - } - - set address(value) { - if (typeof value !== 'string' || value === null || value.length == 0) { - throw 'New address value ' + value + ' is not a string or empty'; - } - this._address = value; - } -} \ No newline at end of file diff --git a/src/main/java/com/kalyshev/yan/computer/controller/ComputerController.java b/src/main/java/com/kalyshev/yan/computer/controller/ComputerController.java index 8e41def..287f2f6 100644 --- a/src/main/java/com/kalyshev/yan/computer/controller/ComputerController.java +++ b/src/main/java/com/kalyshev/yan/computer/controller/ComputerController.java @@ -28,6 +28,16 @@ public class ComputerController { .map(ComputerDto::new) .toList(); } + @GetMapping("/filter") + public List getFilteredComputers(@RequestParam(value = "id", required = false) Long id, + @RequestParam(value = "modelName", required = false) String modelName, + @RequestParam(value = "serialNum", required = false) String serialNum, + @RequestParam(value = "monitorId", required = false) Long monitorId, + @RequestParam(value = "cabinetId", required = false) Long cabinetId) { + return computerService.findFilteredComputers(id, modelName, serialNum, monitorId, cabinetId).stream() + .map(ComputerDto::new) + .toList(); + } @GetMapping("/{id}/computers") public CabinetDto getComputersCabinet(@PathVariable Long id) { return new CabinetDto(computerService.getCabinet(id)); diff --git a/src/main/java/com/kalyshev/yan/computer/service/ComputerService.java b/src/main/java/com/kalyshev/yan/computer/service/ComputerService.java index 23aee0e..855051c 100644 --- a/src/main/java/com/kalyshev/yan/computer/service/ComputerService.java +++ b/src/main/java/com/kalyshev/yan/computer/service/ComputerService.java @@ -17,7 +17,9 @@ import com.kalyshev.yan.computer.model.Computer; import jakarta.persistence.EntityNotFoundException; +import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.Optional; @Service @@ -66,6 +68,33 @@ public class ComputerService { public List findAllComputers() { return computerRepository.findAll(); } + @Transactional(readOnly = true) + public List findFilteredComputers(Long id, String modelName, String serialNum, Long monitorId, Long cabinetId) { + List allComputers = computerRepository.findAll(); + List result = new ArrayList<>(); + for (Computer computer : allComputers) { + boolean flag = true; + if (id != null && !Objects.equals(computer.getId(), id)) { + flag = false; + } + if (modelName != null && !Objects.equals(computer.getModelName(), modelName)) { + flag = false; + } + if (serialNum != null && !Objects.equals(computer.getSerialNum(), serialNum)) { + flag = false; + } + if (monitorId != null && computer.getMonitor() != null && !Objects.equals(computer.getMonitor().getId(), monitorId)) { + flag = false; + } + if (cabinetId != null && computer.getCabinet() != null && !Objects.equals(computer.getCabinet().getId(), cabinetId)) { + flag = false; + } + if (flag) { + result.add(computer); + } + } + return result; + } @Transactional public Computer updateComputer(Long id, String modelName, String serialNum, Long monitorId, Long cabinetId) { if (!(StringUtils.hasText(modelName) || StringUtils.hasText(serialNum))) { diff --git a/src/main/java/com/kalyshev/yan/monitor/controller/MonitorController.java b/src/main/java/com/kalyshev/yan/monitor/controller/MonitorController.java index c9c78fd..3236ad1 100644 --- a/src/main/java/com/kalyshev/yan/monitor/controller/MonitorController.java +++ b/src/main/java/com/kalyshev/yan/monitor/controller/MonitorController.java @@ -1,6 +1,7 @@ package com.kalyshev.yan.monitor.controller; import com.kalyshev.yan.WebConfiguration; +import com.kalyshev.yan.computer.controller.ComputerDto; import com.kalyshev.yan.monitor.model.Monitor; import com.kalyshev.yan.monitor.service.MonitorService; import jakarta.validation.Valid; @@ -25,6 +26,13 @@ public class MonitorController { .map(MonitorDto::new) .toList(); } + @GetMapping("/filter") + public List getFilteredmonitors(@RequestParam(value = "id", required = false) Long id, + @RequestParam(value = "modelName", required = false) String modelName) { + return monitorService.findFilteredMonitors(id, modelName).stream() + .map(MonitorDto::new) + .toList(); + } @PostMapping("/") public MonitorDto createMonitor(@RequestBody @Valid MonitorDto monitorDto) { return new MonitorDto(monitorService.addMonitor(monitorDto.getModelName())); diff --git a/src/main/java/com/kalyshev/yan/monitor/service/MonitorService.java b/src/main/java/com/kalyshev/yan/monitor/service/MonitorService.java index c62c0c9..718aa04 100644 --- a/src/main/java/com/kalyshev/yan/monitor/service/MonitorService.java +++ b/src/main/java/com/kalyshev/yan/monitor/service/MonitorService.java @@ -1,10 +1,11 @@ -package com.kalyshev.yan.monitor.service; + package com.kalyshev.yan.monitor.service; import com.kalyshev.yan.cabinet.model.Cabinet; import com.kalyshev.yan.cabinet.repository.CabinetNotFoundException; import com.kalyshev.yan.cabinet.repository.CabinetRepository; import com.kalyshev.yan.computer.model.Computer; import com.kalyshev.yan.computer.repository.ComputerRepository; +import com.kalyshev.yan.monitor.controller.MonitorController; import com.kalyshev.yan.monitor.repository.MonitorNotFoundException; import com.kalyshev.yan.monitor.repository.MonitorRepository; import com.kalyshev.yan.util.validation.ValidatorUtil; @@ -19,6 +20,8 @@ import com.kalyshev.yan.monitor.model.Monitor; import jakarta.persistence.EntityManager; import jakarta.persistence.EntityNotFoundException; import jakarta.persistence.PersistenceContext; + +import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -53,6 +56,24 @@ public class MonitorService { public List findAllMonitors() { return monitorRepository.findAll(); } + @Transactional(readOnly = true) + public List findFilteredMonitors(Long id, String modelName) { + List allMonitors = monitorRepository.findAll(); + List result = new ArrayList<>(); + for (Monitor monitor : allMonitors) { + boolean flag = true; + if (id != null && !Objects.equals(monitor.getId(), id)) { + flag = false; + } + if (modelName != null && !Objects.equals(monitor.getModelName(), modelName)) { + flag = false; + } + if (flag) { + result.add(monitor); + } + } + return result; + } @Transactional public Monitor updateMonitor(Long id, String modelName) { if (!StringUtils.hasText(modelName)) {