Skip to content

Commit

Permalink
refactor : 주문 삭제 시 조회되지 않는 기능 추가, 안 쓰는 코드 삭제, Optimize Imports
Browse files Browse the repository at this point in the history
  • Loading branch information
axhtl committed Jul 13, 2024
1 parent 5343d48 commit d235369
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 240 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.store.clothstar.member.service;

import org.store.clothstar.member.domain.Address;
import org.store.clothstar.member.dto.request.CreateAddressRequest;
import org.store.clothstar.member.dto.response.AddressResponse;
import org.store.clothstar.member.domain.Address;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.store.clothstar.member.domain.Member;
import org.store.clothstar.member.dto.request.CreateMemberRequest;
import org.store.clothstar.member.dto.request.ModifyMemberRequest;
import org.store.clothstar.member.dto.response.MemberResponse;
import org.store.clothstar.member.domain.Member;

public interface MemberService {
Page<MemberResponse> getAllMemberOffsetPaging(Pageable pageable);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
package org.store.clothstar.order.repository.order;

import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;
import org.store.clothstar.order.entity.OrderEntity;
import org.store.clothstar.order.repository.orderSeller.OrderEntityRepositoryCustom;

public interface JpaOrderRepository extends JpaRepository<OrderEntity, Long>, OrderRepository, OrderEntityRepositoryCustom {

// Slice<OrderEntity> findAllBy(Pageable pageable);
public interface JpaOrderRepository extends JpaRepository<OrderEntity, Long>, OrderRepository{

@Transactional
@Modifying
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import java.util.List;

public interface JpaOrderSellerRepository extends JpaRepository<OrderEntity, Long>, OrderEntityRepositoryCustom, OrderSellerRepository {
public interface JpaOrderSellerRepository extends JpaRepository<OrderEntity, Long>, OrderSellerRepository {

@Query("SELECT o FROM orders o WHERE o.status = 'WAITING'")
List<OrderEntity> findWaitingOrders();
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,19 @@ public OrderSellerService(
public List<OrderResponse> getWaitingOrder() {
List<OrderEntity> waitingOrders = orderSellerRepository.findWaitingOrders();

return waitingOrders.stream()
List<OrderEntity> filteredOrders = waitingOrders.stream()
.filter(orderEntity -> orderEntity.getDeletedAt() == null)
.toList();

return filteredOrders.stream()
.map(orderEntity -> {
Member member = memberService.getMemberByMemberId(orderEntity.getMemberId());
Address address = addressService.getAddressById(orderEntity.getAddressId());
OrderResponse orderResponse = OrderResponse.from(orderEntity, member, address);

List<OrderDetailEntity> orderDetails = orderEntity.getOrderDetails().stream()
.filter(orderDetailEntity -> orderDetailEntity.getDeletedAt() == null)
.collect(Collectors.toList());
.toList();
List<Long> productIds = orderDetails.stream().map(OrderDetailEntity::getProductId).collect(Collectors.toList());
List<Long> productLineIds = orderDetails.stream().map(OrderDetailEntity::getProductLineId).collect(Collectors.toList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,18 @@ public OrderResponse getOrder(Long orderId) {
OrderEntity orderEntity = orderRepository.findById(orderId)
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "주문을 찾을 수 없습니다"));

if (orderEntity.getDeletedAt() != null) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "삭제된 주문입니다.");
}

Member member = memberService.getMemberByMemberId(orderEntity.getMemberId());
Address address = addressService.getAddressById(orderEntity.getAddressId());

// 주문 Response 객체 생성
OrderResponse orderResponse = OrderResponse.from(orderEntity,member,address);

List<OrderDetailEntity> orderDetails = orderEntity.getOrderDetails().stream()
.filter(orderDetailEntity -> orderDetailEntity.getDeletedAt() == null)
.collect(Collectors.toList());
.toList();
List<Long> productIds = orderDetails.stream().map(OrderDetailEntity::getProductId).collect(Collectors.toList());
List<Long> productLineIds = orderDetails.stream().map(OrderDetailEntity::getProductLineId).collect(Collectors.toList());

Expand Down Expand Up @@ -100,7 +103,7 @@ public Page<OrderResponse> getAllOrderOffsetPaging(Pageable pageable) {

List<OrderDetailEntity> orderDetails = orderEntity.getOrderDetails().stream()
.filter(orderDetailEntity -> orderDetailEntity.getDeletedAt() == null)
.collect(Collectors.toList());
.toList();
List<Long> productIds = orderDetails.stream().map(OrderDetailEntity::getProductId).collect(Collectors.toList());
List<Long> productLineIds = orderDetails.stream().map(OrderDetailEntity::getProductLineId).collect(Collectors.toList());

Expand Down Expand Up @@ -132,7 +135,7 @@ public Slice<OrderResponse> getAllOrderSlicePaging(Pageable pageable) {

List<OrderDetailEntity> orderDetails = orderEntity.getOrderDetails().stream()
.filter(orderDetailEntity -> orderDetailEntity.getDeletedAt() == null)
.collect(Collectors.toList());
.toList();
List<Long> productIds = orderDetails.stream().map(OrderDetailEntity::getProductId).collect(Collectors.toList());
List<Long> productLineIds = orderDetails.stream().map(OrderDetailEntity::getProductLineId).collect(Collectors.toList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.store.clothstar.order.entity.OrderEntity;
import org.store.clothstar.orderDetail.entity.OrderDetailEntity;

import java.util.List;
Expand All @@ -15,6 +14,4 @@ public interface JpaOrderDetailRepository extends JpaRepository<OrderDetailEntit
@Modifying
@Query("SELECT od FROM order_detail od WHERE od.order.orderId = :orderId")
List<OrderDetailEntity> findOrderDetailListByOrderId(@Param("orderId") Long orderId);

List<OrderDetailEntity> findByOrder(OrderEntity orderEntity);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.store.clothstar.orderDetail.repository;

import org.store.clothstar.order.entity.OrderEntity;
import org.store.clothstar.orderDetail.entity.OrderDetailEntity;

import java.util.List;
Expand All @@ -12,6 +11,4 @@ public interface OrderDetailRepository {
OrderDetailEntity save(OrderDetailEntity orderdetailEntity);

List<OrderDetailEntity> findOrderDetailListByOrderId(Long orderId);

List<OrderDetailEntity> findByOrder(OrderEntity orderEntity);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.store.clothstar.order.entity.OrderEntity;
import org.store.clothstar.order.repository.order.OrderRepository;
import org.store.clothstar.order.type.Status;
import org.store.clothstar.orderDetail.dto.OrderDetailDTO;
import org.store.clothstar.orderDetail.dto.request.AddOrderDetailRequest;
import org.store.clothstar.orderDetail.dto.request.CreateOrderDetailRequest;
import org.store.clothstar.orderDetail.entity.OrderDetailEntity;
Expand All @@ -21,7 +20,6 @@
import org.store.clothstar.productLine.repository.ProductLineJPARepository;

import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.springframework.data.domain.*;
import org.springframework.data.support.PageableExecutionUtils;
import org.springframework.stereotype.Repository;
import org.store.clothstar.member.domain.QMember;
import org.store.clothstar.member.domain.QSeller;
import org.store.clothstar.product.dto.response.ProductResponse;
import org.store.clothstar.product.entity.QProductEntity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.data.domain.*;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.web.server.ResponseStatusException;
import org.store.clothstar.member.domain.Address;
import org.store.clothstar.member.domain.Member;
Expand Down

0 comments on commit d235369

Please sign in to comment.