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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@Slf4j
public class ControllerLoggingAspect {

@Pointcut("execution(* com.jiyoung.kikihi.platform.adapter.in.web..*.*(..))")
@Pointcut("execution(* site.kikihi.custom.platform.adapter.in.web..*.*(..))")
private void controllerPointcut() {}

@Before("controllerPointcut()")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@Slf4j
public class LoggingAspect {

@Pointcut("execution(* com.jiyoung.kikihi.platform.application.service.*Service.*(..))")
@Pointcut("execution(* site.kikihi.custom.platform.application.service.*Service.*(..))")
private void applicationLayer() {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ public ApiResponse<List<KeyboardRecommendationResponse>> getSimilarProducts(
UUID userId = principalDetails != null ? principalDetails.getId() : null;

// ์œ ์‚ฌํ•œ ์ƒํ’ˆ ์ถ”์ฒœ ์„œ๋น„์Šค ํ˜ธ์ถœ
List<Product> similarProducts = service.getSimilarProducts(userId,productId);
List<KeyboardRecommendationResponse> similarProducts = service.getSimilarProducts(userId,productId);

// ์‘๋‹ต ์ฃผ๊ธฐ
return ApiResponse.ok(KeyboardRecommendationResponse.from(similarProducts));
return ApiResponse.ok(similarProducts);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public String getValue() {

@Getter
@RequiredArgsConstructor
@Schema(name = "[์š”์ฒญ][์ƒํ’ˆ] ํ‚ค์••(Key Pressure) Enum", description = "ํ‚ค์•• ์˜ต์…˜")
@Schema(name = "[์š”์ฒญ][์ƒํ’ˆ] ๋ ˆ์ด์•„์›ƒ(Layout) Enum", description = "๋ ˆ์ด์•„์›ƒ ์˜ต์…˜")
public enum Layout {
@Schema(description = "์ธ์ฒด๊ณตํ•™์  (์Šคํ…์Šค์ปฌ์ณ2)", example = "egonomic")
ERGONOMIC("egonomic"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

@Getter
@Setter
@Schema(name = "[์š”์ฒญ][์ƒํ’ˆ] ํ‚ค๋ณด๋“œ ์ถ”์ฒœ ์š”์ฒญ DTO", description = "ํ‚ค๋ณด๋“œ ์ถ”์ฒœ ์š”์ฒญ์— ์‚ฌ์šฉํ•˜๋Š” DTO์ž…๋‹ˆ๋‹ค.")
@Schema(name = "[์š”์ฒญ][์ƒํ’ˆ] ํ‚ค๋ณด๋“œ ์ถ”์ฒœ ์š”์ฒญ Request", description = "ํ‚ค๋ณด๋“œ ์ถ”์ฒœ ์š”์ฒญ์— ์‚ฌ์šฉํ•˜๋Š” DTO์ž…๋‹ˆ๋‹ค.")
public class KeyboardRecommendationRequest {

@Schema(description = "ํ‚ค๋ณด๋“œ ๋ฐฐ์—ด(Size) ์˜ต์…˜", example = "ten", required = true)
@Schema(description = "ํ‚ค๋ณด๋“œ ๋ฐฐ์—ด(Size) ์˜ต์…˜", example = "tenkeyless", required = true)
private KeyboardOptions.Size size;

@Schema(description = "ํ‚ค์••(Key Pressure) ์˜ต์…˜", example = "light", required = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public record KeyboardRecommendationResponse(
String productName,

@Schema(description = "์ •์ƒ๊ฐ€(์›)", example = "599000.0")
double price,
Double price,

@Schema(description = "๋ถ๋งˆํฌ(์ข‹์•„์š”)ํ•œ ์ƒํ’ˆ ์—ฌ๋ถ€", example = "true")
boolean likedByMe
Expand All @@ -43,26 +43,17 @@ public record KeyboardRecommendationResponse(

/// ์ •์  ํŒฉํ† ๋ฆฌ ๋ฉ”์„œ๋“œ
// ๋‹จ์ผ ๊ฐ์ฒด ๋ณ€ํ™˜ ๋ฉ”์„œ๋“œ ์ถ”๊ฐ€
public static KeyboardRecommendationResponse from(Product product) {
public static KeyboardRecommendationResponse from(Product product, boolean likedByMe) {
return KeyboardRecommendationResponse.builder()
.id(product.getId())
.thumbnail(product.getThumbnail())
.manufacturerName(product.getManufacturer())
.productName(product.getName())
.price(product.getPrice())
.likedByMe(false)
.likedByMe(likedByMe)
.build();
}


// ๊ธฐ์กด ๋ฆฌ์ŠคํŠธ ๋ณ€ํ™˜ ๋ฉ”์„œ๋“œ๋Š” ๊ทธ๋Œ€๋กœ ์œ ์ง€
public static List<KeyboardRecommendationResponse> from(List<Product> productList) {
return productList.stream()
.map(KeyboardRecommendationResponse::from) // ๋‹จ์ผ ๊ฐ์ฒด ๋ณ€ํ™˜ ๋ฉ”์„œ๋“œ ํ˜ธ์ถœ
.toList();
}



}

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.springframework.stereotype.Component;
import site.kikihi.custom.platform.adapter.in.web.dto.request.product.KeyboardOptions;
import site.kikihi.custom.platform.adapter.out.mongo.product.ProductDocument;
import site.kikihi.custom.platform.adapter.out.mongo.product.ProductDocumentRepository;
import site.kikihi.custom.platform.application.out.bookmark.BookmarkPort;
import site.kikihi.custom.platform.application.out.recommend.RecommendKeyboardPort;
import site.kikihi.custom.platform.domain.bookmark.Bookmark;
Expand Down Expand Up @@ -53,21 +52,28 @@ public List<Product> filterAndRecommendKeyboards(
if (keyPressure != null) {
String keyPressureField = "spec_table.๊ธฐ๋Šฅ > ํ‚ค์••";
if (keyPressure <= 49) { // LIGHT ๊ตฌ๊ฐ„
query.addCriteria(Criteria.where(keyPressureField).regex("^([0-4]?[0-9])g$"));
andCriterias.add(Criteria.where(keyPressureField).regex("^([0-4]?[0-9])g$"));
} else { // NORMAL ๊ตฌ๊ฐ„
query.addCriteria(Criteria.where(keyPressureField).regex("^([5-9][0-9]|[1-9][0-9]{2,})g$"));
andCriterias.add(Criteria.where(keyPressureField).regex("^([5-9][0-9]|[1-9][0-9]{2,})g$"));
}

}
// Layout
if (layout != null && !layout.isBlank()) {
if ("ERGONOMIC".equalsIgnoreCase(layout)) {
query.addCriteria(Criteria.where("spec_table.ํ‚ค๋ณด๋“œ๊ตฌ์กฐ > ์Šคํ…์Šค์ปฌ์ณ2").is("โ—‹"));
String val = layout.trim();
boolean ergonomic = "ERGONOMIC".equalsIgnoreCase(val) || "egonomic".equalsIgnoreCase(val);
if (ergonomic) {
andCriterias.add(new Criteria().orOperator(
Criteria.where("spec_table.ํ‚ค๋ณด๋“œ๊ตฌ์กฐ > ์Šคํ…์Šค์ปฌ์ณ2").is("โ—‹"),
Criteria.where("description").regex("์Šคํ…์Šค์ปฌ์ณ2", "i")
));
} else if ("SIMPLE".equalsIgnoreCase(layout)) {
andCriterias.add(Criteria.where("spec_table.ํ‚ค๋ณด๋“œ๊ตฌ์กฐ > ๋กœ์šฐํ”„๋กœํŒŒ์ผ(LP)").is("โ—‹"));
andCriterias.add(Criteria.where("description").regex("์Šคํ…์Šค์ปฌ์ณ2", "i"));
andCriterias.add(Criteria.where("description").regex("lp", "i"));
andCriterias.add(new Criteria().orOperator(
Criteria.where("spec_table.ํ‚ค๋ณด๋“œ๊ตฌ์กฐ > ๋กœ์šฐํ”„๋กœํŒŒ์ผ(LP)").is("โ—‹"),
Criteria.where("description").regex("lp", "i")
));
}

}

// Switch Type
Expand All @@ -83,13 +89,13 @@ public List<Product> filterAndRecommendKeyboards(

// SoundDampener
if (soundDampener != null) {
if (soundDampener == KeyboardOptions.SoundDampener.YES.getValue()) {
if (KeyboardOptions.SoundDampener.YES.getValue().equals(soundDampener)) {
andCriterias.add(new Criteria().orOperator(
Criteria.where("spec_table.ํ‚ค๋ณด๋“œ๊ตฌ์กฐ > ํก์Œ์žฌ").is("โ—‹"),
Criteria.where("description").regex("ํก์Œ์žฌ")
));
} else {
query.addCriteria(new Criteria().andOperator(
andCriterias.add(new Criteria().andOperator(
Criteria.where("spec_table.ํ‚ค๋ณด๋“œ๊ตฌ์กฐ > ํก์Œ์žฌ").ne("โ—‹"),
Criteria.where("description").not().regex("ํก์Œ์žฌ")
));
Expand All @@ -98,13 +104,13 @@ public List<Product> filterAndRecommendKeyboards(

// RGB
if (rgb != null) {
if (rgb == KeyboardOptions.RGB.YES.getValue()) {
if (KeyboardOptions.RGB.YES.getValue().equals(rgb)) {
andCriterias.add(new Criteria().orOperator(
Criteria.where("spec_table.ํ‚ค๋ณด๋“œ๊ตฌ์กฐ > RGB ๋ฐฑ๋ผ์ดํŠธ").is("โ—‹"),
Criteria.where("description").regex("RGB", "i")
));
} else {
query.addCriteria(new Criteria().andOperator(
andCriterias.add(new Criteria().andOperator(
Criteria.where("spec_table.ํ‚ค๋ณด๋“œ๊ตฌ์กฐ > RGB ๋ฐฑ๋ผ์ดํŠธ").ne("โ—‹"),
Criteria.where("description").not().regex("RGB", "i")
));
Expand All @@ -113,19 +119,19 @@ public List<Product> filterAndRecommendKeyboards(

// ๊ฐ€๊ฒฉ
if (minPrice > 0 || maxPrice > 0) {
query.addCriteria(Criteria.where("options").elemMatch(
Criteria.where("main_price").gte(minPrice).lte(maxPrice)
));
}
List<Criteria> priceBounds = new ArrayList<>();
if (minPrice > 0) priceBounds.add(Criteria.where("main_price").gte(minPrice));
if (maxPrice > 0) priceBounds.add(Criteria.where("main_price").lte(maxPrice));
query.addCriteria(Criteria.where("options")
.elemMatch(new Criteria().andOperator(priceBounds.toArray(new Criteria[0]))));
}

// And ์กฐ๊ฑด ์ตœ์ข… ์ ์šฉ
if (!andCriterias.isEmpty()) {
query.addCriteria(new Criteria().andOperator(andCriterias.toArray(new Criteria[0])));
}

List<ProductDocument> results = mongoTemplate.find(query, ProductDocument.class);
return results.stream().map(ProductDocument::toDomain).toList();

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,33 @@
public class ProductDocument {

@Id
private String id; //
private String id;

private String category; //
private String category;

private String name; //
private String name;

private double price; //
private double price;

private List<String> description; //
private List<String> description;

@Field("thumbnail")
private String thumbnail; //
private String thumbnail;

private String manufacturer; //
private String manufacturer;

@Field("detail_purchase_url")
private String detailPageUrl; //
private String detailPageUrl;

@Field("options")
private List<Map<String, Object>> options; //
private List<Map<String, Object>> options;

@Field("all_detail_images")
private List<String> allDetailImages; //
private List<String> allDetailImages;

@Field("spec_table")
private Map<String, Object> specTable; // spec_table์€ ํ˜„์žฌ ๋น„์–ด์žˆ๋Š” ์ƒํƒœ๋กœ ์ดˆ๊ธฐํ™”
@Builder.Default
private Map<String, Object> specTable = new java.util.HashMap<>();

/// ๋„๋ฉ”์ธ ๋ณ€๊ฒฝ
public Product toDomain(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ public interface RecommendationUseCase {
List<KeyboardRecommendationResponse> getTutorialKeyboardRecommendation(UUID userId, KeyboardRecommendationRequest request);

/// ์œ ์‚ฌํ•œ ์ƒํ’ˆ ์ถ”์ฒœ
List<Product> getSimilarProducts(UUID userId, String productId);
List<KeyboardRecommendationResponse> getSimilarProducts(UUID userId, String productId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.stream.Collectors;

@Service
@Transactional
Expand Down Expand Up @@ -118,9 +119,11 @@ public List<KeyboardRecommendationResponse> getTutorialKeyboardRecommendation(UU
);

return documents.stream()
.map(KeyboardRecommendationResponse :: from)
.toList();

.map(product -> {
boolean likedByMe = bookmarkPort.checkBookmarkByUserIdAndProductId(userId, product.getId());
return KeyboardRecommendationResponse.from(product, likedByMe);
})
.collect(Collectors.toList());
}

/**
Expand All @@ -130,7 +133,7 @@ public List<KeyboardRecommendationResponse> getTutorialKeyboardRecommendation(UU
* @return
*/
@Override
public List<Product> getSimilarProducts(UUID userId, String productId) {
public List<KeyboardRecommendationResponse> getSimilarProducts(UUID userId, String productId) {
/// ์œ ์ €๊ฐ€ ์žˆ๋‹ค๋ฉด ์ฒดํฌ, ์—†๋‹ค๋ฉด ๋ฐ”๋กœ ์ƒํ’ˆ ์กฐํšŒ
// if (userId != null) {
// /// ์ปค์Šคํ…€์„ ์ œ์ž‘ํ–ˆ๋‹ค๋ฉด, ๋น„์Šทํ•œ ํŠน์„ฑ์˜ ์ƒํ’ˆ๋“ค์„ ์ถ”์ฒœ
Expand All @@ -145,8 +148,15 @@ public List<Product> getSimilarProducts(UUID userId, String productId) {
Product product = loadProduct(productId);

/// ์œ ์‚ฌํ•œ ์ƒํ’ˆ ํ•„ํ„ฐ๋ง
return recommendKeyboardPort.getSimilarProducts(userId, productId,product);
List<Product> documents=recommendKeyboardPort.getSimilarProducts(userId, productId,product);

// ๊ฐ ์ƒํ’ˆ๋ณ„ ๋ถ๋งˆํฌ ์—ฌ๋ถ€ ์ฒดํฌ ํ›„ ์‘๋‹ต ๋ฆฌ์ŠคํŠธ ์ƒ์„ฑ
return documents.stream()
.map(similarProduct -> {
boolean likedByMe = bookmarkPort.checkBookmarkByUserIdAndProductId(userId, similarProduct.getId());
return KeyboardRecommendationResponse.from(similarProduct, likedByMe);
})
.collect(Collectors.toList());
}


Expand Down
Loading