Skip to content

Commit

Permalink
Merge pull request #165 from BETTER-iTER/feature/130
Browse files Browse the repository at this point in the history
[Feature/130] 리뷰 수정 API 구현
  • Loading branch information
luke0408 authored Feb 13, 2024
2 parents 3d470e1 + 7306355 commit e1ce348
Show file tree
Hide file tree
Showing 14 changed files with 435 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ public interface SpecConnector {
List<SpecData> findAllSpecDataByIds(List<Long> id);

List<Spec> findAllSpecDataByCategory(Category category);

List<Spec> saveAllSpec(List<Spec> specs);

List<SpecData> saveAllData(List<SpecData> specData);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,16 @@ public List<SpecData> findAllSpecDataByIds(List<Long> id) {
public List<Spec> findAllSpecDataByCategory(Category category) {
return this.specRepository.findAllByCategory(category);
}

@Override
public List<Spec> saveAllSpec(List<Spec> specs) {
this.specRepository.saveAll(specs);
return specs;
}

@Override
public List<SpecData> saveAllData(List<SpecData> specData) {
this.specDataRepository.saveAll(specData);
return specData;
}
}
Original file line number Diff line number Diff line change
@@ -1,34 +1,23 @@
package com.example.betteriter.fo_domain.review.controller;

import static com.example.betteriter.global.common.code.status.ErrorStatus._METHOD_ARGUMENT_ERROR;

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.ReviewCommentResponse;
import com.example.betteriter.fo_domain.review.dto.ReviewDetailResponse;
import com.example.betteriter.fo_domain.review.dto.ReviewLikeResponse;
import com.example.betteriter.fo_domain.review.dto.ReviewResponse;
import com.example.betteriter.fo_domain.review.dto.*;
import com.example.betteriter.fo_domain.review.exception.ReviewHandler;
import com.example.betteriter.fo_domain.review.service.ReviewService;
import com.example.betteriter.global.common.response.ResponseDto;
import com.example.betteriter.global.constant.Category;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.util.List;
import javax.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.List;

import static com.example.betteriter.global.common.code.status.ErrorStatus._METHOD_ARGUMENT_ERROR;

@Slf4j
@RestController
@RequestMapping("/review")
Expand Down Expand Up @@ -148,6 +137,20 @@ public ResponseDto<Void> deleteReview(
return ResponseDto.onSuccess(null);
}

/* 리뷰 수정 */
@PutMapping("/{reviewId}")
public ResponseDto<Void> updateReview(
@PathVariable Long reviewId,
@RequestPart(value = "files") List<MultipartFile> images,
@Valid @RequestPart(value = "key") UpdateReviewRequestDto request,
BindingResult bindingResult
) {
log.info("updateReview : {}", request);
this.checkRequestValidation(bindingResult);
this.reviewService.checkReviewOwner(reviewId);
this.reviewService.updateReview(reviewId, request, images);
return ResponseDto.onSuccess(null);
}

private void checkRequestValidation(BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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.review.dto.UpdateReviewRequestDto;
import com.example.betteriter.fo_domain.user.domain.Users;
import com.example.betteriter.global.common.entity.BaseEntity;
import com.example.betteriter.global.constant.Category;
Expand Down Expand Up @@ -163,9 +164,26 @@ public void setReviewsComment(List<Comment> comments) {
this.reviewComment = comments;
}

public void setReviewSpecData(List<ReviewSpecData> reviewSpecData) {
this.specData = reviewSpecData;
}

// 매주 월요일 자정 실행
@Scheduled(cron = "0 0 0 ? * MON")
public void resetClickCountsScheduler() {
this.resetClickCounts();
}

public void updateReview(UpdateReviewRequestDto request, Manufacturer manufacturer) {
this.category = request.getCategory() == null ? this.category : request.getCategory();
this.productName = request.getProductName() == null ? this.productName : request.getProductName();
this.boughtAt = request.getBoughtAt() == null ? this.boughtAt : request.getBoughtAt();
this.manufacturer = manufacturer == null ? this.manufacturer : manufacturer;
this.price = request.getPrice() == null ? this.price : request.getPrice();
this.storeName = request.getStoreName() == null ? this.storeName : request.getStoreName();
this.shortReview = request.getShortReview() == null ? this.shortReview : request.getShortReview();
this.starPoint = request.getStarPoint() == null ? this.starPoint : request.getStarPoint();
this.goodPoint = request.getGoodPoint() == null ? this.goodPoint : request.getGoodPoint();
this.badPoint = request.getBadPoint() == null ? this.badPoint : request.getBadPoint();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ public static ReviewImage createReviewImage(Review review, String imgUrl, int or
.orderNum(orderNum)
.build();
}
}

public void updateImgUrl(String imageUrl) {
this.imgUrl = imageUrl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ public static ReviewSpecData createReviewSpecData(Review review, SpecData specDa
.specData(specData)
.build();
}

public void updateSpecData(SpecData specData) {
this.specData = specData;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.example.betteriter.fo_domain.review.dto;

import com.example.betteriter.global.constant.Category;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.validation.constraints.Max;
import java.time.LocalDate;
import java.util.List;

@Getter
@NoArgsConstructor
public class UpdateReviewRequestDto {

private Category category; // 카테고리

private String productName; // 상품명

private LocalDate boughtAt; // 구매 일자

private String manufacturer; // 제조사 이름

private Integer price; // 가격

private Integer storeName; // 구매처

private String shortReview; // 한줄평

@Max(5)
private Double starPoint; // 별점

private String goodPoint; // 좋은 점

private String badPoint; // 나쁜 점

private List<Long> specData; // specData id 리스트

private List<Integer> imageIndex; // 바꾸고자 하는 이미지의 인덱스

@Builder
public UpdateReviewRequestDto(
Category category,
String productName,
LocalDate boughtAt,
String manufacturer,
Integer price,
Integer storeName,
String shortReview,
Double starPoint,
String goodPoint,
String badPoint,
List<Long> specData,
List<Integer> imageIndex
) {
this.category = category;
this.productName = productName;
this.boughtAt = boughtAt;
this.manufacturer = manufacturer;
this.price = price;
this.storeName = storeName;
this.shortReview = shortReview;
this.starPoint = starPoint;
this.goodPoint = goodPoint;
this.badPoint = badPoint;
this.specData = specData;
this.imageIndex = imageIndex;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Optional;

public interface ReviewImageRepository extends JpaRepository<ReviewImage, Long> {

@Query("select ri.imgUrl from REVIEW_IMAGE ri where ri.review = :review and ri.orderNum = 0")
String findFirstImageWithReview(@Param("review") Review review);

ReviewImage findByReviewAndOrderNum(Review review, Integer integer);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.example.betteriter.fo_domain.review.repository;

import com.example.betteriter.fo_domain.review.domain.Review;
import com.example.betteriter.fo_domain.review.domain.ReviewSpecData;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface ReviewSpecDataRepository extends JpaRepository<ReviewSpecData, Long> {
List<ReviewSpecData> findAllByReview(Review review);

}
Loading

0 comments on commit e1ce348

Please sign in to comment.