-
Notifications
You must be signed in to change notification settings - Fork 36
Round5 #141
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
Merged
Merged
Round5 #141
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
af777a8
feat: Redis μ€μ λ° μΊμ κΈ°λ³Έ ꡬ쑰 ꡬμΆ
sylee6529 4003796
feat: μ’μμ κΈ°λ₯ κ°μ - Redis μΊμ μ μ© λ° νμ
μμ μ± ν₯μ
sylee6529 7339613
feat: μν μ‘°ν κΈ°λ₯ μ 체 κ°μ - Redis μΊμ, 컀μ νμ΄μ§, μΈκΈ° μν API
sylee6529 e1a1921
test: μν μ‘°ν κΈ°λ₯ ν
μ€νΈ μΆκ°
sylee6529 0877830
feat: λ‘컬 κ°λ° νκ²½ κ°μ - λλ ν
μ€νΈ λ°μ΄ν° μμ± λ° μ€μ μ΅μ ν
sylee6529 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
23 changes: 23 additions & 0 deletions
23
apps/commerce-api/src/main/java/com/loopers/application/product/CursorPageInfo.java
This file contains hidden or 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,23 @@ | ||
| package com.loopers.application.product; | ||
|
|
||
| import lombok.Getter; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Getter | ||
| public class CursorPageInfo<T> { | ||
|
|
||
| private final List<T> content; | ||
| private final String nextCursor; | ||
| private final boolean hasNext; | ||
|
|
||
| private CursorPageInfo(List<T> content, String nextCursor, boolean hasNext) { | ||
| this.content = content; | ||
| this.nextCursor = nextCursor; | ||
| this.hasNext = hasNext; | ||
| } | ||
|
|
||
| public static <T> CursorPageInfo<T> of(List<T> content, String nextCursor, boolean hasNext) { | ||
| return new CursorPageInfo<>(content, nextCursor, hasNext); | ||
| } | ||
| } |
28 changes: 28 additions & 0 deletions
28
...ommerce-api/src/main/java/com/loopers/application/product/ProductCursorSearchCommand.java
This file contains hidden or 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,28 @@ | ||
| package com.loopers.application.product; | ||
|
|
||
| import com.loopers.domain.product.enums.ProductSortCondition; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @Builder | ||
| public class ProductCursorSearchCommand { | ||
|
|
||
| private final Long brandId; | ||
| private final String keyword; | ||
| private final ProductSortCondition sort; | ||
| private final String cursor; | ||
| private final int size; | ||
| private final Long memberIdOrNull; | ||
|
|
||
| public static ProductCursorSearchCommand of(Long brandId, String keyword, ProductSortCondition sort, String cursor, int size, Long memberIdOrNull) { | ||
| return ProductCursorSearchCommand.builder() | ||
| .brandId(brandId) | ||
| .keyword(keyword) | ||
| .sort(sort) | ||
| .cursor(cursor) | ||
| .size(size) | ||
| .memberIdOrNull(memberIdOrNull) | ||
| .build(); | ||
| } | ||
| } |
This file contains hidden or 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
98 changes: 94 additions & 4 deletions
98
apps/commerce-api/src/main/java/com/loopers/application/product/ProductFacade.java
This file contains hidden or 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,39 +1,129 @@ | ||
| package com.loopers.application.product; | ||
|
|
||
| import com.loopers.domain.like.service.LikeReadService; | ||
| import com.loopers.domain.product.service.ProductReadService; | ||
| import com.loopers.domain.product.command.ProductSearchFilter; | ||
| import com.loopers.domain.product.enums.ProductSortCondition; | ||
| import com.loopers.infrastructure.cache.ProductDetailCache; | ||
| import com.loopers.infrastructure.cache.ProductListCache; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.data.domain.Page; | ||
| import org.springframework.data.domain.PageRequest; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.stereotype.Component; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Component | ||
| @Transactional | ||
| public class ProductFacade { | ||
|
|
||
| private final ProductReadService productReadService; | ||
| private final LikeReadService likeReadService; | ||
| private final ProductDetailCache productDetailCache; | ||
| private final ProductListCache productListCache; | ||
|
|
||
| @Transactional(readOnly = true) | ||
| public Page<ProductSummaryInfo> getProducts(ProductSearchCommand command) { | ||
| // Cache only for LIKES_DESC sort | ||
| if (command.getSort() == ProductSortCondition.LIKES_DESC) { | ||
| return productListCache.get( | ||
| command.getBrandId(), | ||
| command.getSort(), | ||
| command.getPage(), | ||
| command.getSize() | ||
| ).orElseGet(() -> { | ||
| Page<ProductSummaryInfo> result = fetchProducts(command); | ||
| productListCache.set( | ||
| command.getBrandId(), | ||
| command.getSort(), | ||
| command.getPage(), | ||
| command.getSize(), | ||
| result | ||
| ); | ||
| return result; | ||
| }); | ||
| } | ||
|
|
||
| return fetchProducts(command); | ||
| } | ||
|
|
||
| private Page<ProductSummaryInfo> fetchProducts(ProductSearchCommand command) { | ||
| ProductSearchFilter filter = ProductSearchFilter.of( | ||
| command.getBrandId(), | ||
| command.getKeyword(), | ||
| command.getSort() | ||
| ); | ||
|
|
||
| Pageable pageable = PageRequest.of(command.getPage(), command.getSize()); | ||
|
|
||
| return productReadService.getProducts( | ||
| filter, | ||
| pageable, | ||
| filter, | ||
| pageable, | ||
| command.getMemberIdOrNull() | ||
| ); | ||
| } | ||
|
|
||
| @Transactional(readOnly = true) | ||
| public ProductDetailInfo getProductDetail(Long productId, String memberIdOrNull) { | ||
| return productReadService.getProductDetail(productId, memberIdOrNull); | ||
| public CursorPageInfo<ProductSummaryInfo> getProductsByCursor(ProductCursorSearchCommand command) { | ||
| ProductSearchFilter filter = ProductSearchFilter.of( | ||
| command.getBrandId(), | ||
| command.getKeyword(), | ||
| command.getSort() | ||
| ); | ||
|
|
||
| return productReadService.getProductsByCursor( | ||
| filter, | ||
| command.getCursor(), | ||
| command.getSize(), | ||
| command.getMemberIdOrNull() | ||
| ); | ||
| } | ||
|
|
||
| @Transactional(readOnly = true) | ||
| public ProductDetailInfo getProductDetail(Long productId, Long memberIdOrNull) { | ||
| // 1. μΊμμμ μν μ 보 μ‘°ν (isLikedByMember=falseμΈ μν) | ||
| ProductDetailInfo cachedInfo = productDetailCache.get(productId) | ||
| .orElseGet(() -> { | ||
| // μΊμ miss: DB μ‘°ν (isLikedByMemberλ λμ€μ κ³μ°) | ||
| ProductDetailInfo result = productReadService.getProductDetail(productId, null); | ||
| productDetailCache.set(productId, result); | ||
| return result; | ||
| }); | ||
|
|
||
| // 2. λ‘κ·ΈμΈνμ§ μμ κ²½μ° λ°λ‘ λ°ν | ||
| if (memberIdOrNull == null) { | ||
| return cachedInfo; // isLikedByMember=false κ·Έλλ‘ | ||
| } | ||
|
|
||
| // 3. isLikedByMemberλ§ λμ κ³μ° | ||
| boolean isLiked = likeReadService.isLikedBy(memberIdOrNull, productId); | ||
|
|
||
| // 4. isLikedByMember νλλ§ κ΅μ²΄ν΄μ λ°ν | ||
| return ProductDetailInfo.builder() | ||
| .id(cachedInfo.getId()) | ||
| .name(cachedInfo.getName()) | ||
| .description(cachedInfo.getDescription()) | ||
| .brandName(cachedInfo.getBrandName()) | ||
| .brandDescription(cachedInfo.getBrandDescription()) | ||
| .price(cachedInfo.getPrice()) | ||
| .stock(cachedInfo.getStock()) | ||
| .likeCount(cachedInfo.getLikeCount()) | ||
| .isLikedByMember(isLiked) // β λμ κ³μ° | ||
| .build(); | ||
| } | ||
|
|
||
| @Transactional(readOnly = true) | ||
| public List<ProductSummaryInfo> getPopularProducts(Long memberIdOrNull) { | ||
| // μΊμ μ κ±° - μμ DB μ‘°ν | ||
| return productReadService.getPopularProducts(memberIdOrNull); | ||
| } | ||
|
|
||
| @Transactional(readOnly = true) | ||
| public List<ProductSummaryInfo> getBrandPopularProducts(Long brandId, int limit, Long memberIdOrNull) { | ||
| // μΊμ μ κ±° - μμ DB μ‘°ν | ||
| return productReadService.getBrandPopularProducts(brandId, limit, memberIdOrNull); | ||
| } | ||
| } | ||
This file contains hidden or 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
13 changes: 10 additions & 3 deletions
13
apps/commerce-api/src/main/java/com/loopers/application/product/ProductSummaryInfo.java
This file contains hidden or 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,25 +1,32 @@ | ||
| package com.loopers.application.product; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
| import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; | ||
| import com.loopers.domain.common.vo.Money; | ||
| import lombok.Builder; | ||
|
|
||
| @Builder | ||
| @JsonDeserialize(builder = ProductSummaryInfo.ProductSummaryInfoBuilder.class) | ||
| public class ProductSummaryInfo { | ||
|
|
||
| private final Long id; | ||
| private final String name; | ||
| private final String brandName; | ||
| private final Money price; | ||
| private final int likeCount; | ||
| private final boolean isLikedByMember; | ||
|
|
||
| public Long getId() { return id; } | ||
| public String getName() { return name; } | ||
| public String getBrandName() { return brandName; } | ||
| public Money getPrice() { return price; } | ||
| public int getLikeCount() { return likeCount; } | ||
|
|
||
| @JsonProperty("likedByMember") | ||
| public boolean isLikedByMember() { return isLikedByMember; } | ||
|
|
||
| @JsonPOJOBuilder(withPrefix = "") | ||
| public static class ProductSummaryInfoBuilder { | ||
| } | ||
| } |
This file contains hidden or 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.
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.
μΊμλ μν λͺ©λ‘μμ
isLikedByMemberμνκ° μΌκ΄λμ§ μμ μ μμ΅λλ€.productListCacheλmemberIdλ₯Ό ν€μ ν¬ν¨νμ§ μμ§λ§,fetchProductsλmemberIdOrNullμ μ λ¬νμ¬isLikedByMemberλ₯Ό κ³μ°ν©λλ€. 첫 λ²μ§Έ μμ²μμ μ’μμ μνκ° μΊμλμ΄ λ€λ₯Έ μ¬μ©μμκ² μλͺ»λ μ λ³΄κ° μ 곡λ μ μμ΅λλ€.μν λͺ©λ‘ μΊμλ
isLikedByMember=falseμΈ μνλ‘ μ μ₯νκ³ , μμΈ μ‘°νμ²λΌ λμ μΌλ‘ κ³μ°νλ λ°©μμ κΆμ₯ν©λλ€:if (command.getSort() == ProductSortCondition.LIKES_DESC) { return productListCache.get( command.getBrandId(), command.getSort(), command.getPage(), command.getSize() ).orElseGet(() -> { - Page<ProductSummaryInfo> result = fetchProducts(command); + // μΊμμλ isLikedByMember=false μνλ‘ μ μ₯ + Page<ProductSummaryInfo> result = fetchProducts(command.withMemberIdNull()); productListCache.set( command.getBrandId(), command.getSort(), command.getPage(), command.getSize(), result ); return result; - }); + }).map(cached -> enrichWithLikeStatus(cached, command.getMemberIdOrNull())); }π€ Prompt for AI Agents