-
Notifications
You must be signed in to change notification settings - Fork 24
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 #13 from C4-ComeTrue/feature/kariskan_step3
Feature/kariskan step3
- Loading branch information
Showing
37 changed files
with
941 additions
and
8 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/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.