Create an API in Java using this project as a base.
The project contains a Controller/Service/Repo structure, and “TODO” comments to serve as a guide. The Repository layer is set up to use a Map of objects rather than a database, this layer does not need any changes. “Person” and “Address” are used to serve as entities, one person may have one or many addresses and an address may have one person.
-
Fill out the Person Controller and Service to accommodate the following endpoints:
- GET /person
- This endpoint should return all Person records without their Address information and ordered by last name, first name.
- POST /person
- This endpoint should allow a new Person record to be created.
- A Person is required to have a first name, last name, birthday, and main address.
- The new Person record should use the next available id.
- PUT /person
- This endpoint should allow a Person record to be updated.
- A Person may not be update to have a null/empty main address.
- A Person may not have their birthday updated.
- Update the Address record with the matching id as specified by the payload.
- Attempting to update an id that does not exist should return an error.
- DELETE /person /{id}
- This endpoint should allow a Person record to be deleted.
- Deleting a Person should delete all of their Address information as well.
- Attempting to delete an id that does not exist should return an error.
- GET /person/{id}
- This endpoint should return a single Person record with all of their Address information.
- Attempting to get an id that does not exist should return an error.
- POST /person/lastName
- This endpoint should return all Person records with a matching last name, as specified in the payload.
- GET /person
-
Fill out the Address Controller and Service to accommodate the following endpoints:
- GET /address
- This endpoint should return all Address records ordered by street1, state.
- POST /address
- This endpoint should allow a new Address record to be created.
- An Address is required to have a person Id, zip, and state.
- The new Address record should use the next available id.
- PUT /address
- This endpoint should allow an Address record to be updated.
- An Address may not be update to have a null/empty person Id.
- Update the Address record with the matching id as specified by the payload.
- Attempting to update an id that does not exist should return an error.
- DELETE /address/{id}
- This endpoint should allow an Address record to be deleted.
- An Address used as a main address should not be able to be deleted.
- Attempting to delete an id that does not exist should return an error.
- GET /address/{id}
- This endpoint should return a single Address record with the corresponding Person information.
- Attempting to get an id that does not exist should return an error.
- GET /address
-
When a piece of validation fails, then return an http status of 400 and a message stating what caused the error.
-
Add unit tests for all methods added into the Person Service and Address Service to ensure they return expected results/perform the correct actions when called.