Skip to content
Open
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
2 changes: 1 addition & 1 deletion .claude/rules/project/architecture.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 아키텍처

## 패키지 구조 (DDD)
## 패키지 구조 (4-Layered_Architecture)
```
com.loopers/
├── interfaces/ # REST 컨트롤러, Request DTO, Response DTO (V1Dto)
Expand Down
3 changes: 3 additions & 0 deletions apps/commerce-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ dependencies {
implementation(project(":supports:logging"))
implementation(project(":supports:monitoring"))

// cache
implementation("com.github.ben-manes.caffeine:caffeine")

// web
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.security:spring-security-crypto")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.loopers.application.brand.BrandService;
import com.loopers.application.product.ProductService;
import com.loopers.domain.brand.Brand;
import com.loopers.infrastructure.product.ProductCacheManager;
import com.loopers.domain.like.Like;
import com.loopers.domain.product.Product;
import com.loopers.support.error.CoreException;
Expand All @@ -12,6 +13,7 @@
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import static com.loopers.support.transaction.TransactionHelper.afterCommit;

import java.util.Map;
import java.util.Set;
Expand All @@ -24,6 +26,7 @@ public class LikeFacade {
private final LikeService likeService;
private final ProductService productService;
private final BrandService brandService;
private final ProductCacheManager productCacheManager;

// Command

Expand All @@ -34,6 +37,7 @@ public void like(Long userId, Long productId) {
boolean created = likeService.like(userId, productId);
if (created) {
productService.incrementLikeCount(productId);
afterCommit(() -> productCacheManager.evictDetail(productId));
}
}

Expand All @@ -42,6 +46,7 @@ public void unlike(Long userId, Long productId) {
boolean deleted = likeService.unlike(userId, productId);
if (deleted) {
productService.decrementLikeCountIfPositive(productId);
afterCommit(() -> productCacheManager.evictDetail(productId));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public boolean unlike(Long userId, Long productId) {

// Query

@Transactional(readOnly = true)
public boolean isLiked(Long userId, Long productId) {
return likeRepository.existsByUserIdAndProductId(userId, productId);
}

@Transactional(readOnly = true)
public Page<Like> findLikedActiveProducts(Long userId, Pageable pageable) {
return likeRepository.findAllByUserIdWithActiveProduct(userId, pageable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.loopers.application.product.ProductService;
import com.loopers.domain.order.Order;
import com.loopers.domain.product.Product;
import com.loopers.domain.order.OrderStatus;
import com.loopers.support.error.CoreException;
import com.loopers.support.error.ErrorType;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -72,8 +73,8 @@ public OrderInfo getOrderDetail(Long userId, Long orderId) {
}

@Transactional(readOnly = true)
public Page<OrderInfo.OrderSummary> getOrderList(Long userId, ZonedDateTime startDateTime, ZonedDateTime endDateTime, Pageable pageable) {
Page<Order> orders = orderService.findOrdersByUserIdAndDateRange(userId, startDateTime, endDateTime, pageable);
public Page<OrderInfo.OrderSummary> getOrderList(Long userId, OrderStatus status, ZonedDateTime startDateTime, ZonedDateTime endDateTime, Pageable pageable) {
Page<Order> orders = orderService.findOrdersByUserIdAndStatusAndDateRange(userId, status, startDateTime, endDateTime, pageable);
return orders.map(OrderInfo.OrderSummary::from);
}

Expand All @@ -84,8 +85,16 @@ public OrderInfo getAdminOrderDetail(Long orderId) {
}

@Transactional(readOnly = true)
public Page<OrderInfo.OrderAdminSummary> getAdminOrderList(Pageable pageable) {
Page<Order> orders = orderService.findAllOrders(pageable);
public Page<OrderInfo.OrderAdminSummary> getAdminOrderList(OrderStatus status, Pageable pageable) {
Page<Order> orders = (status != null)
? orderService.findOrdersByStatus(status, pageable)
: orderService.findAllOrders(pageable);
return orders.map(OrderInfo.OrderAdminSummary::from);
}

@Transactional(readOnly = true)
public Page<OrderInfo.OrderAdminSummary> getAdminOrdersByProduct(Long productId, Pageable pageable) {
Page<Order> orders = orderService.findOrdersByProductId(productId, pageable);
return orders.map(OrderInfo.OrderAdminSummary::from);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.loopers.domain.order.Order;
import com.loopers.domain.order.OrderItem;
import com.loopers.domain.order.OrderStatus;

import java.math.BigDecimal;
import java.time.LocalDateTime;
Expand All @@ -10,6 +11,7 @@
public record OrderInfo(
Long id,
Long userId,
OrderStatus status,
BigDecimal totalAmount,
BigDecimal discountAmount,
BigDecimal finalAmount,
Expand Down Expand Up @@ -44,6 +46,7 @@ public static OrderInfo from(Order order) {
return new OrderInfo(
order.getId(),
order.getUserId(),
order.getStatus(),
order.getTotalAmount(),
order.getDiscountAmount(),
order.getFinalAmount(),
Expand All @@ -55,6 +58,7 @@ public static OrderInfo from(Order order) {

public record OrderSummary(
Long id,
OrderStatus status,
BigDecimal totalAmount,
BigDecimal discountAmount,
BigDecimal finalAmount,
Expand All @@ -65,6 +69,7 @@ public record OrderSummary(
public static OrderSummary from(Order order) {
return new OrderSummary(
order.getId(),
order.getStatus(),
order.getTotalAmount(),
order.getDiscountAmount(),
order.getFinalAmount(),
Expand All @@ -77,6 +82,7 @@ public static OrderSummary from(Order order) {
public record OrderAdminSummary(
Long id,
Long userId,
OrderStatus status,
BigDecimal totalAmount,
BigDecimal discountAmount,
BigDecimal finalAmount,
Expand All @@ -88,6 +94,7 @@ public static OrderAdminSummary from(Order order) {
return new OrderAdminSummary(
order.getId(),
order.getUserId(),
order.getStatus(),
order.getTotalAmount(),
order.getDiscountAmount(),
order.getFinalAmount(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.loopers.domain.order.Order;
import com.loopers.domain.order.OrderRepository;
import com.loopers.domain.order.OrderStatus;
import com.loopers.support.error.CoreException;
import com.loopers.support.error.ErrorType;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -52,12 +53,22 @@ public Order getOrder(Long orderId) {
}

@Transactional(readOnly = true)
public Page<Order> findOrdersByUserIdAndDateRange(Long userId, ZonedDateTime startDate, ZonedDateTime endDate, Pageable pageable) {
return orderRepository.findAllByUserIdAndCreatedAtBetween(userId, startDate, endDate, pageable);
public Page<Order> findAllOrders(Pageable pageable) {
return orderRepository.findAll(pageable);
}

@Transactional(readOnly = true)
public Page<Order> findAllOrders(Pageable pageable) {
return orderRepository.findAll(pageable);
public Page<Order> findOrdersByUserIdAndStatusAndDateRange(Long userId, OrderStatus status, ZonedDateTime startDate, ZonedDateTime endDate, Pageable pageable) {
return orderRepository.findAllByUserIdAndStatusAndCreatedAtBetween(userId, status, startDate, endDate, pageable);
}

@Transactional(readOnly = true)
public Page<Order> findOrdersByStatus(OrderStatus status, Pageable pageable) {
return orderRepository.findAllByStatus(status, pageable);
}

@Transactional(readOnly = true)
public Page<Order> findOrdersByProductId(Long productId, Pageable pageable) {
return orderRepository.findAllByProductId(productId, pageable);
}
}
Loading