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
assigneeIdbelongs to company in URL -companyIdpath 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 validateTicketinstance - we can't easily pass
companyIdto this validator though! We need to verify thatticket.assigneeIdbelongs to company withcompanyId.
Desired output:
- ability to access path variables in custom Validators
Any ideas how do I achieve the desired output here?
TickethasassigneeIdproperty and we need to ask database whetherassigneeIdbelongs to a company withcompanyId. So we need bothTicketandcompanyId. Makes sense?