From 8ccd7f6058a8efcde717f54de8502cf31990084f Mon Sep 17 00:00:00 2001 From: Hubert Van De Walle Date: Wed, 19 Aug 2020 00:16:00 +0200 Subject: [PATCH] Show deleted notes count --- app/src/main/kotlin/controllers/NoteController.kt | 3 ++- app/src/main/kotlin/views/NoteView.kt | 3 ++- domain/src/main/kotlin/usecases/NoteService.kt | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/controllers/NoteController.kt b/app/src/main/kotlin/controllers/NoteController.kt index d81b16d..f2a3940 100644 --- a/app/src/main/kotlin/controllers/NoteController.kt +++ b/app/src/main/kotlin/controllers/NoteController.kt @@ -48,7 +48,8 @@ class NoteController( val currentPage = request.query("page")?.toIntOrNull()?.let(::abs) ?: 1 val tag = request.query("tag") val (pages, notes) = noteService.paginatedNotes(jwtPayload.userId, currentPage, tag = tag) - return Response(OK).html(view.notes(jwtPayload, notes, currentPage, pages, tag = tag)) + val deletedCount = noteService.countDeleted(jwtPayload.userId) + return Response(OK).html(view.notes(jwtPayload, notes, currentPage, pages, deletedCount, tag = tag)) } fun note(request: Request, jwtPayload: JwtPayload): Response { diff --git a/app/src/main/kotlin/views/NoteView.kt b/app/src/main/kotlin/views/NoteView.kt index 75d5cff..c7d02a1 100644 --- a/app/src/main/kotlin/views/NoteView.kt +++ b/app/src/main/kotlin/views/NoteView.kt @@ -51,6 +51,7 @@ class NoteView(staticFileResolver: StaticFileResolver) : View(staticFileResolver notes: List, currentPage: Int, numberOfPages: Int, + numberOfDeletedNotes: Int, tag: String?, ) = renderPage(title = "Notes", jwtPayload = jwtPayload) { div("container mx-auto p-4") { @@ -60,7 +61,7 @@ class NoteView(staticFileResolver: StaticFileResolver) : View(staticFileResolver a( href = "/notes/trash", classes = "underline font-semibold" - ) { +"Trash" } + ) { +"Trash ($numberOfDeletedNotes)" } a( href = "/notes/new", classes = "ml-2 btn btn-green" diff --git a/domain/src/main/kotlin/usecases/NoteService.kt b/domain/src/main/kotlin/usecases/NoteService.kt index 937f014..196db02 100644 --- a/domain/src/main/kotlin/usecases/NoteService.kt +++ b/domain/src/main/kotlin/usecases/NoteService.kt @@ -47,6 +47,7 @@ class NoteService( fun trash(userId: Int, uuid: UUID) = noteRepository.delete(userId, uuid, permanent = false) fun restore(userId: Int, uuid: UUID) = noteRepository.restore(userId, uuid) fun delete(userId: Int, uuid: UUID) = noteRepository.delete(userId, uuid, permanent = true) + fun countDeleted(userId: Int) = noteRepository.count(userId, deleted = true) }