As Kenny, a busy front end engineer I need to be able to send a PUT request with a JSON request body (the activity to update) to the API so that I can make a simple form that allows my user to edit an activity.
As Norman, a Tech Lead working across lots of projects I need to be able to depend on conventions like: the response object always containing a key called data or error, or the status code being an accurate indication of the success/failure (and reason) of the request.
Acceptance Criteria:
Given I am a developer who has the Activity API running,
When I make a PUT request to “http://localhost:3000/activities” with a request body containing a JSON object (updated activity),
Then the API should update the activity in the activities.json file that has a matching activity id,
Then the the request should succeed, responding with the correct status code and the activity object that I posted as the response body (response.data).
Given I am a developer who has made an invalid PUT request by specifying an id for a activity that does not exist,
When I inspect the API response,
Then the request should fail, responding with the correct status code and a clear error message (response.error).
### Tasks for User Story 5
- [x] Set up PUT endpoint for /activities in the API
- [x] Parse JSON request body to retrieve updated activity data.
- [x] Validate activity ID exists in activities.json
- [x] If exists, update the activity.
- [x] If not, return an error.
- [x] Correct status code (e.g., 200 for success, 404 for not found).
- [x] Response object containing data or error.
- [x] Test everything to make sure criteria is met
Description:
As Kenny, a busy front end engineer I need to be able to send a PUT request with a JSON request body (the activity to update) to the API so that I can make a simple form that allows my user to edit an activity.
As Norman, a Tech Lead working across lots of projects I need to be able to depend on conventions like: the response object always containing a key called data or error, or the status code being an accurate indication of the success/failure (and reason) of the request.
Acceptance Criteria:
Given I am a developer who has the Activity API running, When I make a PUT request to “http://localhost:3000/activities” with a request body containing a JSON object (updated activity), Then the API should update the activity in the activities.json file that has a matching activity id, Then the the request should succeed, responding with the correct status code and the activity object that I posted as the response body (response.data).
Given I am a developer who has made an invalid PUT request by specifying an id for a activity that does not exist, When I inspect the API response, Then the request should fail, responding with the correct status code and a clear error message (response.error).