Skip to content

Commit

Permalink
FIX : PR 오류 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
choidongkuen committed Dec 20, 2023
1 parent 6174fb3 commit 795648b
Show file tree
Hide file tree
Showing 23 changed files with 1,305 additions and 232 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@
import com.example.betteriter.fo_domain.user.domain.Users;
import com.example.betteriter.global.common.entity.BaseEntity;
import com.example.betteriter.global.constant.Status;
import lombok.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.Where;

import javax.persistence.*;

@Slf4j
@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Where(clause = "status = 'ACTIVE'")
@Entity(name = "COMMENT")
public class Comment extends BaseEntity {
@Id
Expand Down Expand Up @@ -44,6 +47,17 @@ public class Comment extends BaseEntity {
@Enumerated(EnumType.STRING)
private Status status; // 댓글 상태: ACTIVE, INACTIVE, DELETED

@Builder
private Comment(Review review, Users users, String comment,
Integer orderNum, Integer groupId, Status status) {
this.review = review;
this.users = users;
this.comment = comment;
this.orderNum = orderNum;
this.groupId = groupId;
this.status = status;
}

public boolean isDeleted() {
return this.status == Status.DELETED;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@


import com.example.betteriter.fo_domain.user.domain.Users;
import lombok.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import javax.persistence.*;

@Slf4j
@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Entity(name = "COMMENT_LIKE")
public class CommentLike {
Expand All @@ -25,4 +26,10 @@ public class CommentLike {
@JoinColumn(name = "user_id", nullable = false)
@ManyToOne(fetch = FetchType.LAZY)
private Users users;
}

@Builder
private CommentLike(Comment comment, Users users) {
this.comment = comment;
this.users = users;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.example.betteriter.fo_domain.review.dto.CreateReviewRequestDto;
import com.example.betteriter.fo_domain.review.dto.GetReviewSpecResponseDto;
import com.example.betteriter.fo_domain.review.dto.ReviewDetailResponse;
import com.example.betteriter.fo_domain.review.dto.ReviewResponse;
import com.example.betteriter.fo_domain.review.exception.ReviewHandler;
import com.example.betteriter.fo_domain.review.service.ReviewService;
Expand Down Expand Up @@ -47,17 +48,28 @@ public ResponseDto<GetReviewSpecResponseDto> getReviewSpecDataResponse(
/* 카테고리 별 리뷰 조회 */
@GetMapping("/category")
public ResponseDto<ReviewResponse> getReviewsByCategory(
@RequestParam String category
@RequestParam String category,
@RequestParam int page
) {
return ResponseDto.onSuccess(this.reviewService.getReviewByCategory(Category.from(category)));
return ResponseDto.onSuccess(this.reviewService.getReviewByCategory(Category.from(category), page));
}

/* 이름으로 리뷰 조회 */
/* 상품 명 + 필터링 리뷰 조회 */
@GetMapping("/search")
public ResponseDto<ReviewResponse> getReviewsBySearch(
@RequestParam String name
@RequestParam String name,
@RequestParam String sort,
@RequestParam int page
) {
return ResponseDto.onSuccess(this.reviewService.getReviewBySearch(name, sort, page));
}

/* 리뷰 상세 조회 */
@GetMapping("/detail/{reviewId}")
public ResponseDto<ReviewDetailResponse> getReviewDetail(
@PathVariable Long reviewId
) {
return ResponseDto.onSuccess(this.reviewService.getReviewBySearch(name));
return ResponseDto.onSuccess(this.reviewService.getReviewDetail(reviewId));
}


Expand All @@ -68,4 +80,4 @@ private void checkRequestValidation(BindingResult bindingResult) {
throw new ReviewHandler(_METHOD_ARGUMENT_ERROR);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.example.betteriter.fo_domain.review.domain;


import com.example.betteriter.bo_domain.menufacturer.domain.Manufacturer;
import com.example.betteriter.fo_domain.comment.domain.Comment;
import com.example.betteriter.fo_domain.review.dto.ReviewResponseDto;
import com.example.betteriter.fo_domain.user.domain.Users;
import com.example.betteriter.global.common.entity.BaseEntity;
import com.example.betteriter.global.constant.Category;
import com.example.betteriter.global.constant.Status;
import lombok.*;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.annotations.Where;
import org.springframework.scheduling.annotation.Scheduled;

import javax.persistence.*;
Expand All @@ -19,14 +20,17 @@
@Slf4j
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@ToString(of = {"id"})
@Where(clause = "status = 'ACTIVE'") // ACTIVE 상태인 REVIEW 만 조회
@Entity(name = "REVIEW")
public class Review extends BaseEntity {
@OneToMany(mappedBy = "review", cascade = CascadeType.ALL, orphanRemoval = true)
private final List<ReviewScrap> reviewScraped = new ArrayList<>();
@OneToMany(mappedBy = "review", cascade = CascadeType.ALL, orphanRemoval = true)
public List<ReviewSpecData> specData = new ArrayList<>();
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Setter
@JoinColumn(name = "writer_id")
@ManyToOne(fetch = FetchType.LAZY)
private Users writer;
Expand All @@ -37,8 +41,8 @@ public class Review extends BaseEntity {
private Category category;
@Column(name = "product_name", nullable = false)
private String productName;
@Column(name = "amount", nullable = false)
private int amount;
@Column(name = "price")
private int price;
@Column(name = "store_name", nullable = false)
private int storeName;
@Column(name = "bought_at", nullable = false)
Expand All @@ -47,63 +51,54 @@ public class Review extends BaseEntity {
private double starPoint;
@Column(name = "short_review", nullable = false)
private String shortReview;

@Column(name = "click_cnt")
private long clickCount; // 클릭 수
@Column(name = "liked_cnt")
private long likedCount; // 좋아요 수
@Column(name = "scraped_cnt")
private long scrapedCount; // 스크랩 수


@Lob // 최대 500 자
@Column(name = "good_point", nullable = false)
private String goodPoint;
@Lob // 최대 500 자
@Column(name = "bad_point", nullable = false)
private String badPoint;


@Column(name = "status", nullable = false)
@Enumerated(EnumType.STRING)
private Status status; // ACTIVE, DELETED


// --------------- Review 관련 엔티티 ---------------- //
@Setter
@OneToMany(mappedBy = "review", cascade = CascadeType.ALL, orphanRemoval = true)
private List<ReviewImage> reviewImages = new ArrayList<>();
@OneToMany(mappedBy = "review", cascade = CascadeType.ALL, orphanRemoval = true)
private List<ReviewScrap> reviewScraped = new ArrayList<>();
@Setter
@OneToMany(mappedBy = "review", cascade = CascadeType.ALL, orphanRemoval = true)
private List<ReviewLike> reviewLiked = new ArrayList<>();
@Setter
@OneToMany(mappedBy = "review", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Comment> reviewComment = new ArrayList<>();

@Builder
private Review(Long id, Users writer, Manufacturer manufacturer, Category category,
String productName, int amount, int storeName, LocalDate boughtAt,
double starPoint, String shortReview, String goodPoint,
String badPoint, long clickCount, List<ReviewImage> reviewImages,
List<ReviewScrap> reviewScraped, List<ReviewLike> reviewLiked, long likedCount, long scrapedCount
String productName, int storeName, LocalDate boughtAt, int price,
double starPoint, String shortReview, String goodPoint, Status status,
String badPoint, long clickCount, long likedCount, long scrapedCount
) {
this.id = id;
this.writer = writer;
this.manufacturer = manufacturer;
this.category = category;
this.productName = productName;
this.amount = amount;
this.storeName = storeName;
this.boughtAt = boughtAt;
this.price = price;
this.starPoint = starPoint;
this.shortReview = shortReview;
this.goodPoint = goodPoint;
this.badPoint = badPoint;
this.reviewImages = reviewImages;
this.reviewScraped = reviewScraped;
this.clickCount = clickCount;
this.reviewLiked = reviewLiked;
this.likedCount = likedCount;
this.scrapedCount = scrapedCount;
this.status = status;
}

public ReviewResponseDto of(String firstImageUrl) {
Expand All @@ -115,9 +110,14 @@ public void resetClickCounts() {
this.clickCount = 0L;
}


public void setReviewImage(ReviewImage reviewImage) {
this.reviewImages.add(reviewImage);
}

// 매주 월요일 자정 실행
@Scheduled(cron = "0 0 0 ? * MON")
public void resetClickCountsScheduler() {
this.resetClickCounts();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public class ReviewImage {
private int orderNum;

@Builder
private ReviewImage(Review review, String imgUrl, int orderNum) {
private ReviewImage(Long id, Review review, String imgUrl, int orderNum) {
this.id = id;
this.review = review;
this.imgUrl = imgUrl;
this.orderNum = orderNum;
Expand All @@ -42,4 +43,4 @@ public static ReviewImage createReviewImage(Review review, String imgUrl, int or
.orderNum(orderNum)
.build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class CreateReviewRequestDto {
private String manufacturer; // 제조사 이름

@NotNull(message = "가격은 필수 입력 값입니다.")
private int amount; // 가격
private int price; // 가격

@NotNull(message = "구매처 정보는 필수 입력 값입니다.")
private int storeName; // 구매처
Expand All @@ -52,14 +52,14 @@ public class CreateReviewRequestDto {

@Builder
private CreateReviewRequestDto(Category category, String productName, LocalDate boughtAt,
String manufacturerName, int amount, int storeName, String shortReview,
String manufacturer, int price, int storeName, String shortReview,
int starPoint, String goodPoint, String badPoint, List<Long> specData,
List<CreateReviewImageRequestDto> images) {
this.category = category;
this.productName = productName;
this.boughtAt = boughtAt;
this.manufacturer = manufacturerName;
this.amount = amount;
this.manufacturer = manufacturer;
this.price = price;
this.storeName = storeName;
this.shortReview = shortReview;
this.starPoint = starPoint;
Expand All @@ -76,7 +76,7 @@ public Review toEntity(Users users, Manufacturer manufacturer) {
.productName(productName)
.boughtAt(boughtAt)
.manufacturer(manufacturer)
.amount(amount)
.price(price)
.storeName(storeName)
.shortReview(shortReview)
.starPoint(starPoint)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.example.betteriter.fo_domain.review.dto;

import com.example.betteriter.fo_domain.review.domain.Review;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDate;
import java.util.List;
import java.util.stream.Collectors;

@Getter
@NoArgsConstructor
public class GetReviewDetailResponseDto {
private Long id; // 리뷰 아이디
private String productName; // 리뷰 상품명
private List<String> reviewSpecData; // 리뷰 스펙 데이터
private double starPoint; // 리뷰 별점
private String goodPoint; // 리뷰 좋은점
private String badPoint; // 리뷰 안좋은점
private String shortReview; // 리뷰 한줄평
private String manufacturer; // 제조사 이름
private int storeName; // 구매처
private LocalDate boughtAt; // 구매 일
private LocalDate createdAt; // 작성일
private List<GetReviewImageResponseDto> reviewImages; // 리뷰 이미지
private long scrapedCount; // 리뷰 스크랩 갯수


@Builder
public GetReviewDetailResponseDto(Long id, String productName, List<String> reviewSpecData, double starPoint,
String goodPoint, String badPoint, String shortReview, String manufacturer,
int storeName, LocalDate boughtAt, LocalDate createdAt, List<GetReviewImageResponseDto> reviewImages, long scrapedCount
) {
this.id = id;
this.productName = productName;
this.reviewSpecData = reviewSpecData;
this.starPoint = starPoint;
this.goodPoint = goodPoint;
this.badPoint = badPoint;
this.shortReview = shortReview;
this.manufacturer = manufacturer;
this.storeName = storeName;
this.boughtAt = boughtAt;
this.createdAt = createdAt;
this.reviewImages = reviewImages;
this.scrapedCount = scrapedCount;
}

public static GetReviewDetailResponseDto from(Review review) {
return GetReviewDetailResponseDto.builder()
.id(review.getId())
.productName(review.getProductName())
.reviewSpecData(getReviewSpecDataToStr(review))
.starPoint(review.getStarPoint())
.goodPoint(review.getGoodPoint())
.badPoint(review.getBadPoint())
.shortReview(review.getShortReview())
.manufacturer(review.getManufacturer().getCoName())
.storeName(review.getStoreName())
.boughtAt(review.getBoughtAt())
.createdAt(review.getCreatedAt() == null ? null : review.getCreatedAt().toLocalDate())
.reviewImages(GetReviewImageResponseDto.of(review.getReviewImages()))
.scrapedCount(review.getScrapedCount())
.build();
}

private static List<String> getReviewSpecDataToStr(Review review) {
return review.getSpecData().stream()
.map(reviewSpecData -> reviewSpecData.getSpecData().getData())
.collect(Collectors.toList());
}
}
Loading

0 comments on commit 795648b

Please sign in to comment.