SchoolOfCode / bc17-w4d2-project-i-need-a-rest

bootcamp-17-bc17-w4d2-project-empty-repo created by GitHub Classroom
0 stars 0 forks source link

User Story 6: Implement functionality to DELETE an activity #6

Closed DonHamsa closed 1 month ago

DonHamsa commented 1 month ago

Description:

As Kenny, a busy front end engineer I need to be able to send a DELETE request with an activity_id to the API so that I can allow my users to delete their activities.

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 DELETE request to “http://localhost:3000/activities/activity_id_here” Then the API should delete the activity that has a matching activity id in the activities.json file, Then the request should succeed, responding with the correct status code and the deleted activity object in the response body (response.data).

Given I am a developer who has made an invalid DELETE request by specifying an id for a activity that does not exist, When I inspect the API response, Then the the API call should fail with the correct response code and a clear error message (response.error).

### Tasks for User Story 6
- [x] Define a DELETE route at `/activities/:id`
- [x] Extract the `id` from the request parameters.
- [x] Check if the `id` exists in `activities.json`.
- [x] If the `id` does not exist, respond with 400 and an error message.
- [x] If the `id` exists, remove the corresponding activity from `activities.json`.
- [x] Respond with the correct status code (e.g., 200 OK).
- [x] Include the deleted activity object in the response body.
- [x] Test if all User Story criteria is met!
faisalagood commented 1 month ago

Done