We're creating a new API to add new Jobs into a legacy system. The question deals with how to handle creating a Job's required parent entities when you don't know the IDs of those parent entities to assign to. The structure of when a Job is created is as such:
- A Job must be assigned to a Project.
- A Project must be assigned to a CustomerAccount.
- There is no knowledge of what the ID is of the Project it should be assigned to. This goes by the Project Name instead.
- Additionally, two CustomerAccounts could have the same Project Name. For that reason, we also need to pass over the Name of the CustomerAccount.
To summarize, we need to create a new Job while also passing over the Project Name and CustomerAccount Name since we don't have access to the IDs to use. If the Project is not found, one is automatically created then assigned to the Job about to be created.
With this established, the question is: What is the best practice for implementing a REST endpoint that will also create required parent entities?
Our current solution is:
(with the Body containing the JobDTO).
In this scenario, what are some alternative solutions or better ideas for the naming of this endpoint?
Thanks in advance.