-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBookReview.java
More file actions
79 lines (63 loc) · 2.53 KB
/
BookReview.java
File metadata and controls
79 lines (63 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package com.hansung.leafly.domain.bookreview.entity;
import com.hansung.leafly.domain.bookreview.web.dto.ReviewReq;
import com.hansung.leafly.domain.bookreview.web.dto.ReviewUpdateReq;
import com.hansung.leafly.domain.member.entity.Member;
import com.hansung.leafly.global.entity.BaseEntity;
import jakarta.persistence.*;
import lombok.*;
import java.util.ArrayList;
import java.util.List;
@Getter
@Builder
@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PROTECTED)
@Table(name = "BOOKREVIEWS")
public class BookReview extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "bookreview_id")
private Long id;
@Column(nullable = false)
private String title;
@Column(nullable = false)
private String author;
@Column(nullable = false)
private String thumbnail;
@Column(nullable = false)
private Integer rating;
@Column(nullable =true, name = "review_title")
private String reviewTitle;
@Column(nullable = false, columnDefinition = "TEXT")
private String content;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id", nullable = false)
private Member member;
@OneToMany(mappedBy = "bookReview", cascade = CascadeType.ALL, orphanRemoval = true)
private List<BookTag> tags = new ArrayList<>();
@OneToMany(mappedBy = "bookReview", cascade = CascadeType.ALL, orphanRemoval = true)
private List<ReviewImage> images = new ArrayList<>();
public static BookReview toEntity(Member member, ReviewReq req) {
return BookReview.builder()
.member(member)
.title(req.getTitle())
.author(req.getAuthor())
.thumbnail(req.getThumbnail())
.rating(req.getRating())
.reviewTitle(req.getReviewTitle())
.content(req.getContent())
.build();
}
public void update(ReviewUpdateReq req) {
if (req.getTitle() != null) this.title = req.getTitle();
if (req.getAuthor() != null) this.author = req.getAuthor();
if (req.getThumbnail() != null) this.thumbnail = req.getThumbnail();
if (req.getRating() != null) this.rating = req.getRating();
if (req.getReviewTitle() != null) this.reviewTitle = req.getReviewTitle();
if (req.getContent() != null) this.content = req.getContent();
}
public void replaceImages(List<ReviewImage> newImages) {
this.images.clear();
this.images.addAll(newImages);
}
}