Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies {
testImplementation 'com.h2database:h2'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.mariadb.jdbc:mariadb-java-client'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.mysql:mysql-connector-j'
annotationProcessor 'org.projectlombok:lombok'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.example.umc_9th.domain.review.controller;

import com.example.umc_9th.domain.review.dto.res.ReviewResponseDTO;
import com.example.umc_9th.domain.review.entity.Review;
import com.example.umc_9th.domain.review.service.ReviewQueryService;
import com.example.umc_9th.grobal.apiPayload.ApiResponse;
import com.example.umc_9th.grobal.apiPayload.code.GeneralSuccessCode;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -17,15 +20,16 @@ public class ReviewController {
private final ReviewQueryService reviewQueryService;

@GetMapping("/members/{memberId}/reviews/search")
public List<Review> searchMyReview(
// 경로에서 memberId를 받음
public ApiResponse<List<ReviewResponseDTO>> searchMyReview(
@PathVariable Long memberId,

@RequestParam(required = false) Long storeId,
@RequestParam(required = false) Integer rating
) {
// 서비스로 memberId를 포함하여 전달
return reviewQueryService.searchMyReviews(memberId, storeId, rating);


List<ReviewResponseDTO> reviewList = reviewQueryService.searchMyReviews(memberId, storeId, rating);

return ApiResponse.success(GeneralSuccessCode.REVIEWS_FOUND, reviewList);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.example.umc_9th.domain.review.converter;

import com.example.umc_9th.domain.review.dto.res.ReviewResponseDTO;
import com.example.umc_9th.domain.review.entity.Review;

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

public class ReviewConverter {

public static ReviewResponseDTO toReviewDTO(Review review) {


return ReviewResponseDTO.builder()
.reviewId(review.getId())
.memberName(review.getMember().getName())
.storeName(review.getStore().getName())
.rating(review.getRating())
.content(review.getContent())
.build();
}

// Review 엔티티 리스트르르 DTO리스트로 변환
public static List<ReviewResponseDTO> toReviewDTOList(List<Review> reviewList) {
return reviewList.stream()
.map(ReviewConverter::toReviewDTO)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.example.umc_9th.domain.review.dto.res;

import com.example.umc_9th.grobal.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;



@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ReviewResponseDTO extends BaseEntity {

private Long reviewId;

private String memberName;

private String storeName;

private Integer rating;


private String content;



}
11 changes: 0 additions & 11 deletions src/main/java/com/example/umc_9th/domain/review/entity/Review.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,4 @@ public class Review extends BaseEntity {
@JoinColumn(name = "shop_id")
private Store store;


//양방향 고려
// @OneToMany(fetch = FetchType.LAZY)//미션 테이블과1 :N관계매핑
// @JoinColumn(name="mission_id")
// private List<Mission> missions;
//
// @OneToMany(fetch = FetchType.LAZY)//리뷰 이미지와 1:N관계매핑
// @JoinColumn(name="reviewImage_id")
// private List<ReviewImage> reviewImages;


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.umc_9th.domain.review.exception;

import com.example.umc_9th.grobal.apiPayload.code.BaseErrorCode;
import com.example.umc_9th.grobal.apiPayload.exception.GeneralException;

public class ReviewException extends GeneralException {
public ReviewException(BaseErrorCode code) {
super(code);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.example.umc_9th.domain.review.exception.code;

import com.example.umc_9th.grobal.apiPayload.code.BaseErrorCode;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.http.HttpStatus;

@Getter
@AllArgsConstructor
public enum ReviewErrorCode implements BaseErrorCode {

// 리뷰 검색 관련 에러
// 회원 에러
MEMBER_NOT_FOUND(HttpStatus.NOT_FOUND, "REVIEW404_1", "해당 ID의 회원을 찾을 수 없습니다."),
// 평점 유효성
INVALID_RATING_VALUE(HttpStatus.BAD_REQUEST, "REVIEW400_1", "평점 값은 1에서 5 사이여야 합니다.");

private final HttpStatus status;
private final String code;
private final String message;


@Override
public HttpStatus getStatus() {
return this.status;
}

@Override
public String getCode() {
return this.code;
}

@Override
public String getMessage() {
return this.message;
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package com.example.umc_9th.domain.review.service;

import com.example.umc_9th.domain.member.repository.MemberRepository;
import com.example.umc_9th.domain.review.converter.ReviewConverter;
import com.example.umc_9th.domain.review.dto.res.ReviewResponseDTO;
import com.example.umc_9th.domain.review.entity.Review;
import com.example.umc_9th.domain.review.exception.ReviewException;
import com.example.umc_9th.domain.review.exception.code.ReviewErrorCode;
import com.example.umc_9th.domain.review.repository.ReviewRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -14,9 +19,23 @@
public class ReviewQueryService {

private final ReviewRepository reviewRepository;
private final MemberRepository memberRepository;

public List<Review> searchMyReviews(Long memberId, Long storeId, Integer rating) {
return reviewRepository.findMyReviews(memberId, storeId, rating);
}
public List<ReviewResponseDTO> searchMyReviews(Long memberId, Long storeId, Integer rating) {


// 회원 유효성 검사
memberRepository.findById(memberId)
.orElseThrow(() -> new ReviewException(ReviewErrorCode.MEMBER_NOT_FOUND));

// 평점값 유효성 검사
if (rating != null && (rating < 1 || rating > 5)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null인 것과 페이지 유효성 검사는 나누는게 좋을듯 합니다.
이렇게 두면 null이어서 안되는건지, 값이 잘못된건지 구분하기 힘들어요

throw new ReviewException(ReviewErrorCode.INVALID_RATING_VALUE);
}

List<Review> reviewList = reviewRepository.findMyReviews(memberId, storeId, rating);

return ReviewConverter.toReviewDTOList(reviewList);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.example.umc_9th.domain.test.controller;


import com.example.umc_9th.domain.test.converter.TestConverter;
import com.example.umc_9th.domain.test.dto.res.TestResDTO;
import com.example.umc_9th.domain.test.exception.TestException;
import com.example.umc_9th.domain.test.service.query.TestQueryService;
import com.example.umc_9th.grobal.apiPayload.ApiResponse;
import com.example.umc_9th.grobal.apiPayload.code.GeneralErrorCode;
import com.example.umc_9th.grobal.apiPayload.code.GeneralSuccessCode;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/temp")
public class TestController {


private final TestQueryService testQueryService;


@GetMapping("/test")
public ApiResponse<TestResDTO.Testing> test() throws Exception {
// 응답 코드 정의
GeneralSuccessCode code = GeneralSuccessCode.OK;

throw new TestException(GeneralErrorCode.BAD_REQUEST);

// return ApiResponse.success(
// code,
// TestConverter.toTestingDTO("This is Test!"));
//
}

// 예외 상황
@GetMapping("/exception")
public ApiResponse<TestResDTO.Exception> exception(
@RequestParam Long flag
) {
testQueryService.checkFlag(flag);

// 응답 코드 정의
GeneralSuccessCode code = GeneralSuccessCode.OK;
return ApiResponse.success(code, TestConverter.toExceptionDTO("This is Test!"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.example.umc_9th.domain.test.converter;

import com.example.umc_9th.domain.test.dto.res.TestResDTO;

public class TestConverter {

// 객체 -> DTO
public static TestResDTO.Testing toTestingDTO(
String testing
) {
return TestResDTO.Testing.builder()
.testing(testing)
.build();
}


// 예외객체 -> DTO
public static TestResDTO.Exception toExceptionDTO(
String testing
){
return TestResDTO.Exception.builder()
.testString(testing)
.build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.example.umc_9th.domain.test.dto.req;

public class TestReqDTO {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.umc_9th.domain.test.dto.res;


import lombok.Builder;
import lombok.Getter;

//DTO 하나만 만드록 안에다 스태틱으로 여러개
//RequestDTO는 보통 프론트 그대로 받기 떄문에 빌더 패턴 적용할 필요 없음
public class TestResDTO {
//DTO 자체는 수많은 곳에서 사용이 될 수 있기에 static class로 만들면 매번 class 파일을 만들 필요 없음
@Builder
@Getter
public static class Testing {
private String testing;
}

@Builder
@Getter
public static class Exception {
private String testString;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.umc_9th.domain.test.exception;

import com.example.umc_9th.grobal.apiPayload.code.BaseErrorCode;
import com.example.umc_9th.grobal.apiPayload.exception.GeneralException;

public class TestException extends GeneralException {
public TestException(BaseErrorCode code) {
super(code);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.umc_9th.domain.test.exception.code;

import com.example.umc_9th.grobal.apiPayload.code.BaseErrorCode;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.http.HttpStatus;

@Getter
@AllArgsConstructor
public enum TestErrorCode implements BaseErrorCode {

// For test
TEST_EXCEPTION(HttpStatus.BAD_REQUEST, "TEST400_1", "이거는 테스트"),
;

private final HttpStatus status;
private final String code;
private final String message;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example.umc_9th.domain.test.service.query;

public interface TestQueryService {
void checkFlag(Long flag);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.umc_9th.domain.test.service.query;

import com.example.umc_9th.domain.test.exception.TestException;
import com.example.umc_9th.domain.test.exception.code.TestErrorCode;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class TestQueryServiceImpl implements TestQueryService {


@Override
public void checkFlag(Long flag){
if (flag == 1){
throw new TestException(TestErrorCode.TEST_EXCEPTION);
}
}

}
Loading