Merge branch 'export'
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package be.simplenotes.persistance.notes
|
||||
|
||||
import be.simplenotes.domain.model.ExportedNote
|
||||
import be.simplenotes.domain.model.Note
|
||||
import be.simplenotes.domain.model.PersistedNote
|
||||
import be.simplenotes.domain.model.PersistedNoteMetadata
|
||||
@@ -167,4 +168,33 @@ internal class NoteRepositoryImpl(private val db: Database) : NoteRepository {
|
||||
(it.name eq tag) and (it.note.userId eq userId) and (it.note.deleted eq deleted)
|
||||
}
|
||||
}
|
||||
|
||||
override fun export(userId: Int): List<ExportedNote> {
|
||||
|
||||
val notes = db.notes
|
||||
.filterColumns { it.columns - it.userId }
|
||||
.filter { it.userId eq userId }
|
||||
.sortedByDescending { it.updatedAt }
|
||||
.toList()
|
||||
|
||||
if (notes.isEmpty()) return emptyList()
|
||||
|
||||
val uuids = notes.map { note -> note.uuid }
|
||||
|
||||
val tagsByUuid = db.tags
|
||||
.filterColumns { listOf(it.noteUuid, it.name) }
|
||||
.filter { it.noteUuid inList uuids }
|
||||
.groupByTo(HashMap(), { it.note.uuid }, { it.name })
|
||||
|
||||
return notes.map { note ->
|
||||
ExportedNote(
|
||||
title = note.title,
|
||||
tags = tagsByUuid[note.uuid] ?: emptyList(),
|
||||
markdown = note.markdown,
|
||||
html = note.html,
|
||||
updatedAt = note.updatedAt,
|
||||
trash = note.deleted,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user