Skip to content

Commit

Permalink
Merge pull request #86 from YAPP-Github/feature/review
Browse files Browse the repository at this point in the history
이미지 등록 버그 수정 및 좋아요 싫어요 구현 완료
  • Loading branch information
devk0ng authored Oct 10, 2023
2 parents f03b547 + c534d55 commit 65a4467
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 95 deletions.
80 changes: 0 additions & 80 deletions src/main/java/com/pyonsnalcolor/config/SecurityConfig.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,22 @@ public ResponseEntity<EventProductResponseDto> getEventProduct(
ProductResponseDto result = memberService.updateProductIfFavorite(product, ProductType.EVENT, memberId);
return new ResponseEntity(result, HttpStatus.OK);
}

@Operation(summary = "event 상품 리뷰 좋아요", description = "id에 해당하는 event 상품의 리뷰 좋아요 카운트 증가.")
@PutMapping("/products/event-products/{productId}/reviews/{reviewId}/like")
public ResponseEntity<Void> likeReview(@PathVariable("productId") String productId,
@PathVariable("reviewId") String reviewId) throws Throwable {
eventProductService.likeReview(productId, reviewId);

return ResponseEntity.ok().build();
}

@Operation(summary = "event 상품 리뷰 싫어요", description = "id에 해당하는 event 상품의 리뷰 싫어요 카운트 증가.")
@PutMapping("/products/event-products/{productId}/reviews/{reviewId}/hate")
public ResponseEntity<Void> hateReview(@PathVariable("productId") String productId,
@PathVariable("reviewId") String reviewId) throws Throwable {
eventProductService.hateReview(productId, reviewId);

return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.*;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -66,4 +68,22 @@ public ResponseEntity<PbProductResponseDto> getPbProduct(
ProductResponseDto result = memberService.updateProductIfFavorite(product, ProductType.PB, memberId);
return new ResponseEntity(result, HttpStatus.OK);
}
}

@Operation(summary = "PB 상품 리뷰 좋아요", description = "id에 해당하는 PB 상품의 리뷰 좋아요 카운트 증가.")
@PutMapping("/products/pb-products/{productId}/reviews/{reviewId}/like")
public ResponseEntity<Void> likeReview(@PathVariable("productId") String productId,
@PathVariable("reviewId") String reviewId) throws Throwable {
pbProductService.likeReview(productId, reviewId);

return ResponseEntity.ok().build();
}

@Operation(summary = "PB 상품 리뷰 싫어요", description = "id에 해당하는 PB 상품의 리뷰 싫어요 카운트 증가.")
@PutMapping("/products/pb-products/{productId}/reviews/{reviewId}/hate")
public ResponseEntity<Void> hateReview(@PathVariable("productId") String productId,
@PathVariable("reviewId") String reviewId) throws Throwable {
pbProductService.hateReview(productId, reviewId);

return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
import org.springframework.data.domain.Page;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -51,4 +49,4 @@ public ResponseEntity<CurationProductsResponseDto> getCurationProducts() {
CurationProductsResponseDto result = searchProductService.getCurationProducts();
return new ResponseEntity(result, HttpStatus.OK);
}
}
}
2 changes: 2 additions & 0 deletions src/main/java/com/pyonsnalcolor/product/dto/ReviewDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ public class ReviewDto {
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
private LocalDateTime updatedTime;
private Long likeCount;
private Long hateCount;
}
31 changes: 25 additions & 6 deletions src/main/java/com/pyonsnalcolor/product/entity/Review.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

import com.pyonsnalcolor.product.dto.ReviewDto;
import com.pyonsnalcolor.product.enumtype.Like;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;

import java.time.LocalDateTime;

@Getter
@Builder
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class Review extends BaseTimeEntity {
public class Review {
private String reviewId;
private Like taste; //맛
private Like quality; //퀄리티
private Like valueForMoney; //가성비
Expand All @@ -20,9 +21,27 @@ public class Review extends BaseTimeEntity {
private String image; //이미지
private Long writerId; // 작성자 id <- 이후 기능 추가 고려
private String writerName;
private LocalDateTime createdTime;
private LocalDateTime updatedTime;
private Long likeCount;
private Long hateCount;

public ReviewDto convertToDto() {
return new ReviewDto(taste, quality, valueForMoney, score, contents, image, writerId, writerName,
getCreatedDate(), getModifiedDate());
createdTime, updatedTime, likeCount, hateCount);
}

public void likeReview() {
if(this.likeCount == null) {
this.likeCount = 0L;
}
this.likeCount += 1;
}

public void hateReview() {
if(this.hateCount == null) {
this.hateCount = 0L;
}
this.hateCount += 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import com.pyonsnalcolor.product.dto.ReviewDto;
import com.pyonsnalcolor.product.entity.BaseProduct;
import com.pyonsnalcolor.product.entity.Review;
import com.pyonsnalcolor.product.entity.UUIDGenerator;
import com.pyonsnalcolor.product.enumtype.*;
import com.pyonsnalcolor.product.repository.BasicProductRepository;
import com.pyonsnalcolor.product.repository.ImageRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
Expand All @@ -22,6 +22,7 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDateTime;
import java.util.List;
import java.util.NoSuchElementException;

Expand Down Expand Up @@ -83,15 +84,52 @@ private Criteria createFilterCriteria(List<Recommend> recommends, List<Category>
return criteria;
}

//리뷰 좋아요
public void likeReview(String productId, String reviewId) throws Throwable {
BaseProduct baseProduct = (BaseProduct) basicProductRepository
.findById(productId)
.orElseThrow(NoSuchElementException::new);

Review review = baseProduct.getReviews().stream().filter(
r -> r.getReviewId().equals(reviewId)
).findFirst()
.orElseThrow(NoSuchElementException::new);

review.likeReview();

basicProductRepository.save(baseProduct);
}

//리뷰 싫어요
public void hateReview(String productId, String reviewId) throws Throwable {
BaseProduct baseProduct = (BaseProduct) basicProductRepository
.findById(productId)
.orElseThrow(NoSuchElementException::new);

Review review = baseProduct.getReviews().stream().filter(
r -> r.getReviewId().equals(reviewId)
).findFirst()
.orElseThrow(NoSuchElementException::new);

review.hateReview();

basicProductRepository.save(baseProduct);
}

//리뷰 등록
public void registerReview(MultipartFile image, ReviewDto reviewDto, String productId) throws Throwable {
BaseProduct baseProduct = (BaseProduct) basicProductRepository
.findById(productId)
.orElseThrow(NoSuchElementException::new);

String filePath = imageRepository.uploadImage(image);
String filePath = "None";

if (image != null) {
filePath = imageRepository.uploadImage(image);
}

Review review = new Review().builder()
.reviewId(UUIDGenerator.generateId())
.contents(reviewDto.getContents())
.image(filePath)
.quality(reviewDto.getQuality())
Expand All @@ -100,6 +138,10 @@ public void registerReview(MultipartFile image, ReviewDto reviewDto, String prod
.valueForMoney(reviewDto.getValueForMoney())
.writerId(reviewDto.getWriterId())
.writerName(reviewDto.getWriterName())
.updatedTime(LocalDateTime.now())
.createdTime(LocalDateTime.now())
.hateCount(0L)
.likeCount(0L)
.build();

baseProduct.addReview(review);
Expand All @@ -122,4 +164,4 @@ public void validateProductTypeOfProduct(String id) {
throw new PyonsnalcolorProductException(INVALID_PRODUCT_TYPE);
}
}
}
}

0 comments on commit 65a4467

Please sign in to comment.