Skip to content

Commit

Permalink
Merge pull request #160 from BETTER-iTER/feauture/159
Browse files Browse the repository at this point in the history
[FEATURE-159]
  • Loading branch information
choidongkuen authored Feb 1, 2024
2 parents 5395c45 + 4c61256 commit 527007a
Show file tree
Hide file tree
Showing 17 changed files with 1,211 additions and 1,043 deletions.
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ dependencies {
// email
implementation 'org.springframework.boot:spring-boot-starter-mail'

// s3
implementation platform("io.awspring.cloud:spring-cloud-aws-dependencies:3.1.0")
implementation "io.awspring.cloud:spring-cloud-aws-starter-s3"


compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,97 +1,112 @@
package com.example.betteriter.fo_domain.review.controller;

import com.example.betteriter.fo_domain.review.dto.*;
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.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.*;

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

import static com.example.betteriter.global.common.code.status.ErrorStatus._METHOD_ARGUMENT_ERROR;
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.multipart.MultipartFile;

@Slf4j
@RestController
@RequestMapping("/review")
@RequiredArgsConstructor
@Tag(name = "ReviewController", description = "Review API")
public class ReviewController {

private final ReviewService reviewService;

/* 리뷰 등록 API */
@PostMapping
public ResponseDto<Long> createReview(
@Valid @RequestBody CreateReviewRequestDto request,
BindingResult bindingResult
@RequestPart(value = "files") List<MultipartFile> images,
@Valid @RequestPart(value = "review") CreateReviewRequestDto request,
BindingResult bindingResult
) {
this.checkRequestValidation(bindingResult);
return ResponseDto.onSuccess(this.reviewService.createReview(request));
return ResponseDto.onSuccess(this.reviewService.createReview(request, images));
}

/* 리뷰 등록시 스펙 데이터 조회 API */
@GetMapping("/spec/data")
public ResponseDto<GetReviewSpecResponseDto> getReviewSpecDataResponse(
@RequestParam String category
@RequestParam String category
) {
return ResponseDto.onSuccess(this.reviewService.getReviewSpecDataResponse(Category.from(category)));
}

/* 카테고리 별 리뷰 조회 */
@GetMapping("/category")
public ResponseDto<ReviewResponse> getReviewsByCategory(
@RequestParam String category,
@RequestParam int page
@RequestParam String category,
@RequestParam int page
) {
return ResponseDto.onSuccess(this.reviewService.getReviewByCategory(Category.from(category), page));
}

/* 상품 명 + 필터링 리뷰 조회 */
@GetMapping("/search")
public ResponseDto<ReviewResponse> getReviewsBySearch(
@RequestParam String name,
@RequestParam String sort,
@RequestParam int page,
@RequestParam(required = false) String category,
@RequestParam(required = false) Boolean expert
@RequestParam String name,
@RequestParam String sort,
@RequestParam int page,
@RequestParam(required = false) String category,
@RequestParam(required = false) Boolean expert
) {
return ResponseDto.onSuccess(this.reviewService.getReviewBySearch(name, sort, page, Category.from(category), expert));
return ResponseDto.onSuccess(
this.reviewService.getReviewBySearch(name, sort, page, Category.from(category), expert));
}

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

/* 리뷰 상세 좋아요 정보 조회 */
@GetMapping("/{reviewId}/detail/likes")
public ResponseDto<List<ReviewLikeResponse>> getReviewDetailLikes(
@PathVariable Long reviewId
@PathVariable Long reviewId
) {
return ResponseDto.onSuccess(this.reviewService.getReviewDetailLikes(reviewId));
}

/* 리뷰 상세 댓글 정보 조회 */
@GetMapping("/{reviewId}/detail/comments")
public ResponseDto<List<ReviewCommentResponse>> getReviewDetailComments(
@PathVariable Long reviewId
@PathVariable Long reviewId
) {
return ResponseDto.onSuccess(this.reviewService.getReviewDetailComments(reviewId));
}

/* 리뷰 좋아요 */
@PostMapping("/{reviewId}/like")
public ResponseDto<Void> reviewLike(
@PathVariable Long reviewId
@PathVariable Long reviewId
) {
this.reviewService.reviewLike(reviewId);
return ResponseDto.onSuccess(null);
Expand All @@ -100,7 +115,7 @@ public ResponseDto<Void> reviewLike(
/* 리뷰 좋아요 취소 */
@DeleteMapping("/{reviewId}/like")
public ResponseDto<Void> deleteReviewLike(
@PathVariable Long reviewId
@PathVariable Long reviewId
) {
this.reviewService.deleteReviewLike(reviewId);
return ResponseDto.onSuccess(null);
Expand All @@ -109,7 +124,7 @@ public ResponseDto<Void> deleteReviewLike(
/* 리뷰 스크랩 */
@PostMapping("{reviewId}/scrap")
public ResponseDto<Void> reviewScrap(
@PathVariable Long reviewId
@PathVariable Long reviewId
) {
this.reviewService.reviewScrap(reviewId);
return ResponseDto.onSuccess(null);
Expand All @@ -118,7 +133,7 @@ public ResponseDto<Void> reviewScrap(
/* 리뷰 스크랩 취소 */
@DeleteMapping("{reviewId}/scrap")
public ResponseDto<Void> deleteReviewScrap(
@PathVariable Long reviewId
@PathVariable Long reviewId
) {
this.reviewService.deleteReviewScrap(reviewId);
return ResponseDto.onSuccess(null);
Expand All @@ -127,7 +142,7 @@ public ResponseDto<Void> deleteReviewScrap(
/* 리뷰 삭제 */
@DeleteMapping("/{reviewId}")
public ResponseDto<Void> deleteReview(
@PathVariable Long reviewId
@PathVariable Long reviewId
) {
this.reviewService.deleteReview(reviewId);
return ResponseDto.onSuccess(null);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package com.example.betteriter.fo_domain.review.dto;

import static com.example.betteriter.global.constant.Status.ACTIVE;

import com.example.betteriter.bo_domain.menufacturer.domain.Manufacturer;
import com.example.betteriter.fo_domain.review.domain.Review;
import com.example.betteriter.fo_domain.user.domain.Users;
import com.example.betteriter.global.constant.Category;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

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

import static com.example.betteriter.global.constant.Status.ACTIVE;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class CreateReviewRequestDto {

@NotNull(message = "카테고리는 필수 입력 값입니다.")
private Category category; // 카테고리

Expand Down Expand Up @@ -53,14 +53,11 @@ public class CreateReviewRequestDto {

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

private List<CreateReviewImageRequestDto> images; // 리뷰 이미지

@Builder
public CreateReviewRequestDto(Category category, String productName, LocalDate boughtAt,
String manufacturer, int price, int storeName,
String comparedProductName, String shortReview, int starPoint, String goodPoint,
String badPoint, List<Long> specData, List<CreateReviewImageRequestDto> images
) {
String manufacturer, int price, int storeName,
String comparedProductName, String shortReview, int starPoint, String goodPoint,
String badPoint, List<Long> specData) {
this.category = category;
this.productName = productName;
this.boughtAt = boughtAt;
Expand All @@ -73,36 +70,23 @@ public CreateReviewRequestDto(Category category, String productName, LocalDate b
this.goodPoint = goodPoint;
this.badPoint = badPoint;
this.specData = specData;
this.images = images;
}

public Review toEntity(Users users, Manufacturer manufacturer) {
return Review.builder()
.writer(users)
.category(category)
.productName(productName)
.boughtAt(boughtAt)
.manufacturer(manufacturer)
.price(price)
.comparedProductName(comparedProductName)
.storeName(storeName)
.shortReview(shortReview)
.starPoint(starPoint)
.goodPoint(goodPoint)
.badPoint(badPoint)
.status(ACTIVE)
.build();
}

@Getter
@NoArgsConstructor
public static class CreateReviewImageRequestDto {
@NotBlank
private String imgUrl;

@Builder
private CreateReviewImageRequestDto(String imgUrl) {
this.imgUrl = imgUrl;
}
.writer(users)
.category(category)
.productName(productName)
.boughtAt(boughtAt)
.manufacturer(manufacturer)
.price(price)
.comparedProductName(comparedProductName)
.storeName(storeName)
.shortReview(shortReview)
.starPoint(starPoint)
.goodPoint(goodPoint)
.badPoint(badPoint)
.status(ACTIVE)
.build();
}
}
Loading

0 comments on commit 527007a

Please sign in to comment.