1차 팀프로젝트 11회차

이동원·2024년 6월 26일

Review 엔티티 작성

  • 데이터를 명확히 구조화 하여 관리 및 검색을 보장하기 위함
@Getter
@Setter
@Entity
@NoArgsConstructor
public class Review {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    @Column(length = 50)
    private String title;
    @Column(columnDefinition = "LONGTEXT")
    private String content;
    @ManyToOne(fetch = FetchType.LAZY)
    private Product product; //물건에 리뷰를 다니깐.
    @ManyToOne(fetch = FetchType.LAZY)
    private SiteUser author; //글쓴이(작성자)
    private Double grade; //평점(별점)
    private LocalDateTime createDate;
    private LocalDateTime modifyDate;


    @Builder //LocalDateTime  createDate 은 내가 굳이 받을필요없다. 내가 알아서 세팅 해줄수있다.
    private Review(SiteUser siteUser, Product product, String title, String content, Double grade) {
        this.author = siteUser;
        this.product = product;
        this.title = title;
        this.content = content;
        this.grade = grade;
        this.createDate = LocalDateTime.now();
    }


}

ReviewRequestDTO 작성

  • 상대방이 주고싶은 정보만 주려고 , 안전하기때문에.


@Getter
public class ReviewRequestDTO { //요청받는것
private Long productId;
private Long reviewId;
private String title;
private String content;
private Double grade;

}

ReviewResponseDTO 작성

  • 내가 주고싶은 정보만 주려고 , 안전하기때문에
@Getter
@Setter
@NoArgsConstructor  ////2번째
public class ReviewResponseDTO {

    private String title;
    private String content;
    private Double grade;
    private Long id;
    private Long createDate;
    private Long modifyDate;
    private String author;
// 객체로 못보낸다 ex) private Product product;


    @Builder// 보낼떄 Review review 를  ReviewResponseDTO 로 보내야하므로.
    private ReviewResponseDTO(Review review , Long createDate , Long modifyDate){  //같은클래스이름  , //원래는 LocalDateTime 인데 ,Long 으로밖에 못보내서
      this.title= review.getTitle();
      this.content= review.getContent();
      this.grade= review.getGrade();
      this.id=review.getId();
      this.author=review.getAuthor().getNickname();
      this.createDate=createDate;
      this.modifyDate=modifyDate;


    }

}

0개의 댓글