Partially add aspirant user
This commit is contained in:
parent
fc480dd559
commit
d36bdf6eca
@ -9,24 +9,17 @@ import java.util.Date;
|
|||||||
|
|
||||||
public class AspirantForm {
|
public class AspirantForm {
|
||||||
private Integer id;
|
private Integer id;
|
||||||
|
|
||||||
private String surname;
|
private String surname;
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
private String patronymic;
|
private String patronymic;
|
||||||
|
|
||||||
private Course course;
|
private Course course;
|
||||||
|
|
||||||
private Integer managerId;
|
private Integer managerId;
|
||||||
|
|
||||||
private Date birthDate;
|
private Date birthDate;
|
||||||
|
|
||||||
private Speciality speciality;
|
private Speciality speciality;
|
||||||
|
|
||||||
private String theme;
|
private String theme;
|
||||||
|
|
||||||
private Base base;
|
private Base base;
|
||||||
|
private Integer userId;
|
||||||
|
private String email;
|
||||||
|
|
||||||
public AspirantForm() {
|
public AspirantForm() {
|
||||||
}
|
}
|
||||||
@ -42,6 +35,8 @@ public class AspirantForm {
|
|||||||
this.birthDate = aspirant.getBirthDate();
|
this.birthDate = aspirant.getBirthDate();
|
||||||
this.speciality = aspirant.getSpeciality();
|
this.speciality = aspirant.getSpeciality();
|
||||||
this.theme = aspirant.getTheme();
|
this.theme = aspirant.getTheme();
|
||||||
|
this.userId = aspirant.getUser() == null ? null : aspirant.getUser().getId();
|
||||||
|
this.email = aspirant.getUser() == null ? null : aspirant.getUser().getLogin();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
@ -123,4 +118,20 @@ public class AspirantForm {
|
|||||||
public void setBase(Base base) {
|
public void setBase(Base base) {
|
||||||
this.base = base;
|
this.base = base;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Integer getUserId() {
|
||||||
|
return userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserId(Integer userId) {
|
||||||
|
this.userId = userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmail(String email) {
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,8 @@ import ru.ulstu.aspirant.model.Aspirant;
|
|||||||
import ru.ulstu.aspirant.service.AspirantService;
|
import ru.ulstu.aspirant.service.AspirantService;
|
||||||
import ru.ulstu.manager.model.Manager;
|
import ru.ulstu.manager.model.Manager;
|
||||||
import ru.ulstu.manager.service.ManagerService;
|
import ru.ulstu.manager.service.ManagerService;
|
||||||
|
import ru.ulstu.model.User;
|
||||||
|
import ru.ulstu.user.UserService;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -13,11 +15,14 @@ import java.util.List;
|
|||||||
public class AdminAspirantService {
|
public class AdminAspirantService {
|
||||||
private final AspirantService aspirantService;
|
private final AspirantService aspirantService;
|
||||||
private final ManagerService managerService;
|
private final ManagerService managerService;
|
||||||
|
private final UserService userService;
|
||||||
|
|
||||||
public AdminAspirantService(AspirantService aspirantService,
|
public AdminAspirantService(AspirantService aspirantService,
|
||||||
ManagerService managerService) {
|
ManagerService managerService,
|
||||||
|
UserService userService) {
|
||||||
this.aspirantService = aspirantService;
|
this.aspirantService = aspirantService;
|
||||||
this.managerService = managerService;
|
this.managerService = managerService;
|
||||||
|
this.userService = userService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Aspirant> getAspirants() {
|
public List<Aspirant> getAspirants() {
|
||||||
@ -41,6 +46,13 @@ public class AdminAspirantService {
|
|||||||
aspirant.setBirthDate(aspirantForm.getBirthDate());
|
aspirant.setBirthDate(aspirantForm.getBirthDate());
|
||||||
aspirant.setSpeciality(aspirantForm.getSpeciality());
|
aspirant.setSpeciality(aspirantForm.getSpeciality());
|
||||||
aspirant.setTheme(aspirantForm.getTheme());
|
aspirant.setTheme(aspirantForm.getTheme());
|
||||||
|
User user = userService.getUserById(aspirantForm.getUserId());
|
||||||
|
if (!user.getLogin().equals(aspirantForm.getEmail())) {
|
||||||
|
user.setLogin(aspirantForm.getEmail());
|
||||||
|
userService.createUser(user);
|
||||||
|
}
|
||||||
|
aspirant.setUser(user);
|
||||||
|
|
||||||
aspirantService.save(aspirant);
|
aspirantService.save(aspirant);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ import jakarta.validation.constraints.NotNull;
|
|||||||
import ru.ulstu.indicator.model.Course;
|
import ru.ulstu.indicator.model.Course;
|
||||||
import ru.ulstu.manager.model.Manager;
|
import ru.ulstu.manager.model.Manager;
|
||||||
import ru.ulstu.model.BaseEntity;
|
import ru.ulstu.model.BaseEntity;
|
||||||
|
import ru.ulstu.model.User;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@ -41,6 +42,9 @@ public class Aspirant extends BaseEntity {
|
|||||||
@Enumerated(EnumType.STRING)
|
@Enumerated(EnumType.STRING)
|
||||||
private Base base;
|
private Base base;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
private User user;
|
||||||
|
|
||||||
public Aspirant() {
|
public Aspirant() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,4 +124,12 @@ public class Aspirant extends BaseEntity {
|
|||||||
public void setBase(Base base) {
|
public void setBase(Base base) {
|
||||||
this.base = base;
|
this.base = base;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public User getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUser(User user) {
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,11 +57,19 @@ public class UserService implements UserDetailsService {
|
|||||||
if (getUserByLogin(user.getLogin()) != null) {
|
if (getUserByLogin(user.getLogin()) != null) {
|
||||||
throw new RuntimeException(user.getLogin());
|
throw new RuntimeException(user.getLogin());
|
||||||
}
|
}
|
||||||
|
User dbUser = (user.getId() == null)
|
||||||
|
? user
|
||||||
|
: getUserById(user.getId());
|
||||||
//user.setRoles(Collections.singleton(new UserRole(UserRoleConstants.USER)));
|
//user.setRoles(Collections.singleton(new UserRole(UserRoleConstants.USER)));
|
||||||
user.setPassword(passwordEncoder.encode(user.getPassword()));
|
dbUser.setPassword(passwordEncoder.encode(user.getPassword()));
|
||||||
user = userRepository.save(user);
|
dbUser.setLogin(user.getLogin());
|
||||||
log.debug("Created Information for User: {}", user.getLogin());
|
dbUser = userRepository.save(dbUser);
|
||||||
return user;
|
log.debug("Created Information for User: {}", dbUser.getLogin());
|
||||||
|
return dbUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
public User getUserById(Integer id) {
|
||||||
|
return userRepository.findById(id).orElseThrow(() -> new RuntimeException("User not found by id"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createDefaultUser(String login, String userRole) {
|
private void createDefaultUser(String login, String userRole) {
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
th:object="${aspirant}"
|
th:object="${aspirant}"
|
||||||
method="post">
|
method="post">
|
||||||
<input type="hidden" th:field="*{id}">
|
<input type="hidden" th:field="*{id}">
|
||||||
|
<input type="hidden" th:field="*{userId}">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="surname">Фамилия</label>
|
<label for="surname">Фамилия</label>
|
||||||
<input th:field="*{surname}"
|
<input th:field="*{surname}"
|
||||||
@ -49,6 +50,20 @@
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="email">Email</label>
|
||||||
|
<input th:field="*{email}"
|
||||||
|
id="email"
|
||||||
|
required
|
||||||
|
type="email"
|
||||||
|
class="form-control"
|
||||||
|
placeholder="Email">
|
||||||
|
<p th:if="${#fields.hasErrors('email')}"
|
||||||
|
th:class="${#fields.hasErrors('email')}? error">
|
||||||
|
Не может быть пустым
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="course">Курс</label>
|
<label for="course">Курс</label>
|
||||||
<select class="form-select form-control"
|
<select class="form-select form-control"
|
||||||
|
Loading…
Reference in New Issue
Block a user