Skip to content

Commit

Permalink
Digits-delete WOD
Browse files Browse the repository at this point in the history
  • Loading branch information
aghalarp committed Oct 16, 2013
1 parent e0a7a9f commit 9203568
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
11 changes: 11 additions & 0 deletions app/controllers/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,15 @@ public static Result postContact() {
}

}

/**
* Deletes corresponding ID from ContactDB.
* @param id The id to delete.
* @return Index page.
*/
public static Result deleteContact(long id) {
ContactDB.deleteContact(id);

return ok(Index.render(ContactDB.getContacts()));
}
}
15 changes: 15 additions & 0 deletions app/models/ContactDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,19 @@ public static Contact getContact(long id) {
}
}

/**
* Deletes a specified id from the contacts Map.
* @param id The ID to delete.
*/
public static void deleteContact(long id) {
Contact contact = contacts.get(id);

if (contact == null) {
throw new RuntimeException("Passed a bogus id: " + id);
}
else {
contacts.remove(id);
}
}

}
3 changes: 2 additions & 1 deletion app/views/Index.scala.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ <h1>Current Contacts</h1>
<td>@contact.getFirstName()</td>
<td>@contact.getLastName()</td>
<td>@contact.getTelephone()</td>
<td><a href="@routes.Application.newContact(contact.getId())">Edit</a></td>
<td><a class="btn btn-warning btn-xs" href="@routes.Application.newContact(contact.getId())">Edit</a></td>
<td><a class="btn btn-danger btn-xs" href="@routes.Application.deleteContact(contact.getId())">Delete</a></td>
</tr>
}

Expand Down
1 change: 1 addition & 0 deletions conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
GET / controllers.Application.index()
GET /newcontact controllers.Application.newContact(id: Long ?= 0)
POST /newcontact controllers.Application.postContact()
GET /delete controllers.Application.deleteContact(id: Long)

# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.at(path="/public", file)

0 comments on commit 9203568

Please sign in to comment.