Find notes by tags in notes list

This commit is contained in:
2020-08-17 17:09:48 +02:00
parent 8021814c31
commit 5295e32d86
5 changed files with 28 additions and 13 deletions
@@ -29,11 +29,11 @@ class NoteService(
.map { Note(it.metadata, markdown = markdownText, html = it.html) }
.map { noteRepository.update(userId, uuid, it) }
fun paginatedNotes(userId: Int, page: Int, itemsPerPage: Int = 20): PaginatedNotes {
val count = noteRepository.count(userId)
fun paginatedNotes(userId: Int, page: Int, itemsPerPage: Int = 20, tag: String? = null): PaginatedNotes {
val count = noteRepository.count(userId, tag)
val offset = (page - 1) * itemsPerPage
val numberOfPages = (count / itemsPerPage) + 1
val notes = if (count == 0) emptyList() else noteRepository.findAll(userId, itemsPerPage, offset)
val notes = if (count == 0) emptyList() else noteRepository.findAll(userId, itemsPerPage, offset, tag)
return PaginatedNotes(numberOfPages, notes)
}