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
@@ -132,5 +132,9 @@ internal class NoteRepositoryImpl(private val db: Database) : NoteRepository {
.mapColumns(isDistinct = true) { it.name } as List<String>
}
override fun count(userId: Int) = db.notes.count { it.userId eq userId }
override fun count(userId: Int, tag: String?): Int {
if (tag == null) return db.notes.count { it.userId eq userId }
return db.sequenceOf(Tags)
.count { it.name eq tag and (it.note.userId eq userId) }
}
}