Add indicator max value

This commit is contained in:
Anton Romanov 2025-01-29 10:21:00 +04:00
parent 8b8d64bd00
commit bf57c20b96
4 changed files with 40 additions and 6 deletions

View File

@ -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;
}
}

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -4,17 +4,24 @@
layout:decorate="~{default}">
<div class="container" layout:fragment="content">
<h3>Редактирование показателя:</h3>
<form action="#" th:action="@{/admin/saveIndicator}" th:object="${indicator}" method="post"
<form action="#" th:action="@{/admin/saveIndicator}"
th:object="${indicator}"
method="post"
enctype="multipart/form-data">
<input type="hidden" th:field="*{id}">
<input type="hidden" th:field="*{version}">
<div class="form-group">
<label for="name">Название</label>
<input type="text" class="form-control" id="name" th:field="*{name}" placeholder="Название показателя">
<input type="text" required class="form-control" id="name" th:field="*{name}"
placeholder="Название показателя">
<p th:if="${#fields.hasErrors('name')}" th:class="${#fields.hasErrors('name')}? error">
Не может быть пустым</p>
</div>
<div class="form-group">
<label for="name">Максимальная сумма баллов</label>
<input type="number" required class="form-control" id="max" min="0" , max="30" th:field="*{max}">
</div>
<button name="save" type="submit" class="btn btn-outline-dark">Сохранить</button>
<button name="delete"
type="submit"