Commit 2a27f25c authored by Samuel Dudík's avatar Samuel Dudík
Browse files

Add entity and DAO for User and ProductReview

parent 8eab4d35
package cz.muni.fi.pa165.winery.persistence.dao.review;
import cz.muni.fi.pa165.winery.persistence.dao.DaoBase;
import cz.muni.fi.pa165.winery.persistence.entities.ProductReview;
/**
* @author Samuel Dudík
*/
public interface ProductReviewDao extends DaoBase<ProductReview> {
}
package cz.muni.fi.pa165.winery.persistence.dao.review;
import cz.muni.fi.pa165.winery.persistence.dao.DaoBaseImpl;
import cz.muni.fi.pa165.winery.persistence.entities.ProductReview;
/**
* @author Samuel Dudík
*/
public class ProductReviewDaoImpl extends DaoBaseImpl<ProductReview> implements ProductReviewDao {
public ProductReviewDaoImpl() {
super(ProductReview.class);
}
}
\ No newline at end of file
package cz.muni.fi.pa165.winery.persistence.dao.user;
public interface UserDao {
import cz.muni.fi.pa165.winery.persistence.dao.DaoBase;
import cz.muni.fi.pa165.winery.persistence.entities.User;
/**
* @author Samuel Dudík
*/
public interface UserDao extends DaoBase<User> {
}
package cz.muni.fi.pa165.winery.persistence.dao.user;
public class UserDaoImpl {
import cz.muni.fi.pa165.winery.persistence.dao.DaoBaseImpl;
import cz.muni.fi.pa165.winery.persistence.entities.User;
/**
* @author Samuel Dudík
*/
public class UserDaoImpl extends DaoBaseImpl<User> implements UserDao {
public UserDaoImpl() {
super(User.class);
}
}
package cz.muni.fi.pa165.winery.persistence.entities;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
/**
* @author Samuel Dudík
*
* Review of a product the user has bought.
*/
@Getter
@Setter
@Entity
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "ProductReview")
public class ProductReview extends EntityBase {
/**
* Grade given to the reviewed product
*
* Has to be in range <0, 10>.
*/
@NotNull
@Size(max = 10)
private short grade;
/**
* Review description
*
* Optional description specifying more details.
*/
private String text;
/**
* User that submitted this review
*/
@ManyToOne(fetch = FetchType.LAZY)
@Fetch(FetchMode.SELECT)
private User user;
/**
* The wine bottle being reviewed
*/
@ManyToOne(fetch = FetchType.LAZY)
@Fetch(FetchMode.SELECT)
private WineBottle wineBottle;
}
package cz.muni.fi.pa165.winery.persistence.entities;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
......@@ -9,13 +11,69 @@ import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import java.util.ArrayList;
import java.util.List;
/**
* @author Samuel Dudík
*
* User represents the basic user role which can buy products and review them.
*/
@Getter
@Setter
@Entity
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "ApplicationUser")
public class User extends EntityBase {
/**
* User's first name (forename)
*/
@NotBlank
private String firstName;
/**
* User's last name (surname)
*/
@NotBlank
private String lastName;
/**
* User's email address
*/
@NotBlank
@Email
private String email;
/**
* The hash of the user submitted password
*
* Will be used for authentication.
*/
@NotBlank
private String passwordHash;
/**
* User's previous orders
*/
@OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
@Fetch(FetchMode.SELECT)
private List<Order> orders = new ArrayList<>();
/**
* User's product reviews
*/
@OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
@Fetch(FetchMode.SELECT)
private List<ProductReview> reviews = new ArrayList<>();
/**
* Roles assigned to this user
*/
@OneToMany(fetch = FetchType.EAGER, mappedBy = "user")
@Fetch(FetchMode.SELECT)
private List<UserRole> roles = new ArrayList<>();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment