-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
962 additions
and
228 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
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
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
8 changes: 8 additions & 0 deletions
8
...s/smrtstore/domain/orderManagement/delivery/infrastructure/DeliveryInfoJpaRepository.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 com.programmers.smrtstore.domain.orderManagement.delivery.infrastructure; | ||
|
||
import com.programmers.smrtstore.domain.orderManagement.delivery.entity.DeliveryInfo; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface DeliveryInfoJpaRepository extends JpaRepository<DeliveryInfo, Long> { | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
...com/programmers/smrtstore/domain/orderManagement/order/application/OrderPointService.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,52 @@ | ||
package com.programmers.smrtstore.domain.orderManagement.order.application; | ||
|
||
import static com.programmers.smrtstore.core.properties.ErrorCode.ORDER_NOT_FOUND; | ||
import static com.programmers.smrtstore.core.properties.ErrorCode.USER_NOT_FOUND; | ||
|
||
import com.programmers.smrtstore.domain.orderManagement.order.domain.entity.Order; | ||
import com.programmers.smrtstore.domain.orderManagement.order.exception.OrderException; | ||
import com.programmers.smrtstore.domain.orderManagement.order.infrastructure.OrderJpaRepository; | ||
import com.programmers.smrtstore.domain.orderManagement.order.presentation.dto.res.OrderedProductResponse; | ||
import com.programmers.smrtstore.domain.user.domain.entity.User; | ||
import com.programmers.smrtstore.domain.user.exception.UserException; | ||
import com.programmers.smrtstore.domain.user.infrastructure.UserJpaRepository; | ||
import com.programmers.smrtstore.util.DateTimeUtils; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class OrderPointService { | ||
private final UserJpaRepository userJpaRepository; | ||
private final OrderJpaRepository orderJpaRepository; | ||
|
||
public Integer calculateUserMonthlyTotalSpending(Long userId, int month, int year) { | ||
checkUserExistence(userId); | ||
DateTimeUtils.validateMonth(month); | ||
DateTimeUtils.validateYear(year); | ||
return orderJpaRepository.calculateMonthlyTotalSpending(userId, month, year); | ||
} | ||
|
||
public Integer getTotalPriceByOrderId(String orderId) { | ||
Order order = orderJpaRepository.findByIdIncludeDeleted(orderId) | ||
.orElseThrow(() -> new OrderException(ORDER_NOT_FOUND, String.valueOf(orderId))); | ||
return order.getTotalPrice(); | ||
} | ||
|
||
public List<OrderedProductResponse> getProductsForOrder(String orderId) { | ||
return orderJpaRepository.findByIdWithOrderSheetIncludeDeleted(orderId) | ||
.orElseThrow(() -> new OrderException(ORDER_NOT_FOUND, String.valueOf(orderId))) | ||
.getOrderSheet().getOrderedProducts().stream() | ||
.map(OrderedProductResponse::from) | ||
.toList(); | ||
} | ||
|
||
private User checkUserExistence(Long userId) { | ||
return userJpaRepository.findById(userId) | ||
.orElseThrow(() -> new UserException(USER_NOT_FOUND, String.valueOf(userId))); | ||
} | ||
|
||
} |
Oops, something went wrong.