Skip to content

Commit

Permalink
Merge pull request #283 from linglong67/feature/review-file-upload
Browse files Browse the repository at this point in the history
[feat] 리뷰 + 파일 기능 추가 및 리팩토링
  • Loading branch information
gunsight1 authored Mar 8, 2024
2 parents ab06bda + 8a1d437 commit 1b9f2a6
Show file tree
Hide file tree
Showing 30 changed files with 641 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,4 @@ public static ProductDto from(Product entity) {
entity.getModifiedBy()
);
}

public Product toEntity() {
return Product.of(
productNo,
productName
);
}
}
2 changes: 2 additions & 0 deletions module-admin/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ spring:
server:
port: 8082

module:
name: admin
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.kernel360.file.repository;

public interface FileRepository extends FileRepositoryJpa {
}
22 changes: 22 additions & 0 deletions module-api/src/main/java/com/kernel360/member/dto/MemberDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,26 @@ public static MemberDto of(
null
);
}

/** find review **/
public static MemberDto of(
Long memberNo,
String id,
int age,
int gender
){
return new MemberDto(
memberNo,
id,
null,
null,
Gender.ordinalToName(gender),
Age.ordinalToValue(age),
null,
null,
null,
null,
null
);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package com.kernel360.product.dto;

import com.kernel360.product.entity.Product;
import jakarta.persistence.Column;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;

import java.time.LocalDate;

Expand Down Expand Up @@ -117,6 +113,51 @@ public static ProductDetailDto of(
);
}

/** find review **/
public static ProductDetailDto of(
Long productNo,
String productName,
String imageSource,
String companyName,
String upperItem,
String item
) {
return new ProductDetailDto(
productNo,
productName,
null,
imageSource,
null,
null,
null,
companyName,
null,
null,
null,
upperItem,
item,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null
);
}

public static ProductDetailDto from(Product entity) {
return ProductDetailDto.of(
entity.getProductNo(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,4 @@ public static ProductDto from(Product entity) {
entity.getModifiedBy()
);
}

public Product toEntity() {
return Product.of(
productNo,
productName
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
@RequiredArgsConstructor
public enum ReviewErrorCode implements ErrorCode {
INVALID_STAR_RATING_VALUE(HttpStatus.BAD_REQUEST.value(), "ERV001", "유효하지 않은 별점입니다."),
INVALID_REVIEW_WRITE_REQUEST(HttpStatus.BAD_REQUEST.value(), "ERV002", "리뷰가 중복되거나 유효하지 않습니다.");
INVALID_REVIEW_WRITE_REQUEST(HttpStatus.BAD_REQUEST.value(), "ERV002", "리뷰가 중복되거나 유효하지 않습니다."),
NOT_FOUND_REVIEW(HttpStatus.BAD_REQUEST.value(), "ERV003", "리뷰가 존재하지 않습니다.");

private final int status;
private final String code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import com.kernel360.response.ApiResponse;
import com.kernel360.review.code.ReviewBusinessCode;
import com.kernel360.review.dto.ReviewDto;
import com.kernel360.review.dto.ReviewResponseDto;
import com.kernel360.review.dto.ReviewRequestDto;
import com.kernel360.review.service.ReviewService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequiredArgsConstructor
Expand All @@ -17,31 +21,44 @@ public class ReviewController {

private final ReviewService reviewService;

@GetMapping("")
public ResponseEntity<ApiResponse<Page<ReviewDto>>> getReviewsByProduct(
@RequestParam(name = "productNo") Long productNo,
@GetMapping("/product/{productNo}")
public ResponseEntity<ApiResponse<Page<ReviewResponseDto>>> getReviewsByProduct(
@PathVariable Long productNo,
@RequestParam(name = "sortBy", defaultValue = "reviewNo", required = false) String sortBy,
Pageable pageable) {

return ApiResponse.toResponseEntity(ReviewBusinessCode.SUCCESS_GET_REVIEWS, reviewService.getReviewsByProduct(productNo, sortBy, pageable));
}

@GetMapping("/member/{memberNo}")
public ResponseEntity<ApiResponse<Page<ReviewResponseDto>>> getReviewsByMember(
@PathVariable Long memberNo,
@RequestParam(name = "sortBy", defaultValue = "reviewNo", required = false) String sortBy,
Pageable pageable) {

return ApiResponse.toResponseEntity(ReviewBusinessCode.SUCCESS_GET_REVIEWS, reviewService.getReviewsByMember(memberNo, sortBy, pageable));
}

@GetMapping("/{reviewNo}")
public ResponseEntity<ApiResponse<ReviewDto>> getReview(@PathVariable Long reviewNo) {
public ResponseEntity<ApiResponse<ReviewResponseDto>> getReview(@PathVariable Long reviewNo) {

return ApiResponse.toResponseEntity(ReviewBusinessCode.SUCCESS_GET_REVIEW, reviewService.getReview(reviewNo));
}

@PostMapping("")
public <T> ResponseEntity<ApiResponse<T>> createReview(@RequestBody ReviewDto reviewDto) {
reviewService.createReview(reviewDto);
public <T> ResponseEntity<ApiResponse<T>> createReview(
@RequestPart ReviewRequestDto review,
@RequestPart(required = false) List<MultipartFile> files) {
reviewService.createReview(review, files);

return ApiResponse.toResponseEntity(ReviewBusinessCode.SUCCESS_CREATE_REVIEW);
}

@PatchMapping("")
public <T> ResponseEntity<ApiResponse<T>> updateReview(@RequestBody ReviewDto reviewDto) {
reviewService.updateReview(reviewDto);
public <T> ResponseEntity<ApiResponse<T>> updateReview(
@RequestPart ReviewRequestDto review,
@RequestPart(required = false) List<MultipartFile> files) {
reviewService.updateReview(review, files);

return ApiResponse.toResponseEntity(ReviewBusinessCode.SUCCESS_UPDATE_REVIEW);
}
Expand Down
75 changes: 0 additions & 75 deletions module-api/src/main/java/com/kernel360/review/dto/ReviewDto.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.kernel360.review.dto;

import com.kernel360.member.entity.Member;
import com.kernel360.product.entity.Product;
import com.kernel360.review.entity.Review;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;

/**
* DTO for {@link ReviewRequestDto}
*/
public record ReviewRequestDto(Long reviewNo,
Long productNo,
Long memberNo,
BigDecimal starRating,
String title,
String contents,
LocalDate createdAt,
String createdBy,
LocalDate modifiedAt,
String modifiedBy,
List<String> files) {

public static ReviewRequestDto of(
Long reviewNo,
Long productNo,
Long memberNo,
BigDecimal starRating,
String title,
String contents,
LocalDate createdAt,
String createdBy,
LocalDate modifiedAt,
String modifiedBy,
List<String> files
) {
return new ReviewRequestDto(
reviewNo,
productNo,
memberNo,
starRating,
title,
contents,
createdAt,
createdBy,
modifiedAt,
modifiedBy,
files
);
}

public Review toEntity() {
return Review.of(
reviewNo,
Product.of(productNo),
Member.of(memberNo),
starRating,
title,
contents,
true
);
}

public Review toEntityForUpdate() {
return Review.of(
reviewNo,
starRating,
title,
contents,
true
);
}
}
Loading

0 comments on commit 1b9f2a6

Please sign in to comment.