Skip to content

Commit

Permalink
[feat] #225 주문 배송지 조회 api 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
yoon520 committed Feb 13, 2024
1 parent 9c95880 commit e7ec43e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/main/java/com/dmarket/controller/AdminController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.dmarket.dto.common.*;
import com.dmarket.dto.request.*;
import com.dmarket.dto.response.*;
import com.dmarket.exception.ErrorCode;
import com.dmarket.jwt.JWTUtil;
import com.dmarket.service.AdminService;
import jakarta.servlet.http.HttpServletRequest;
Expand All @@ -19,7 +18,10 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.*;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
Expand Down Expand Up @@ -379,6 +381,12 @@ public ResponseEntity<CMResDto<Map<String, Object>>> getOrdersByStatus(@RequestP
return new ResponseEntity<>(CMResDto.successDataRes(responseData), HttpStatus.OK);
}

@GetMapping("/orders/{orderId}/delivery-address")
public ResponseEntity<CMResDto<UserResDto.UserDeliveryAddress>> getDeliveryAddress(@PathVariable Long orderId){
UserResDto.UserDeliveryAddress deliveryAddress = adminService.getDeliveryAddress(orderId);
return new ResponseEntity<>(CMResDto.successDataRes(deliveryAddress), HttpStatus.OK);
}

// 배송 상태 변경
@PutMapping("/orders/{detailId}")
public ResponseEntity<CMResDto<String>> updateOrderStatus(@PathVariable Long detailId,
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/com/dmarket/dto/response/UserResDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,25 @@ public UserAddress(User user) {
}
}

@Data
@NoArgsConstructor
@AllArgsConstructor
public static class UserDeliveryAddress {
private String userName;
private String userPhoneNum;
private Integer userPostalCode;
private String userAddress;
private String userDetailedAddress;

public UserDeliveryAddress(User user){
this.userName = user.getUserName();
this.userPhoneNum = user.getUserPhoneNum();
this.userPostalCode = user.getUserPostalCode();
this.userAddress = user.getUserAddress();
this.userDetailedAddress = user.getUserAddressDetail();
}
}

@Data
@NoArgsConstructor
@AllArgsConstructor
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/com/dmarket/service/AdminService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.dmarket.domain.board.Inquiry;
import com.dmarket.domain.board.InquiryReply;
import com.dmarket.domain.board.Notice;
import com.dmarket.domain.order.Order;
import com.dmarket.domain.order.OrderDetail;
import com.dmarket.domain.order.Refund;
import com.dmarket.domain.order.Return;
Expand All @@ -20,6 +21,7 @@
import com.dmarket.dto.response.*;
import com.dmarket.exception.BadRequestException;
import com.dmarket.exception.ConflictException;
import com.dmarket.exception.ErrorCode;
import com.dmarket.exception.NotFoundException;
import com.dmarket.jwt.JWTUtil;
import com.dmarket.notification.SendNotificationEvent;
Expand Down Expand Up @@ -748,6 +750,23 @@ public void updateOrderDetailState(Long detailId, String orderStatus) {

}

// 주문 배송지 조회
public UserResDto.UserDeliveryAddress getDeliveryAddress(Long orderId){
// 주문 조회 시 없으면 예외 처리
Order order = orderRepository.findByOrderId(orderId);
if(order == null) {
throw new BadRequestException(ORDER_NOT_FOUND);
}

// 사용자 조회 시 없으면 예외처리
User user = userRepository.findByUserId(order.getUserId());
if(user == null){
throw new BadRequestException(USER_NOT_FOUND);
}

return new UserResDto.UserDeliveryAddress(user);
}

// 옵션 삭제
@Transactional
public void deleteOptionByOptionId(Long optionId) {
Expand Down

0 comments on commit e7ec43e

Please sign in to comment.