From a64c2772bd7ea2772d9b56f2c18545c890404472 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 29 Jan 2025 12:54:07 +0400 Subject: [PATCH] Add indicator courses --- .../ru/ulstu/admin/model/IndicatorForm.java | 15 +++++++++++++ .../ulstu/admin/service/AdminController.java | 7 ++++++- .../ru/ulstu/admin/service/AdminService.java | 1 + .../java/ru/ulstu/indicator/model/Course.java | 18 ++++++++++++++++ .../ru/ulstu/indicator/model/Indicator.java | 21 +++++++++++++++++++ .../resources/templates/editIndicator.html | 12 +++++++++++ 6 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/main/java/ru/ulstu/indicator/model/Course.java diff --git a/src/main/java/ru/ulstu/admin/model/IndicatorForm.java b/src/main/java/ru/ulstu/admin/model/IndicatorForm.java index adeb8d0..3750a2c 100644 --- a/src/main/java/ru/ulstu/admin/model/IndicatorForm.java +++ b/src/main/java/ru/ulstu/admin/model/IndicatorForm.java @@ -1,5 +1,10 @@ package ru.ulstu.admin.model; +import ru.ulstu.indicator.model.Course; + +import java.util.ArrayList; +import java.util.List; + public class IndicatorForm { private Integer id; @@ -9,6 +14,8 @@ public class IndicatorForm { private String proofDocuments; + private List courses = new ArrayList<>(); + public String getName() { return name; } @@ -40,4 +47,12 @@ public class IndicatorForm { public void setProofDocuments(String proofDocuments) { this.proofDocuments = proofDocuments; } + + public List getCourses() { + return courses; + } + + public void setCourses(List courses) { + this.courses = courses; + } } diff --git a/src/main/java/ru/ulstu/admin/service/AdminController.java b/src/main/java/ru/ulstu/admin/service/AdminController.java index 78dc074..5c68519 100644 --- a/src/main/java/ru/ulstu/admin/service/AdminController.java +++ b/src/main/java/ru/ulstu/admin/service/AdminController.java @@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import ru.ulstu.admin.model.IndicatorForm; +import ru.ulstu.indicator.model.Course; import ru.ulstu.indicator.model.Indicator; import ru.ulstu.model.UserRoleConstants; @@ -30,7 +31,11 @@ public class AdminController { @GetMapping("/editIndicator/{indicatorId}") @Secured({UserRoleConstants.ADMIN}) public String editIndicator(@PathVariable(value = "indicatorId") Integer id, Model model) { - model.addAttribute("indicator", (id != null && id != 0) ? adminService.getIndicatorById(id) : new Indicator()); + model.addAttribute("indicator", + (id != null && id != 0) + ? adminService.getIndicatorById(id) + : new Indicator()); + model.addAttribute("courses", Course.values()); return "editIndicator"; } diff --git a/src/main/java/ru/ulstu/admin/service/AdminService.java b/src/main/java/ru/ulstu/admin/service/AdminService.java index 07bf447..98159e0 100644 --- a/src/main/java/ru/ulstu/admin/service/AdminService.java +++ b/src/main/java/ru/ulstu/admin/service/AdminService.java @@ -26,6 +26,7 @@ public class AdminService { indicator.setName(indicatorForm.getName()); indicator.setMax(indicatorForm.getMax()); indicator.setProofDocuments(indicatorForm.getProofDocuments()); + indicator.setCourses(indicatorForm.getCourses()); indicatorService.save(indicator); } diff --git a/src/main/java/ru/ulstu/indicator/model/Course.java b/src/main/java/ru/ulstu/indicator/model/Course.java new file mode 100644 index 0000000..e04a726 --- /dev/null +++ b/src/main/java/ru/ulstu/indicator/model/Course.java @@ -0,0 +1,18 @@ +package ru.ulstu.indicator.model; + +public enum Course { + FIRST("первый"), + SECOND("второй"), + THIRD("третий"), + FOURTH("четвертый"); + + private final String name; + + Course(String name) { + this.name = name; + } + + public String getName() { + return name; + } +} diff --git a/src/main/java/ru/ulstu/indicator/model/Indicator.java b/src/main/java/ru/ulstu/indicator/model/Indicator.java index a60e21f..1944119 100644 --- a/src/main/java/ru/ulstu/indicator/model/Indicator.java +++ b/src/main/java/ru/ulstu/indicator/model/Indicator.java @@ -1,6 +1,10 @@ package ru.ulstu.indicator.model; +import jakarta.persistence.CollectionTable; +import jakarta.persistence.ElementCollection; import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; import jakarta.persistence.Lob; import jakarta.validation.constraints.Max; import jakarta.validation.constraints.Min; @@ -8,6 +12,9 @@ import jakarta.validation.constraints.NotBlank; import ru.ulstu.admin.model.IndicatorForm; import ru.ulstu.model.BaseEntity; +import java.util.ArrayList; +import java.util.List; + @Entity public class Indicator extends BaseEntity { @@ -22,6 +29,11 @@ public class Indicator extends BaseEntity { @Lob private String proofDocuments; + @ElementCollection(targetClass = Course.class) + @CollectionTable + @Enumerated(EnumType.STRING) + private List courses = new ArrayList<>(); + public Indicator() { } @@ -29,6 +41,7 @@ public class Indicator extends BaseEntity { this.name = indicatorForm.getName(); this.max = indicatorForm.getMax(); this.proofDocuments = indicatorForm.getProofDocuments(); + this.courses = indicatorForm.getCourses(); } public String getName() { @@ -54,4 +67,12 @@ public class Indicator extends BaseEntity { public void setProofDocuments(String proofDocuments) { this.proofDocuments = proofDocuments; } + + public List getCourses() { + return courses; + } + + public void setCourses(List courses) { + this.courses = courses; + } } diff --git a/src/main/resources/templates/editIndicator.html b/src/main/resources/templates/editIndicator.html index 6d9146c..e45d045 100644 --- a/src/main/resources/templates/editIndicator.html +++ b/src/main/resources/templates/editIndicator.html @@ -48,6 +48,18 @@ Не может быть пустым

+
+ + + +