1 | package com.wediscussmovies.project.model;
|
---|
2 |
|
---|
3 | import com.wediscussmovies.project.model.relation.MovieLikes;
|
---|
4 | import com.wediscussmovies.project.model.relation.UserGenres;
|
---|
5 | import com.wediscussmovies.project.model.relation.MovieRates;
|
---|
6 | import com.wediscussmovies.project.model.relation.PersonRates;
|
---|
7 | import lombok.Data;
|
---|
8 | import org.springframework.security.core.GrantedAuthority;
|
---|
9 | import org.springframework.security.core.userdetails.UserDetails;
|
---|
10 |
|
---|
11 | import javax.persistence.*;
|
---|
12 | import java.util.ArrayList;
|
---|
13 | import java.util.Collection;
|
---|
14 | import java.util.Objects;
|
---|
15 |
|
---|
16 | @Entity
|
---|
17 | @Table(name = "users", schema = "project", catalog = "db_202122z_va_prj_wediscussmovies")
|
---|
18 | @Data
|
---|
19 | public class User implements UserDetails {
|
---|
20 | @GeneratedValue(strategy = GenerationType.IDENTITY)
|
---|
21 | @Id
|
---|
22 | @Column(name = "user_id")
|
---|
23 | private int userId;
|
---|
24 | @Basic
|
---|
25 | @Column(name = "username")
|
---|
26 | private String username;
|
---|
27 | @Basic
|
---|
28 | @Column(name = "name")
|
---|
29 | private String name;
|
---|
30 | @Basic
|
---|
31 | @Column(name = "surname")
|
---|
32 | private String surname;
|
---|
33 | @Basic
|
---|
34 | @Column(name = "email")
|
---|
35 | private String email;
|
---|
36 | @Basic
|
---|
37 | @Column(name = "password")
|
---|
38 | private String password;
|
---|
39 | @OneToMany(mappedBy = "user")
|
---|
40 | private Collection<Discussion> discussions;
|
---|
41 | @OneToMany(mappedBy = "user")
|
---|
42 | private Collection<MovieLikes> movieLikes;
|
---|
43 | @OneToMany(mappedBy = "user")
|
---|
44 | private Collection<MovieRates> movieRates;
|
---|
45 | @OneToMany(mappedBy = "user")
|
---|
46 | private Collection<PersonRates> personRates;
|
---|
47 | @OneToMany(mappedBy = "user")
|
---|
48 | private Collection<Reply> replies;
|
---|
49 | @OneToMany(mappedBy = "user")
|
---|
50 | private Collection<UserGenres> userGenres;
|
---|
51 |
|
---|
52 | public User() {
|
---|
53 |
|
---|
54 | }
|
---|
55 |
|
---|
56 |
|
---|
57 |
|
---|
58 | @Override
|
---|
59 | public boolean isAccountNonExpired() {
|
---|
60 | return true;
|
---|
61 | }
|
---|
62 |
|
---|
63 | @Override
|
---|
64 | public boolean isAccountNonLocked() {
|
---|
65 | return true;
|
---|
66 | }
|
---|
67 |
|
---|
68 | @Override
|
---|
69 | public boolean isCredentialsNonExpired() {
|
---|
70 | return true;
|
---|
71 | }
|
---|
72 |
|
---|
73 | @Override
|
---|
74 | public boolean isEnabled() {
|
---|
75 | return true;
|
---|
76 | }
|
---|
77 |
|
---|
78 |
|
---|
79 | @Override
|
---|
80 | public Collection<? extends GrantedAuthority> getAuthorities() {
|
---|
81 | return new ArrayList<>();
|
---|
82 | }
|
---|
83 |
|
---|
84 | public User( String email,String username , String password, String name,String surname) {
|
---|
85 | this.username = username;
|
---|
86 | this.name = name;
|
---|
87 | this.surname = surname;
|
---|
88 | this.email = email;
|
---|
89 | this.password = password;
|
---|
90 | }
|
---|
91 |
|
---|
92 | @Override
|
---|
93 | public boolean equals(Object o) {
|
---|
94 | if (this == o) return true;
|
---|
95 | if (o == null || getClass() != o.getClass()) return false;
|
---|
96 | User user = (User) o;
|
---|
97 | return userId == user.userId;
|
---|
98 | }
|
---|
99 |
|
---|
100 | @Override
|
---|
101 | public int hashCode() {
|
---|
102 | return Objects.hash(userId);
|
---|
103 | }
|
---|
104 | }
|
---|