-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from 28th-meetup/feat/mypage-1112
[feat] 리뷰 관련 api 추가
- Loading branch information
Showing
22 changed files
with
266 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/main/java/com/kusitms/jipbap/food/dto/RegisterCategoryRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/java/com/kusitms/jipbap/order/OrderExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.kusitms.jipbap.order; | ||
|
||
import com.kusitms.jipbap.common.response.CommonResponse; | ||
import com.kusitms.jipbap.common.response.ErrorCode; | ||
import com.kusitms.jipbap.order.exception.OrderNotExistsException; | ||
import com.kusitms.jipbap.store.exception.StoreExistsException; | ||
import com.kusitms.jipbap.store.exception.StoreNotExistsException; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
@Slf4j | ||
@RestControllerAdvice | ||
public class OrderExceptionHandler { | ||
@ExceptionHandler(OrderNotExistsException.class) | ||
@ResponseStatus(HttpStatus.BAD_REQUEST) | ||
public CommonResponse<?> handleOrderNotExistsException(OrderNotExistsException e, HttpServletRequest request) { | ||
log.warn("ORDER-001> 요청 URI: " + request.getRequestURI() + ", 에러 메세지: " + e.getMessage()); | ||
return new CommonResponse<>(ErrorCode.STORE_NOT_FOUND_ERROR); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/kusitms/jipbap/order/ReviewController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.kusitms.jipbap.order; | ||
|
||
import com.kusitms.jipbap.common.response.CommonResponse; | ||
import com.kusitms.jipbap.order.dto.GetRegisteredReviewsResponseDto; | ||
import com.kusitms.jipbap.order.dto.RegisterReviewRequestDto; | ||
import com.kusitms.jipbap.order.dto.ReviewDto; | ||
import com.kusitms.jipbap.security.Auth; | ||
import com.kusitms.jipbap.security.AuthInfo; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequestMapping("/review") | ||
@RequiredArgsConstructor | ||
public class ReviewController { | ||
|
||
private final ReviewService reviewService; | ||
|
||
@Operation(summary = "주문 리뷰 작성") | ||
@PostMapping | ||
public CommonResponse<ReviewDto> registerReview(@Auth AuthInfo authInfo, @RequestBody RegisterReviewRequestDto dto) { | ||
return new CommonResponse<>(reviewService.registerReview(authInfo.getEmail(), dto)); | ||
} | ||
|
||
@Operation(summary = "유저가 작성한 리뷰 모아보기") | ||
@GetMapping | ||
public CommonResponse<GetRegisteredReviewsResponseDto> getUserRegisteredReviews(@Auth AuthInfo authInfo) { | ||
return new CommonResponse<>(reviewService.getUserRegisteredReviews(authInfo.getEmail())); | ||
} | ||
|
||
@Operation(summary = "가게 리뷰 모두보기") | ||
@GetMapping("/{storeId}") | ||
public CommonResponse<GetRegisteredReviewsResponseDto> getStoreRegisteredReviews(@PathVariable Long storeId) { | ||
return new CommonResponse<>(reviewService.getStoreRegisteredReviews(storeId)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.kusitms.jipbap.order; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ReviewRepository extends JpaRepository <Review, Long>, ReviewRepositoryExtension { | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/kusitms/jipbap/order/ReviewRepositoryExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.kusitms.jipbap.order; | ||
|
||
import com.kusitms.jipbap.store.Store; | ||
import com.kusitms.jipbap.user.User; | ||
|
||
import java.util.List; | ||
|
||
public interface ReviewRepositoryExtension { | ||
List<Review> findAllReviewsByUser(User user); | ||
List<Review> findAllReviewsByStore(Store store); | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/kusitms/jipbap/order/ReviewRepositoryExtensionImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.kusitms.jipbap.order; | ||
|
||
import com.kusitms.jipbap.store.Store; | ||
import com.kusitms.jipbap.user.User; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
import static com.kusitms.jipbap.food.QFood.food; | ||
import static com.kusitms.jipbap.order.QOrder.order; | ||
import static com.kusitms.jipbap.order.QReview.review; | ||
|
||
@RequiredArgsConstructor | ||
public class ReviewRepositoryExtensionImpl implements ReviewRepositoryExtension { | ||
|
||
private final JPAQueryFactory queryFactory; | ||
|
||
@Override | ||
public List<Review> findAllReviewsByUser(User user) { | ||
return queryFactory.selectFrom(review) | ||
.join(review.order, order) | ||
.where(order.user.eq(user)) | ||
.fetch(); | ||
} | ||
|
||
@Override | ||
public List<Review> findAllReviewsByStore(Store store) { | ||
return queryFactory.selectFrom(review) | ||
.join(review.order, order) | ||
.join(order.food, food) | ||
.where(food.store.eq(store)) | ||
.fetch(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.kusitms.jipbap.order; | ||
|
||
import com.kusitms.jipbap.order.dto.GetRegisteredReviewsResponseDto; | ||
import com.kusitms.jipbap.order.dto.RegisterReviewRequestDto; | ||
import com.kusitms.jipbap.order.dto.ReviewDto; | ||
import com.kusitms.jipbap.order.exception.OrderNotExistsException; | ||
import com.kusitms.jipbap.store.Store; | ||
import com.kusitms.jipbap.store.StoreRepository; | ||
import com.kusitms.jipbap.store.exception.StoreNotExistsException; | ||
import com.kusitms.jipbap.user.User; | ||
import com.kusitms.jipbap.user.UserRepository; | ||
import com.kusitms.jipbap.user.exception.UserNotFoundException; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class ReviewService { | ||
|
||
private final ReviewRepository reviewRepository; | ||
private final UserRepository userRepository; | ||
private final OrderRepository orderRepository; | ||
private final StoreRepository storeRepository; | ||
|
||
@Transactional | ||
public ReviewDto registerReview(String email, RegisterReviewRequestDto dto) { | ||
userRepository.findByEmail(email).orElseThrow(()-> new UserNotFoundException("유저 정보가 존재하지 않습니다.")); | ||
Order order = orderRepository.findById(dto.getOrderId()).orElseThrow(()-> new OrderNotExistsException("orderId: "+dto.getOrderId()+"에 해당하는 주문이 존재하지 않습니다.")); | ||
|
||
Review review = reviewRepository.save(new Review(null, order, dto.getRating(), dto.getMessage())); | ||
|
||
return new ReviewDto(review.getId(), review.getOrder().getId(), review.getRating(), review.getMessage()); | ||
} | ||
|
||
@Transactional | ||
public GetRegisteredReviewsResponseDto getUserRegisteredReviews(String email) { | ||
User user = userRepository.findByEmail(email).orElseThrow(() -> new UserNotFoundException("유저 정보가 존재하지 않습니다.")); | ||
|
||
List<Review> reviews = reviewRepository.findAllReviewsByUser(user); | ||
|
||
return new GetRegisteredReviewsResponseDto( | ||
reviews.stream() | ||
.map(r -> new ReviewDto(r.getId(), r.getOrder().getId(), r.getRating(), r.getMessage())) | ||
.collect(Collectors.toList()) | ||
); | ||
} | ||
|
||
@Transactional | ||
public GetRegisteredReviewsResponseDto getStoreRegisteredReviews(Long storeId) { | ||
Store store = storeRepository.findById(storeId).orElseThrow(()-> new StoreNotExistsException("storeId: "+storeId+"에 해당하는 가게가 존재하지 않습니다.")); | ||
|
||
List<Review> reviews = reviewRepository.findAllReviewsByStore(store); | ||
|
||
return new GetRegisteredReviewsResponseDto( | ||
reviews.stream() | ||
.map(r -> new ReviewDto(r.getId(), r.getOrder().getId(), r.getRating(), r.getMessage())) | ||
.collect(Collectors.toList()) | ||
); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/kusitms/jipbap/order/dto/GetRegisteredReviewsResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.kusitms.jipbap.order.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
import java.util.List; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class GetRegisteredReviewsResponseDto { | ||
private List<ReviewDto> reviewList; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/com/kusitms/jipbap/order/dto/RegisterReviewRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.kusitms.jipbap.order.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class RegisterReviewRequestDto { | ||
private Long orderId; | ||
private Long rating; | ||
private String message; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.kusitms.jipbap.order.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class ReviewDto { | ||
|
||
private Long id; | ||
|
||
private Long orderId; | ||
|
||
private Long rating; | ||
|
||
private String message; | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/kusitms/jipbap/order/exception/OrderNotExistsException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.kusitms.jipbap.order.exception; | ||
|
||
public class OrderNotExistsException extends RuntimeException{ | ||
public OrderNotExistsException(String message) { | ||
super(message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class RegisterStoreRequestDto { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.