Advertisement
Guest User

UserClass

a guest
Mar 22nd, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.43 KB | None | 0 0
  1. package com.team5.beertag.models;
  2.  
  3. import com.fasterxml.jackson.annotation.JsonIgnore;
  4. import org.hibernate.annotations.LazyCollection;
  5. import org.hibernate.annotations.LazyCollectionOption;
  6.  
  7. import javax.persistence.*;
  8. import javax.validation.constraints.Size;
  9. import java.util.List;
  10. import java.util.Objects;
  11. import java.util.Set;
  12.  
  13. @Entity
  14. @Table(name = "users")
  15. public class User {
  16.  
  17.     @Id
  18.     @GeneratedValue(strategy = GenerationType.IDENTITY)
  19.     @Column(name = "user_id")
  20.     private int id;
  21.  
  22.     @Column(name = "username")
  23.     @Size(min = 2, max = 15, message = "Username must be between 2 and 15 characters.")
  24.     private String username;
  25.  
  26.     @Column(name = "role_id")
  27.     @Size(min = 2, max = 10, message = "User role must be between 2 and 10 characters.")
  28.     private String userRole;
  29.  
  30.     @Column(name = "avatar_url")
  31.     @Size(min = 2, max = 255, message = "Avatar URL must be between 2 and 255 characters.")
  32.     private String avatarURL;
  33.  
  34.     @Column(name = "password")
  35.     @Size(min = 5, max = 10, message = "Password must be between 5 and 10 characters.")
  36.     private String password;
  37.  
  38.     @LazyCollection(LazyCollectionOption.FALSE)
  39.     @OneToMany(mappedBy = "user")
  40.     private Set<BeerStatus> beerStatuses;
  41.  
  42.     @OneToMany(mappedBy = "user")
  43.     private List<Rating> beerRatings;
  44.  
  45.     public User() {
  46.     }
  47.  
  48.     public User(String username, String password, String userRole, String avatarURL) {
  49.         this.username = username;
  50.         this.password = password;
  51.         this.userRole = userRole;
  52.         this.avatarURL = avatarURL;
  53.     }
  54.  
  55.     private void setUsername(String username) {
  56.         this.username = username;
  57.     }
  58.  
  59.     private void setUserRole(String userRole) {
  60.         this.userRole = userRole;
  61.     }
  62.  
  63.     private void setAvatarURL(String avatarURL) {
  64.         this.avatarURL = avatarURL;
  65.     }
  66.  
  67.     public int getId() {
  68.         return id;
  69.     }
  70.  
  71.     public String getUsername() {
  72.         return username;
  73.     }
  74.  
  75.     public String getUserRole() {
  76.         return userRole;
  77.     }
  78.  
  79.     public String getAvatarURL() {
  80.         return avatarURL;
  81.     }
  82.  
  83.     public String getPassword() {
  84.         return password;
  85.     }
  86.  
  87.     public void setPassword(String password) {
  88.         this.password = password;
  89.     }
  90.  
  91.     public Set<BeerStatus> getBeerStatuses() {
  92.         return beerStatuses;
  93.     }
  94.  
  95.     public void setBeerStatuses(Set<BeerStatus> beerStatuses) {
  96.         this.beerStatuses = beerStatuses;
  97.     }
  98.  
  99.     @Override
  100.     public boolean equals(Object o) {
  101.         if (o == this) return true;
  102.         if (!(o instanceof User)) {
  103.             return false;
  104.         }
  105.  
  106.         User other = (User) o;
  107.  
  108.         return this.getUsername().equals(other.getUsername());
  109.     }
  110.  
  111.     @Override
  112.     public int hashCode() {
  113.         return Objects.hash(this.getUsername());
  114.     }
  115. @JsonIgnore
  116.     public List<Rating> getBeerRatings() {
  117.         return beerRatings;
  118.     }
  119.  
  120.     public void setBeerRatings(List<Rating> beerRatings) {
  121.         this.beerRatings = beerRatings;
  122.     }
  123. }
  124.  
  125.  
  126. //   @OneToMany
  127. //    @LazyCollection(LazyCollectionOption.FALSE)
  128. //    @JoinTable(
  129. //            name = "user_beer_wishlist",
  130. //            joinColumns = @JoinColumn(name = "user_id"),
  131. //            inverseJoinColumns = @JoinColumn(name = "Beer_id")
  132. //    )
  133. //    private List<Beer> wishlist;
  134. //
  135. //    @OneToMany
  136. //    @LazyCollection(LazyCollectionOption.FALSE)
  137. //    @JoinTable(
  138. //            name = "tasted_beer",
  139. //            joinColumns = @JoinColumn(name = "user_id"),
  140. //            inverseJoinColumns = @JoinColumn(name = "Beer_id")
  141. //    )
  142. //    private List<Beer> tasted;
  143. //
  144. //    @OneToMany
  145. //    @LazyCollection(LazyCollectionOption.FALSE)
  146. //    @JoinTable(
  147. //            name = "Ratings",
  148. //            joinColumns = @JoinColumn(name = "user_id"),
  149. //            inverseJoinColumns = @JoinColumn(name = "beer_id")
  150. //    )
  151. //    private List<Beer> rated;
  152. //
  153. //
  154. //    public List<Beer> getWishlist() {
  155. //        return wishlist;
  156. //    }
  157. //
  158. //    public void setWishlist(List<Beer> wishlist) {
  159. //        this.wishlist = wishlist;
  160. //    }
  161. //
  162. //    public List<Beer> getTasted() {
  163. //        return tasted;
  164. //    }
  165. //
  166. //    public void setTasted(List<Beer> tasted) {
  167. //        this.tasted = tasted;
  168. //    }
  169. //
  170. //    public List<Beer> getRated() {
  171. //        return rated;
  172. //    }
  173. //
  174. //    public void setRated(List<Beer> rated) {
  175. //        this.rated = rated;
  176. //    }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement