From 7465803162b6ecad6771c5ef60122f9c4abedb07 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Fri, 5 Apr 2019 22:06:16 +0400 Subject: [PATCH] #42 add columns 'birth_date'&'degree' to User --- src/main/java/ru/ulstu/user/model/User.java | 40 +++++++++++++++++++ .../java/ru/ulstu/user/model/UserDto.java | 27 +++++++++++++ .../db/changelog-20190404_000000-schema.xml | 13 ++++++ 3 files changed, 80 insertions(+) create mode 100644 src/main/resources/db/changelog-20190404_000000-schema.xml diff --git a/src/main/java/ru/ulstu/user/model/User.java b/src/main/java/ru/ulstu/user/model/User.java index de9f028..40f1f45 100644 --- a/src/main/java/ru/ulstu/user/model/User.java +++ b/src/main/java/ru/ulstu/user/model/User.java @@ -7,6 +7,8 @@ import ru.ulstu.core.model.BaseEntity; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToMany; @@ -83,6 +85,28 @@ public class User extends BaseEntity { @BatchSize(size = 20) private Set roles; + @Size(max = 4) + @Column(name = "birth_year", length = 4) + private Integer birthYear; + + public enum UserDegree { + CANDIDATE("Кандидат технических наук"), + DOCTOR("Доктор технических наук"); + + private String degreeName; + + UserDegree(String degreeName) { + this.degreeName = degreeName; + } + + public String getDegreeName() { + return degreeName; + } + } + + @Enumerated(value = EnumType.STRING) + private UserDegree degree; + public User() { roles = new HashSet<>(); activated = false; @@ -186,4 +210,20 @@ public class User extends BaseEntity { public void setPatronymic(String patronymic) { this.patronymic = patronymic; } + + public Integer getBirthYear() { + return birthYear; + } + + public void setBirthYear(Integer birthYear) { + this.birthYear = birthYear; + } + + public UserDegree getDegree() { + return degree; + } + + public void setDegree(UserDegree degree) { + this.degree = degree; + } } diff --git a/src/main/java/ru/ulstu/user/model/UserDto.java b/src/main/java/ru/ulstu/user/model/UserDto.java index c98e0bb..dadfe99 100644 --- a/src/main/java/ru/ulstu/user/model/UserDto.java +++ b/src/main/java/ru/ulstu/user/model/UserDto.java @@ -70,6 +70,13 @@ public class UserDto implements OdinDto { @Size(min = Constants.MIN_PASSWORD_LENGTH, max = 50) private String passwordConfirm; + @OdinCaption("Год рождения") + @Size(max = 4) + private Integer birthYear; + + @OdinCaption("Ученая степень") + private User.UserDegree degree; + public UserDto() { activated = false; roles = new LinkedHashSet<>(); @@ -86,6 +93,8 @@ public class UserDto implements OdinDto { this.roles.addAll(user.getRoles().stream() .map(UserRoleDto::new) .collect(Collectors.toList())); + this.birthYear = user.getBirthYear(); + this.degree = user.getDegree(); } public Integer getId() { @@ -163,6 +172,22 @@ public class UserDto implements OdinDto { return passwordConfirm; } + public Integer getBirthYear() { + return birthYear; + } + + public void setBirthYear(Integer birthYear) { + this.birthYear = birthYear; + } + + public User.UserDegree getDegree() { + return degree; + } + + public void setDegree(User.UserDegree degree) { + this.degree = degree; + } + @JsonIgnore public boolean isPasswordsValid() { if (StringUtils.isEmpty(password) || StringUtils.isEmpty(passwordConfirm)) { @@ -188,6 +213,8 @@ public class UserDto implements OdinDto { ", roles=" + roles + ", password='" + password + '\'' + ", passwordConfirm='" + passwordConfirm + '\'' + + ", birthYear='" + birthYear + '\'' + + ", degree='" + degree + '\'' + '}'; } } diff --git a/src/main/resources/db/changelog-20190404_000000-schema.xml b/src/main/resources/db/changelog-20190404_000000-schema.xml new file mode 100644 index 0000000..251905c --- /dev/null +++ b/src/main/resources/db/changelog-20190404_000000-schema.xml @@ -0,0 +1,13 @@ + + + + + + + + + + +