-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/kariskan step3 #13
Merged
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
4521acd
feat: Review entity 작성
kariskan 6531d84
feat: 상품에 대한 주문 주량, 평균 평점 column 추가
kariskan d9235d3
feat: 리뷰 추가 로직
kariskan d1146c9
feat: 리뷰 객체 관리하는 factory 클래스 작성
kariskan 9cee426
fix: 상품 구매 확정 시 상품에 대한 구매 횟수 증가
kariskan 7a4bc18
feat: 중복 리뷰 에러 코드 추가
kariskan 417d558
feat: ReviewController 요청에 인터셉터 거치도록 수정
kariskan 5f1e396
feat: ReviewController 작성
kariskan b9ba65f
feat: 상품 검색 기준 SortType 작성
kariskan 720f044
feat: 상품 검색 Controller 작성
kariskan fcc83f1
feat: 검색 조건에 따른 쿼리 작성
kariskan 55c8f38
feat: @ModelAttribute 검증기 작성
kariskan ab83678
fix: column definition 변경
kariskan ca6f424
fix: ddl-auto 옵션 변경
kariskan 100aff7
test: ProductController test 추가
kariskan 9dce566
test: ReviewController test 추가
kariskan eafc4f7
test: ProductReadService test 추가
kariskan ce558c8
test: ReviewService test 추가
kariskan 58e11b7
style: reformat code
kariskan 03f2f88
refactor: code smell 제거
kariskan ba453e6
test: entity 테스트 추가
kariskan dd0100d
refactor: @Min, @Max를 @Range로 변경
kariskan 3bbbc72
refactor: 변수명 간소화
kariskan e110bca
refactor: 불필요한 import 제거
kariskan 22ba3bf
refactor: magic number 제거
kariskan ae58853
fix: 해당 상품에 구매 이력이 존재하는 경우에만 리뷰 작성하도록 수정
kariskan 4361cd9
test: ReviewServiceTest 추가
kariskan 71fba2f
style: 주석 추가
kariskan 415e5de
test: 상품 검색 테스트 수정
kariskan 01d0876
test: @SpringBootTest 제거
kariskan edb548b
test: @SpringBootTest 제거
kariskan 0a83f2b
refactor: 형식 일치, asc 제거
kariskan 53064d6
refactor: requireNonNullElse 활용
kariskan b55169e
chore: ddl-auto 옵션 변경
kariskan 83ffe38
fix: count 쿼리가 아닌 exists 쿼리로 변경
kariskan 797fce9
refactor: factory class 의존성 삭제하고 static 메서드로 변경
kariskan ae37561
fix: http status code 변경
kariskan 1d88ac1
fix: avgScore 고정 소수점 계산으로 변경
kariskan 19ab651
feat: 동적 쿼리 MyBatis 도입
kariskan 040c2b2
bug: 잘못된 쿼리 수정
kariskan 5925e88
feat: ReviewFactory private 생성자 추가
kariskan 6f3bb69
feat: OrderProduct Scheduler 추가
kariskan 7116384
style: code reformat
kariskan 1de95b3
chore: build.gradle 수정
kariskan 2b9b59e
fix: error message 수정
kariskan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/org/c4marathon/assignment/domain/order/repository/OrderRepository.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 |
---|---|---|
@@ -1,7 +1,11 @@ | ||
package org.c4marathon.assignment.domain.order.repository; | ||
|
||
import java.util.List; | ||
|
||
import org.c4marathon.assignment.domain.order.entity.Order; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface OrderRepository extends JpaRepository<Order, Long> { | ||
|
||
boolean existsByConsumerIdAndIdIn(Long consumerId, List<Long> ids); | ||
} |
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
27 changes: 27 additions & 0 deletions
27
src/main/java/org/c4marathon/assignment/domain/product/controller/ProductController.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,27 @@ | ||
package org.c4marathon.assignment.domain.product.controller; | ||
|
||
import org.c4marathon.assignment.domain.product.dto.request.ProductSearchRequest; | ||
import org.c4marathon.assignment.domain.product.dto.response.ProductSearchResponse; | ||
import org.c4marathon.assignment.domain.product.service.ProductReadService; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.ModelAttribute; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/products") | ||
public class ProductController { | ||
|
||
private final ProductReadService productReadService; | ||
|
||
@GetMapping | ||
public ProductSearchResponse searchProduct( | ||
@Valid @ModelAttribute ProductSearchRequest request | ||
) { | ||
return productReadService.searchProduct(request); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/org/c4marathon/assignment/domain/product/dto/request/ProductSearchRequest.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,48 @@ | ||
package org.c4marathon.assignment.domain.product.dto.request; | ||
|
||
import static java.util.Objects.*; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import org.c4marathon.assignment.global.constant.SortType; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Size; | ||
import lombok.Builder; | ||
|
||
public record ProductSearchRequest( | ||
@NotNull @Size(min = 2, message = "keyword length less than 2") String keyword, | ||
@NotNull SortType sortType, | ||
LocalDateTime createdAt, | ||
Long productId, | ||
Long amount, | ||
Long orderCount, | ||
Double score, | ||
int pageSize | ||
) { | ||
|
||
@Builder | ||
public ProductSearchRequest( | ||
String keyword, | ||
SortType sortType, | ||
LocalDateTime createdAt, | ||
Long productId, | ||
Long amount, | ||
Long orderCount, | ||
Double score, | ||
int pageSize | ||
) { | ||
this.keyword = keyword; | ||
this.sortType = sortType; | ||
this.createdAt = requireNonNullElse(createdAt, LocalDateTime.now()); | ||
this.productId = requireNonNullElse(productId, Long.MIN_VALUE); | ||
this.amount = requireNonNullElse(amount, getDefaultAmount(sortType)); | ||
this.orderCount = requireNonNullElse(orderCount, Long.MAX_VALUE); | ||
this.score = requireNonNullElse(score, Double.MAX_VALUE); | ||
this.pageSize = pageSize; | ||
} | ||
|
||
private Long getDefaultAmount(SortType sortType) { | ||
return sortType == SortType.PRICE_ASC ? Long.MIN_VALUE : Long.MAX_VALUE; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/org/c4marathon/assignment/domain/product/dto/response/ProductSearchEntry.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,15 @@ | ||
package org.c4marathon.assignment.domain.product.dto.response; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public record ProductSearchEntry( | ||
long id, | ||
String name, | ||
String description, | ||
long amount, | ||
int stock, | ||
LocalDateTime createdAt, | ||
Long orderCount, | ||
Double avgScore | ||
) { | ||
} |
8 changes: 8 additions & 0 deletions
8
...ain/java/org/c4marathon/assignment/domain/product/dto/response/ProductSearchResponse.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,8 @@ | ||
package org.c4marathon.assignment.domain.product.dto.response; | ||
|
||
import java.util.List; | ||
|
||
public record ProductSearchResponse( | ||
List<ProductSearchEntry> productSearchEntries | ||
) { | ||
} |
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
12 changes: 12 additions & 0 deletions
12
src/main/java/org/c4marathon/assignment/domain/product/repository/ProductMapper.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,12 @@ | ||
package org.c4marathon.assignment.domain.product.repository; | ||
|
||
import java.util.List; | ||
|
||
import org.apache.ibatis.annotations.Mapper; | ||
import org.c4marathon.assignment.domain.product.dto.request.ProductSearchRequest; | ||
import org.c4marathon.assignment.domain.product.dto.response.ProductSearchEntry; | ||
|
||
@Mapper | ||
public interface ProductMapper { | ||
List<ProductSearchEntry> selectByCondition(ProductSearchRequest request); | ||
} |
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
27 changes: 27 additions & 0 deletions
27
src/main/java/org/c4marathon/assignment/domain/review/controller/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,27 @@ | ||
package org.c4marathon.assignment.domain.review.controller; | ||
|
||
import org.c4marathon.assignment.domain.consumer.entity.Consumer; | ||
import org.c4marathon.assignment.domain.review.dto.request.ReviewCreateRequest; | ||
import org.c4marathon.assignment.domain.review.service.ReviewService; | ||
import org.c4marathon.assignment.global.auth.ConsumerThreadLocal; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/reviews") | ||
public class ReviewController { | ||
|
||
private final ReviewService reviewService; | ||
|
||
@PostMapping | ||
public void createReview(@Valid @RequestBody ReviewCreateRequest request) { | ||
Consumer consumer = ConsumerThreadLocal.get(); | ||
reviewService.createReview(consumer, request); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/org/c4marathon/assignment/domain/review/dto/request/ReviewCreateRequest.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,14 @@ | ||
package org.c4marathon.assignment.domain.review.dto.request; | ||
|
||
import org.hibernate.validator.constraints.Range; | ||
|
||
import jakarta.validation.constraints.Size; | ||
|
||
public record ReviewCreateRequest( | ||
@Range(min = 1, max = 5, message = "invalid score range") | ||
int score, | ||
@Size(max = 100, message = "comment length more than 100") | ||
String comment, | ||
long productId | ||
) { | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
가능하면
@ModelAttribute
보다는@RequestBody
를 사용하면 좋을 것 같아요.참고: https://tecoble.techcourse.co.kr/post/2021-05-11-requestbody-modelattribute/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이유가 왜일까요? 참고 문서에서는
@RequestBody
는 http body가 java object로 변환되고,@ModelAttribute
는 form or query param을 java object로 변환된다고 하는데 GetMapping에서는 body를 통한 데이터 전달을 지양하고, 보통 query string으로 요청을 하는 것으로 알고 있어서요.차이가 있다면 RequestBody는 기본 생성자 + getter or setter이고 ModelAttribute는 생성자 or setter인 것 같습니다.
그런데 record로 정의하면 생성자, getter, 기타 등등 포함되기 때문에 어떤 형태로 오든 변환이 가능하지 않나요?
ProductSearchRequest.class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아 Get이었네요 ㅋㅋ
제가 잘못봄