Add input validation to REST API request DTOs#206
Open
devin-ai-integration[bot] wants to merge 2 commits intomasterfrom
Open
Add input validation to REST API request DTOs#206devin-ai-integration[bot] wants to merge 2 commits intomasterfrom
devin-ai-integration[bot] wants to merge 2 commits intomasterfrom
Conversation
- Add javax.validation annotations to all request DTOs: - CreateOrderRequest: @positive on IDs, @NotEmpty/@Valid on lineItems - CreateOrderRequest.LineItem: @notblank on menuItemId, @min(1) on quantity - ReviseOrderRequest: @notempty on revisedLineItemQuantities - OrderAcceptance: @NotNull/@FutureOrPresent on readyBy - CreateConsumerRequest: @NotNull/@Valid on name - CreateRestaurantRequest: @notblank on name, @NotNull/@Valid on menu/address - CreateCourierRequest: @NotNull/@Valid on name/address - CourierLocationUpdate: @DecimalMin/@DecimalMax for lat/lng ranges - Add validation to shared DTOs: - PersonName: @notblank on firstName/lastName - Address: @notblank on street1/city/state/zip - RestaurantMenuDTO: @NotEmpty/@Valid on menuItems - MenuItemDTO: @notblank on id/name, @NotNull on price - Add @Valid to all controller @RequestBody parameters - Add MethodArgumentNotValidException handler in GlobalExceptionHandler - Add hibernate-validator dependency to ftgo-common Co-Authored-By: Wes Convery <2wconvery@gmail.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
Co-Authored-By: Wes Convery <2wconvery@gmail.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds
javax.validationannotations to all REST API request DTOs and enables validation enforcement via@Validon controller@RequestBodyparameters. Invalid requests now return a structured400 Bad Requestresponse with field-level error details.Changes
Request DTOs validated:
CreateOrderRequest—@PositiveonconsumerId/restaurantId,@NotEmpty/@ValidonlineItemsCreateOrderRequest.LineItem—@NotBlankonmenuItemId,@Min(1)onquantityReviseOrderRequest—@NotEmptyonrevisedLineItemQuantitiesOrderAcceptance—@NotNull/@FutureOrPresentonreadyByCreateConsumerRequest—@NotNull/@ValidonnameCreateRestaurantRequest—@NotBlankonname,@NotNull/@Validonmenu/addressCreateCourierRequest—@NotNull/@Validonname/addressCourierLocationUpdate—@DecimalMin/@DecimalMaxfor lat (-90..90) and lng (-180..180)Shared DTOs validated (cascading via
@Valid):PersonName—@NotBlankonfirstName/lastNameAddress—@NotBlankonstreet1/city/state/zipRestaurantMenuDTO—@NotEmpty/@ValidonmenuItemsMenuItemDTO—@NotBlankonid/name,@NotNullonpriceControllers updated with
@Valid:OrderController—create,revise,acceptConsumerController—createRestaurantController—createCourierController—create,updateCourierLocation,updateLocationError handling:
MethodArgumentNotValidExceptionhandler toGlobalExceptionHandlerreturning400with field-level validation error messagesDependency:
hibernate-validator:6.2.5.Finaltoftgo-common/build.gradleReview & Testing Checklist for Human
/orderswith empty body)CreateRestaurantRequest→Address→street1blank triggers error)Notes
OrderControllerTestdue to Mockito/JDK 21 incompatibility (project targets Java 8 but env runs JDK 21) — not introduced by this PRCourierAvailabilitywas intentionally left without validation sinceboolean availabledefaults tofalsewhich is a valid stateLink to Devin session: https://app.devin.ai/sessions/8dc58d00626f43a1a3281cd5d02372ca
Requested by: @WesternConcrete
Devin Review