We've now finished Create and Read and are ready to add Update and Delete.
This sprint we will:
- Add a button to delete an album.
Note: as we go through this if you get stuck make use of the hints, your neighbors and the solutions.
You must complete all of the previous sprint before starting this sprint. (excludes stretch challenges) If you have not done so, see below:
If you have not completed sprints 1-3 yet, it is strongly advised that you save your work and checkout the solution branch (3) to get started.
-
First git add and commit any current changes.
-
Then checkout the solutions branch:
git checkout solutions_sprint_3
- Then create a new branch from this:
git checkout -b sprint4
Once again let's start on the front-end and add a button to delete an album.
-
Add another button to the
panel-footer
. -
Use jQuery to catch the
click
event for the button. -
In your
click
event determine the album-id of the current album. Justconsole.log
it for now.
Let's add a route for DELETE /api/albums/:id
to our server.
- Add the new route on the server side. It should return just a 200 or 204 status code.
HTTP DELETE often doesn't have a defined body.
-
Test it with curl or postman.
-
Connect it to the database and delete the specified album.
Now you can tie the previous front-end and back-end changes together.
- When a user clicks the delete button, send a DELETE request to the server and remove the album from the page.
Note jQuery doesn't have a
$.delete
method. Use$.ajax
-
Remove the deleted albums from the page.
-
Refresh the page and make sure they are truly being deleted.
If you run out of things to delete, try re-seeding your database.
- Prompt the user with an alert "Are you sure?" when they click delete.
- for a superior look and feel, use a bootstrap modal for this prompt
- Add an animation for album deletion.