Use Case:
- let's design a RESTful create operation using POST HTTP verb - creating tickets where creator (assigner) specifies a ticket assignee
- we're creating a new "ticket" on following location:
/companyId/userId/ticket
we're providing ticket body containing
assigneeId
:{ "assigneeId": 10 }
we need to validate that
assigneeId
belongs to company in URL -companyId
path variable
So far:
@RequestMapping(value="/{companyId}/{userId}/ticket", method=POST)
public void createTicket(@Valid @RequestBody Ticket newTicket, @PathVariable Long companyId, @PathVariable Long userId) {
...
}
- we can easily specify a custom Validator (
TicketValidator
) (even with dependencies) and validateTicket
instance - we can't easily pass
companyId
to this validator though! We need to verify thatticket.assigneeId
belongs to company withcompanyId
.
Desired output:
- ability to access path variables in custom Validators
Any ideas how do I achieve the desired output here?
Ticket
hasassigneeId
property and we need to ask database whetherassigneeId
belongs to a company withcompanyId
. So we need bothTicket
andcompanyId
. Makes sense? – Weldonwelfare