-
Notifications
You must be signed in to change notification settings - Fork 1
[Order] - Feat: Add Patch API for update checkout entity #8
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,5 +4,5 @@ | |
|
|
||
| @ConfigurationProperties(prefix = "yas.services") | ||
| public record ServiceUrlConfig( | ||
| String cart, String customer, String product, String tax, String promotion) { | ||
| } | ||
| String cart, String customer, String product, String tax, String promotion, String payment) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing payment service URL config
Adding 'String payment' to the ServiceUrlConfig record introduces a new required configuration property. The PaymentService in the order module uses Code suggestionCheck the AI-generated fix before applying Code Review Run #f96c13 Should Bito avoid suggestions like this for future reviews? (Manage Rules)
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| import com.yas.commonlibrary.constants.ApiConstant; | ||
| import com.yas.order.service.CheckoutService; | ||
| import com.yas.order.viewmodel.ErrorVm; | ||
| import com.yas.order.viewmodel.checkout.CheckoutPatchVm; | ||
| import com.yas.order.viewmodel.checkout.CheckoutPaymentMethodPutVm; | ||
| import com.yas.order.viewmodel.checkout.CheckoutPostVm; | ||
| import com.yas.order.viewmodel.checkout.CheckoutStatusPutVm; | ||
|
|
@@ -12,9 +13,11 @@ | |
| import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
| import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
| import jakarta.validation.Valid; | ||
| import java.util.Map; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PatchMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.PutMapping; | ||
|
|
@@ -56,4 +59,18 @@ public ResponseEntity<Void> updatePaymentMethod(@PathVariable final String id, | |
| checkoutService.updateCheckoutPaymentMethod(id, checkoutPaymentMethodPutVm); | ||
| return ResponseEntity.ok().build(); | ||
| } | ||
|
|
||
| @PatchMapping("/storefront/checkouts/{id}") | ||
| @ApiResponses(value = { | ||
| @ApiResponse(responseCode = ApiConstant.CODE_200, description = ApiConstant.OK, | ||
| content = @Content()), | ||
| @ApiResponse(responseCode = ApiConstant.CODE_404, description = ApiConstant.NOT_FOUND, | ||
| content = @Content(schema = @Schema(implementation = ErrorVm.class))), | ||
| @ApiResponse(responseCode = ApiConstant.CODE_400, description = ApiConstant.BAD_REQUEST, | ||
| content = @Content(schema = @Schema(implementation = ErrorVm.class)))}) | ||
| public ResponseEntity<CheckoutVm> updateCheckout(@PathVariable final String id, | ||
| @Valid @RequestBody | ||
| CheckoutPatchVm checkoutPatchVm) { | ||
| return ResponseEntity.ok(checkoutService.updateCheckoutByFields(id, checkoutPatchVm)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing input validation for shipping address ID
The new PATCH endpoint for updating checkout fields calls Code suggestionCheck the AI-generated fix before applying Code Review Run #f96c13 Should Bito avoid suggestions like this for future reviews? (Manage Rules)
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package com.yas.order.mapper; | ||
|
|
||
| import com.yas.order.model.CheckoutAddress; | ||
| import com.yas.order.viewmodel.customer.ActiveAddressVm; | ||
| import org.mapstruct.Mapper; | ||
| import org.mapstruct.Mapping; | ||
| import org.mapstruct.MappingTarget; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Mapper(componentModel = "spring") | ||
| @Component | ||
| public interface AddressMapper { | ||
| @Mapping(target = "id", ignore = true) | ||
| CheckoutAddress toModel(ActiveAddressVm activeAddressVm); | ||
|
|
||
| ActiveAddressVm toVm(CheckoutAddress checkoutAddress); | ||
|
|
||
| @Mapping(target = "id", ignore = true) | ||
| CheckoutAddress updateModel(@MappingTarget CheckoutAddress checkoutAddress, ActiveAddressVm activeAddressVm); | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -8,10 +8,12 @@ | |||||
| import jakarta.persistence.Entity; | ||||||
| import jakarta.persistence.EnumType; | ||||||
| import jakarta.persistence.Enumerated; | ||||||
| import jakarta.persistence.FetchType; | ||||||
| import jakarta.persistence.GeneratedValue; | ||||||
| import jakarta.persistence.GenerationType; | ||||||
| import jakarta.persistence.Id; | ||||||
| import jakarta.persistence.OneToMany; | ||||||
| import jakarta.persistence.OneToOne; | ||||||
| import jakarta.persistence.Table; | ||||||
| import java.math.BigDecimal; | ||||||
| import java.util.ArrayList; | ||||||
|
|
@@ -57,12 +59,18 @@ public class Checkout extends AbstractAuditEntity { | |||||
| @SuppressWarnings("unused") | ||||||
| private String shipmentMethodId; | ||||||
|
|
||||||
| @SuppressWarnings("unused") | ||||||
| private String shipmentServiceId; | ||||||
|
|
||||||
| @Column(name = "payment_method_id") | ||||||
| private String paymentMethodId; | ||||||
|
|
||||||
| @SuppressWarnings("unused") | ||||||
| private Long shippingAddressId; | ||||||
|
|
||||||
| @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.PERSIST) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Incorrect JPA OneToOne mapping
The newly added @OnetoOne relationship to CheckoutAddress lacks the mappedBy attribute, causing both entities to attempt owning the foreign key. This invalid JPA mapping will result in a MappingException at runtime when the application tries to persist or load entities, breaking checkout functionality in Code suggestionCheck the AI-generated fix before applying
Suggested change
Code Review Run #f96c13 Should Bito avoid suggestions like this for future reviews? (Manage Rules)
|
||||||
| private CheckoutAddress checkoutAddress; | ||||||
|
|
||||||
| @SuppressWarnings("unused") | ||||||
| @JdbcTypeCode(SqlTypes.JSON) | ||||||
| @Column(name = "last_error", columnDefinition = "jsonb") | ||||||
|
|
||||||
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.
The AddressDetailVm record is missing the addressLine2 field, which is included in the data returned by the
locationService.getAddressByIdmethod. This will cause deserialization failures when the customer module receives AddressDetailVm instances from the location service that include this field. Add String addressLine2 after addressLine1 to match the expected data structure.Code suggestion
Code Review Run #f96c13
Should Bito avoid suggestions like this for future reviews? (Manage Rules)