UserCommons.java

  1. package edu.ucsb.cs156.happiercows.entities;

  2. import com.fasterxml.jackson.annotation.JsonIgnore;
  3. import com.fasterxml.jackson.annotation.JsonInclude;
  4. import lombok.*;

  5. import javax.persistence.EmbeddedId;
  6. import javax.persistence.Entity;
  7. import javax.persistence.ManyToOne;
  8. import javax.persistence.MapsId;

  9. @Data
  10. @AllArgsConstructor
  11. @NoArgsConstructor(access = AccessLevel.PROTECTED)
  12. @Builder
  13. @Entity(name = "user_commons")
  14. public class UserCommons {
  15.     @EmbeddedId
  16.     @JsonIgnore
  17.     @Builder.Default
  18.     private UserCommonsKey id = new UserCommonsKey();

  19.     @MapsId("userId")
  20.     @ManyToOne
  21.     @JsonIgnore
  22.     private User user;

  23.     @MapsId("commonsId")
  24.     @ManyToOne
  25.     @JsonIgnore
  26.     private Commons commons;

  27.     private String username;

  28.     private double totalWealth;

  29.     private int numOfCows;

  30.     private double cowHealth;

  31.     private int cowsBought;

  32.     private int cowsSold;

  33.     private int cowDeaths;

  34.     // userID and commonsId are used by the frontend
  35.     @JsonInclude
  36.     public long getUserId() {
  37.       return user.getId();
  38.     }

  39.     @JsonInclude
  40.     public long getCommonsId() {
  41.         return commons.getId();
  42.     }

  43.     public void setId(UserCommonsKey id) {
  44.         this.id = id;
  45.     }
  46.      public UserCommonsKey getId() {
  47.         return this.id;
  48.     }
  49. }