-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[14] 운송장 번호 입력 #49
Merged
ohsuha
merged 2 commits into
feature/user/18-cancle-order
from
feature/partner/14-register-shipment-code
Oct 23, 2024
Merged
[14] 운송장 번호 입력 #49
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
44 changes: 44 additions & 0 deletions
44
src/main/java/org/example/commerce_site/application/shipment/ShipmentFacade.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,44 @@ | ||
package org.example.commerce_site.application.shipment; | ||
|
||
import org.example.commerce_site.application.order.OrderDetailService; | ||
import org.example.commerce_site.application.order.OrderService; | ||
import org.example.commerce_site.application.partner.PartnerService; | ||
import org.example.commerce_site.application.product.ProductService; | ||
import org.example.commerce_site.application.shipment.dto.ShipmentRequestDto; | ||
import org.example.commerce_site.attribute.OrderStatus; | ||
import org.example.commerce_site.common.exception.CustomException; | ||
import org.example.commerce_site.common.exception.ErrorCode; | ||
import org.example.commerce_site.domain.OrderDetail; | ||
import org.example.commerce_site.domain.Partner; | ||
import org.example.commerce_site.domain.Product; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ShipmentFacade { | ||
private final OrderService orderService; | ||
private final OrderDetailService orderDetailService; | ||
private final ShipmentService shipmentService; | ||
private final PartnerService partnerService; | ||
private final ProductService productService; | ||
|
||
@Transactional | ||
public void updateTrackingCode(ShipmentRequestDto.UpdateTrackingNumber dto) { | ||
OrderDetail orderDetail = orderDetailService.getOrderDetail(dto.getOrderDetailId()); | ||
if (orderDetail.getOrder().getStatus() == OrderStatus.CANCELLED) { | ||
throw new CustomException(ErrorCode.ORDER_CAN_NOT_UPDATE_TRACK_CODE); | ||
} | ||
|
||
Product product = productService.getProduct(orderDetail.getProductId()); | ||
Partner partner = partnerService.getPartner(dto.getUserAuthId()); | ||
if (product.getPartnerId() != partner.getId()) { | ||
throw new CustomException(ErrorCode.ACCESS_DENIED); | ||
} | ||
|
||
shipmentService.updateTrackingCode(orderDetail.getId(), dto.getTrackingNumber()); | ||
orderService.updateStatus(orderDetail.getOrder(), OrderStatus.SHIPPED); | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
src/main/java/org/example/commerce_site/application/shipment/dto/ShipmentRequestDto.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,17 @@ | ||
package org.example.commerce_site.application.shipment.dto; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
|
||
public class ShipmentRequestDto { | ||
@Getter | ||
@Builder | ||
@ToString | ||
public static class UpdateTrackingNumber { | ||
private Long orderDetailId; | ||
private String userAuthId; | ||
private String trackingNumber; | ||
} | ||
|
||
} |
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
3 changes: 3 additions & 0 deletions
3
src/main/java/org/example/commerce_site/infrastructure/shipment/ShipmentRepository.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 |
---|---|---|
@@ -1,9 +1,12 @@ | ||
package org.example.commerce_site.infrastructure.shipment; | ||
|
||
import java.util.Optional; | ||
|
||
import org.example.commerce_site.domain.Shipment; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface ShipmentRepository extends JpaRepository<Shipment, Long> { | ||
Optional<Shipment> findByOrderDetailId(Long orderDetailId); | ||
} |
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
33 changes: 33 additions & 0 deletions
33
src/main/java/org/example/commerce_site/representation/shipment/ShipmentController.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,33 @@ | ||
package org.example.commerce_site.representation.shipment; | ||
|
||
import org.example.commerce_site.application.shipment.ShipmentFacade; | ||
import org.example.commerce_site.common.response.ApiSuccessResponse; | ||
import org.example.commerce_site.representation.shipment.dto.ShipmentRequest; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestAttribute; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@PreAuthorize("hasAuthority('ROLE_PARTNER')") | ||
@RequestMapping("/shipments") | ||
public class ShipmentController { | ||
private final ShipmentFacade shipmentFacade; | ||
|
||
@PutMapping("/{order_detail_id}") | ||
public ApiSuccessResponse updateShipment( | ||
@PathVariable("order_detail_id") Long orderDetailId, | ||
@RequestAttribute("userId") String userAuthId, | ||
@RequestBody ShipmentRequest.UpdateTrackingNumber request | ||
) { | ||
shipmentFacade.updateTrackingCode( | ||
ShipmentRequest.UpdateTrackingNumber.toDto(request, userAuthId, orderDetailId)); | ||
return ApiSuccessResponse.success(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/org/example/commerce_site/representation/shipment/dto/ShipmentRequest.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,25 @@ | ||
package org.example.commerce_site.representation.shipment.dto; | ||
|
||
import org.example.commerce_site.application.shipment.dto.ShipmentRequestDto; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
|
||
public class ShipmentRequest { | ||
@Getter | ||
@ToString | ||
public static class UpdateTrackingNumber { | ||
@NotNull | ||
private String trackingNumber; | ||
|
||
public static ShipmentRequestDto.UpdateTrackingNumber toDto(ShipmentRequest.UpdateTrackingNumber request, | ||
String userAuthId, Long orderDetailId) { | ||
return ShipmentRequestDto.UpdateTrackingNumber.builder() | ||
.trackingNumber(request.trackingNumber) | ||
.userAuthId(userAuthId) | ||
.orderDetailId(orderDetailId) | ||
.build(); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
camelCase와 snake_case가 섞여 있네요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
모두 snake_case 로 수정하겠습니다