source: trip-planner/src/main/java/finki/diplomska/tripplanner/models/User.java

Last change on this file was 6fe77af, checked in by Ema <ema_spirova@…>, 3 years ago

add location feature

  • Property mode set to 100644
File size: 2.5 KB
Line 
1package finki.diplomska.tripplanner.models;
2
3import com.fasterxml.jackson.annotation.JsonIgnore;
4import com.fasterxml.jackson.annotation.JsonManagedReference;
5import lombok.AllArgsConstructor;
6import lombok.Getter;
7import lombok.Setter;
8import org.springframework.security.core.GrantedAuthority;
9import org.springframework.security.core.userdetails.UserDetails;
10
11import javax.persistence.*;
12import javax.validation.constraints.Email;
13import javax.validation.constraints.NotBlank;
14import java.util.ArrayList;
15import java.util.Collection;
16import java.util.Date;
17import java.util.List;
18
19@Entity
20@Table(name = "users")
21@AllArgsConstructor
22@Getter
23@Setter
24public class User implements UserDetails {
25
26 @Id
27 @GeneratedValue(strategy = GenerationType.IDENTITY)
28 private Long id;
29
30 @Email(message = "Username needs to be an email")
31 @NotBlank(message = "username is required")
32 @Column(unique = true)
33 private String username;
34 @NotBlank(message = "Please enter your full name")
35 private String fullName;
36 @NotBlank(message = "Password field is required")
37 private String password;
38 @Transient
39 private String confirmPassword;
40 private Date create_At;
41 private Date update_At;
42
43 //OneToMany with Planners
44 @OneToMany(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER, mappedBy = "user", orphanRemoval = true)
45 @JsonIgnore
46 private List<Planner> planners = new ArrayList<>();
47
48 @OneToMany(cascade = CascadeType.REFRESH, mappedBy = "user", orphanRemoval = true)
49 @JsonIgnore
50 private List<Location> locationList = new ArrayList<>();;
51
52 public User() {
53 }
54
55 public User(String username, String fullName, String password, String confirmPassword) {
56 this.username = username;
57 this.fullName = fullName;
58 this.password = password;
59 this.confirmPassword = confirmPassword;
60 }
61
62 @PrePersist
63 protected void onCreate(){
64 this.create_At = new Date();
65 }
66 @PreUpdate
67 protected void onUpdate(){
68 this.update_At = new Date();
69 }
70
71 @Override
72 @JsonIgnore
73 public Collection<? extends GrantedAuthority> getAuthorities() {
74 return null;
75 }
76
77 @Override
78 @JsonIgnore
79 public boolean isAccountNonExpired() {
80 return true;
81 }
82
83 @Override
84 @JsonIgnore
85 public boolean isAccountNonLocked() {
86 return true;
87 }
88
89 @Override
90 @JsonIgnore
91 public boolean isCredentialsNonExpired() {
92 return true;
93 }
94
95 @Override
96 @JsonIgnore
97 public boolean isEnabled() {
98 return true;
99 }
100}
Note: See TracBrowser for help on using the repository browser.