From bf57c20b961c5f0e10356164307abd73ef2d3707 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Wed, 29 Jan 2025 10:21:00 +0400 Subject: [PATCH] Add indicator max value --- .../ru/ulstu/admin/model/IndicatorForm.java | 10 ++++++++++ .../ru/ulstu/admin/service/AdminService.java | 3 ++- .../ru/ulstu/indicator/model/Indicator.java | 20 +++++++++++++++++-- .../resources/templates/editIndicator.html | 13 +++++++++--- 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/main/java/ru/ulstu/admin/model/IndicatorForm.java b/src/main/java/ru/ulstu/admin/model/IndicatorForm.java index f143358..2ef8d45 100644 --- a/src/main/java/ru/ulstu/admin/model/IndicatorForm.java +++ b/src/main/java/ru/ulstu/admin/model/IndicatorForm.java @@ -5,6 +5,8 @@ public class IndicatorForm { private String name; + private int max; + public String getName() { return name; } @@ -20,4 +22,12 @@ public class IndicatorForm { public void setId(Integer id) { this.id = id; } + + public int getMax() { + return max; + } + + public void setMax(int max) { + this.max = max; + } } diff --git a/src/main/java/ru/ulstu/admin/service/AdminService.java b/src/main/java/ru/ulstu/admin/service/AdminService.java index 5a67910..6151795 100644 --- a/src/main/java/ru/ulstu/admin/service/AdminService.java +++ b/src/main/java/ru/ulstu/admin/service/AdminService.java @@ -21,9 +21,10 @@ public class AdminService { public void saveIndicator(IndicatorForm indicatorForm) { Indicator indicator = indicatorForm.getId() == null - ? new Indicator(indicatorForm.getName()) + ? new Indicator(indicatorForm) : indicatorService.getIndicatorById(indicatorForm.getId()); indicator.setName(indicatorForm.getName()); + indicator.setMax(indicatorForm.getMax()); indicatorService.save(indicator); } diff --git a/src/main/java/ru/ulstu/indicator/model/Indicator.java b/src/main/java/ru/ulstu/indicator/model/Indicator.java index fbec5a2..6a8beca 100644 --- a/src/main/java/ru/ulstu/indicator/model/Indicator.java +++ b/src/main/java/ru/ulstu/indicator/model/Indicator.java @@ -1,7 +1,10 @@ package ru.ulstu.indicator.model; import jakarta.persistence.Entity; +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotBlank; +import ru.ulstu.admin.model.IndicatorForm; import ru.ulstu.model.BaseEntity; @Entity @@ -10,11 +13,16 @@ public class Indicator extends BaseEntity { @NotBlank private String name; + @Min(0) + @Max(30) + private int max; + public Indicator() { } - public Indicator(String name) { - this.name = name; + public Indicator(IndicatorForm indicatorForm) { + this.name = indicatorForm.getName(); + this.max = indicatorForm.getMax(); } public String getName() { @@ -24,4 +32,12 @@ public class Indicator extends BaseEntity { public void setName(String name) { this.name = name; } + + public int getMax() { + return max; + } + + public void setMax(int max) { + this.max = max; + } } diff --git a/src/main/resources/templates/editIndicator.html b/src/main/resources/templates/editIndicator.html index b13ee24..6fb8fbb 100644 --- a/src/main/resources/templates/editIndicator.html +++ b/src/main/resources/templates/editIndicator.html @@ -4,17 +4,24 @@ layout:decorate="~{default}">

Редактирование показателя:

-
-
- +

Не может быть пустым

+
+ + +
+