Add aspirant manager

This commit is contained in:
Anton Romanov 2025-01-29 20:17:11 +04:00
parent 32d8779fd4
commit d04c61b683
5 changed files with 28 additions and 24 deletions

View File

@ -29,9 +29,9 @@ public class AdminAspirantController {
@GetMapping("/editAspirant/{aspirantId}")
public String editAspirant(@PathVariable(value = "aspirantId") Integer id, Model model) {
model.addAttribute("aspirant",
(id != null && id != 0)
new AspirantForm((id != null && id != 0)
? adminAspirantService.getAspirantById(id)
: new Aspirant());
: new Aspirant()));
model.addAttribute("courses", Course.values());
model.addAttribute("managers", adminAspirantService.getManagers());
return "admin/editAspirant";

View File

@ -1,9 +1,9 @@
package ru.ulstu.admin.model;
import ru.ulstu.aspirant.model.Aspirant;
import ru.ulstu.aspirant.model.Base;
import ru.ulstu.aspirant.model.Speciality;
import ru.ulstu.indicator.model.Course;
import ru.ulstu.manager.model.Manager;
import java.util.Date;
@ -18,7 +18,7 @@ public class AspirantForm {
private Course course;
private Manager manager;
private Integer managerId;
private Date birthDate;
@ -28,6 +28,22 @@ public class AspirantForm {
private Base base;
public AspirantForm() {
}
public AspirantForm(Aspirant aspirant) {
this.id = aspirant.getId();
this.name = aspirant.getName();
this.surname = aspirant.getSurname();
this.patronymic = aspirant.getPatronymic();
this.base = aspirant.getBase();
this.course = aspirant.getCourse();
this.managerId = aspirant.getManager() == null ? null : aspirant.getManager().getId();
this.birthDate = aspirant.getBirthDate();
this.speciality = aspirant.getSpeciality();
this.theme = aspirant.getTheme();
}
public Integer getId() {
return id;
}
@ -68,12 +84,12 @@ public class AspirantForm {
this.course = course;
}
public Manager getManager() {
return manager;
public Integer getManagerId() {
return managerId;
}
public void setManager(Manager manager) {
this.manager = manager;
public void setManagerId(Integer managerId) {
this.managerId = managerId;
}
public Date getBirthDate() {

View File

@ -30,14 +30,14 @@ public class AdminAspirantService {
public void saveAspirant(AspirantForm aspirantForm) {
Aspirant aspirant = aspirantForm.getId() == null
? new Aspirant(aspirantForm)
? new Aspirant()
: aspirantService.getAspirantById(aspirantForm.getId());
aspirant.setName(aspirantForm.getName());
aspirant.setSurname(aspirantForm.getSurname());
aspirant.setPatronymic(aspirantForm.getPatronymic());
aspirant.setBase(aspirantForm.getBase());
aspirant.setCourse(aspirantForm.getCourse());
aspirant.setManager(aspirantForm.getManager());
aspirant.setManager(managerService.getManagerById(aspirantForm.getManagerId()));
aspirant.setBirthDate(aspirantForm.getBirthDate());
aspirant.setSpeciality(aspirantForm.getSpeciality());
aspirant.setTheme(aspirantForm.getTheme());

View File

@ -8,7 +8,6 @@ import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import ru.ulstu.admin.model.AspirantForm;
import ru.ulstu.indicator.model.Course;
import ru.ulstu.manager.model.Manager;
import ru.ulstu.model.BaseEntity;
@ -42,17 +41,6 @@ public class Aspirant extends BaseEntity {
@Enumerated(EnumType.STRING)
private Base base;
public Aspirant(AspirantForm aspirantForm) {
this.name = aspirantForm.getName();
this.surname = aspirantForm.getSurname();
this.patronymic = aspirantForm.getPatronymic();
this.theme = aspirantForm.getTheme();
this.manager = aspirantForm.getManager();
this.speciality = aspirantForm.getSpeciality();
this.base = aspirantForm.getBase();
this.birthDate = aspirantForm.getBirthDate();
}
public Aspirant() {
}

View File

@ -74,9 +74,9 @@
<label for="manager">Научный руководитель</label>
<select class="form-select form-control"
id="manager" aria-label="select example"
th:field="*{manager}">
th:field="*{managerId}">
<option th:each="m : ${managers}"
th:value="${m}"
th:value="${m.id}"
th:text="${m.name}">
</option>
</select>