Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/main/java/codes/yam/contacts/ContactController.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ public String validateEmail(@PathVariable String slug, @RequestParam String emai
return "";
}

@GetMapping("/count")
@ResponseBody
public String count() {
return "(%d total Contacts)".formatted(contactService.count());
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

@ExceptionHandler(ContactNotFoundException.class)
@ResponseStatus(HttpStatus.NOT_FOUND)
public String handleNotFound(ContactNotFoundException ex, Model model) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/codes/yam/contacts/ContactService.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public Contact update(String slug, Contact updated) {
return contactRepository.save(contact);
}

public long count() {
return contactRepository.count();
}

private String generateSlug(Contact contact) {
return (contact.getFirst().toLowerCase() + "-" + contact.getLast().toLowerCase())
.replaceAll("[^a-z0-9-]", "");
Expand Down
Loading