Skip to content

Commit

Permalink
Merge pull request #91 from ClothingStoreService/refactor/order-inque…
Browse files Browse the repository at this point in the history
…ry-in-service

refactor : 서비스 로직을 이용하여 주문 조회 구현
  • Loading branch information
axhtl authored Jul 13, 2024
2 parents 7c02a0a + d235369 commit f5c0e31
Show file tree
Hide file tree
Showing 36 changed files with 565 additions and 440 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.store.clothstar.category.service.CategoryService;
import org.store.clothstar.common.dto.MessageDTO;
import org.store.clothstar.common.util.URIBuilder;
import org.store.clothstar.productLine.dto.response.ProductLineResponse;
import org.store.clothstar.productLine.dto.response.ProductLineWithProductsJPAResponse;
import org.store.clothstar.productLine.service.ProductLineService;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.store.clothstar.member.application;

import org.springframework.stereotype.Service;
import org.store.clothstar.member.dto.request.CreateSellerRequest;
import org.store.clothstar.member.domain.Seller;
import org.store.clothstar.member.dto.request.CreateSellerRequest;
import org.store.clothstar.member.service.SellerService;

@Service
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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;

Expand All @@ -10,4 +11,6 @@ public interface AddressService {
List<AddressResponse> findMemberAllAddress(Long memberId);

Long addrSave(Long memberId, CreateAddressRequest createAddressRequest);

Address getAddressById(Long addressId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.web.server.ResponseStatusException;
import org.store.clothstar.common.error.ErrorCode;
import org.store.clothstar.common.error.exception.NotFoundMemberException;
import org.store.clothstar.member.domain.Address;
Expand Down Expand Up @@ -41,4 +43,10 @@ public Long addrSave(Long memberId, CreateAddressRequest createAddressRequest) {

return address.getAddressId();
}

@Override
public Address getAddressById(Long addressId) {
return addressRepository.findById(addressId)
.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "배송지 정보를 찾을 수 없습니다."));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;
Expand All @@ -25,4 +26,6 @@ public interface MemberService {
Long signUp(CreateMemberRequest createMemberDTO);

void signupCertifyNumEmailSend(String email);

Member getMemberByMemberId(Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ public void signupCertifyNumEmailSend(String email) {
log.info("인증번호 전송 완료, email = {}", email);
}

@Override
public Member getMemberByMemberId(Long memberId) {
return memberRepository.findById(memberId)
.orElseThrow(() -> new NotFoundMemberException(ErrorCode.NOT_FOUND_MEMBER));
}

private String sendEmailAuthentication(String toEmail) {
String certifyNum = redisUtil.createdCertifyNum();
String message = mailContentBuilder.build(certifyNum);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.store.clothstar.member.service;

import org.store.clothstar.member.dto.request.CreateSellerRequest;
import org.store.clothstar.member.domain.Seller;
import org.store.clothstar.member.dto.request.CreateSellerRequest;

public interface SellerService {
Seller getSellerById(Long memberId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.springframework.web.bind.annotation.*;
import org.store.clothstar.common.dto.MessageDTO;
import org.store.clothstar.order.dto.reponse.OrderResponse;
import org.store.clothstar.order.entity.OrderEntity;
import org.store.clothstar.order.service.OrderSellerService;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,22 @@ public OrderResponse(OrderEntity orderEntity,
this.orderDetailList = new ArrayList<>();
}

public static OrderResponse from(OrderEntity orderEntity) {
public static OrderResponse from(OrderEntity orderEntity, Member member, Address address) {
return OrderResponse.builder()
.orderId(orderEntity.getOrderId())
.ordererName(orderEntity.getMember().getName())
.ordererName(member.getName())
.createdAt(orderEntity.getCreatedAt().toLocalDate())
.status(orderEntity.getStatus())
.totalShippingPrice(orderEntity.getTotalShippingPrice())
.totalProductsPrice(orderEntity.getTotalProductsPrice())
.paymentMethod(orderEntity.getPaymentMethod())
.totalPaymentPrice(orderEntity.getTotalPaymentPrice())
.address(AddressDTO.builder()
.receiverName(orderEntity.getAddress().getReceiverName())
.addressBasic(orderEntity.getAddress().getAddressInfo().getAddressBasic())
.addressDetail(orderEntity.getAddress().getAddressInfo().getAddressDetail())
.telNo(orderEntity.getAddress().getTelNo())
.deliveryRequest(orderEntity.getAddress().getAddressInfo().getDeliveryRequest())
.receiverName(address.getReceiverName())
.addressBasic(address.getAddressInfo().getAddressBasic())
.addressDetail(address.getAddressInfo().getAddressDetail())
.telNo(address.getTelNo())
.deliveryRequest(address.getAddressInfo().getDeliveryRequest())
.build())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import org.store.clothstar.order.type.Status;
import org.store.clothstar.order.utils.GenerateOrderId;

import java.time.LocalDateTime;

@Getter
@Builder
@NoArgsConstructor
Expand All @@ -38,8 +36,8 @@ public class CreateOrderRequest {
public OrderEntity toOrderEntity(Member member, Address address) {
return OrderEntity.builder()
.orderId(GenerateOrderId.generateOrderId())
.member(member)
.address(address)
.memberId(member.getMemberId())
.addressId(address.getAddressId())
.status(Status.WAITING)
.totalShippingPrice(3000)
.totalProductsPrice(0)
Expand Down
12 changes: 4 additions & 8 deletions src/main/java/org/store/clothstar/order/entity/OrderEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.store.clothstar.common.entity.BaseEntity;
import org.store.clothstar.member.domain.Address;
import org.store.clothstar.member.domain.Member;
import org.store.clothstar.order.type.PaymentMethod;
import org.store.clothstar.order.type.Status;
import org.store.clothstar.orderDetail.entity.OrderDetailEntity;
Expand Down Expand Up @@ -43,13 +41,11 @@ public class OrderEntity extends BaseEntity {
@Column(name = "total_payment_price")
private int totalPaymentPrice;

@ManyToOne
@JoinColumn(name = "member_id")
private Member member;
@Column(name = "member_id")
private Long memberId;

@OneToOne
@JoinColumn(name = "address_id")
private Address address;
@Column(name = "address_id")
private Long addressId;

public void updatePrices(int totalProductsPrice, int totalPaymentPrice) {
this.totalProductsPrice = totalProductsPrice;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package org.store.clothstar.order.repository.order;

import org.springframework.data.domain.Page;
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 {
public interface JpaOrderRepository extends JpaRepository<OrderEntity, Long>, OrderRepository{

@Transactional
@Modifying
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,19 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.store.clothstar.order.dto.reponse.OrderResponse;
import org.store.clothstar.order.entity.OrderEntity;

import java.util.List;
import java.util.Optional;

public interface OrderRepository {

Optional<OrderEntity> findById(Long orderId);

OrderResponse findOrderWithDetails(Long orderId);

Page<OrderResponse> findAllOffsetPaging(Pageable pageable);

Slice<OrderResponse> findAllSlicePaging(Pageable pageable);

OrderEntity save(OrderEntity orderEntity);

void deliveredToConfirmOrder(Long orderId);

Page<OrderEntity> findAll(Pageable pageable);

Slice<OrderEntity> findAllBy(Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
import org.springframework.transaction.annotation.Transactional;
import org.store.clothstar.order.entity.OrderEntity;

public interface JpaOrderSellerRepository extends JpaRepository<OrderEntity, Long>, OrderEntityRepositoryCustom, OrderSellerRepository {
import java.util.List;

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

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

@Transactional
@Modifying
Expand Down

This file was deleted.

Loading

0 comments on commit f5c0e31

Please sign in to comment.