备份代码

This commit is contained in:
lulz1 2024-05-21 17:01:34 +08:00
parent 896df778c6
commit 72ba4fb18c
1 changed files with 19 additions and 2 deletions

View File

@ -5,6 +5,7 @@ import echo.org.domain.Folder
import echo.org.domain.FolderRepository
import echo.org.domain.FolderVO
import echo.org.instructure.DatabaseSingleton.dbQuery
import echo.org.instructure.FolderDocuments.documentId
import echo.org.instructure.Folders.id
import echo.org.instructure.Folders.parentFolderId
import org.jetbrains.exposed.sql.*
@ -45,6 +46,13 @@ object Folders : Table() {
}
}
object FolderDocuments : Table() {
val folderId = long("folder_id").references(Folders.id, onDelete = ReferenceOption.CASCADE)
val documentId = long("document_id").references(Documents.id, onDelete = ReferenceOption.CASCADE)
override val primaryKey = PrimaryKey(folderId, documentId)
}
class FolderRepositoryImpl : FolderRepository {
override suspend fun createFolder(folderVO: FolderVO): Folder = dbQuery {
Folders.insert {
@ -90,12 +98,21 @@ class FolderRepositoryImpl : FolderRepository {
override suspend fun getSubfolders(folderId: Long): List<Folder> = dbQuery {
Folders.selectAll().where { parentFolderId eq folderId }
.mapNotNull { Folders.toFolder(it) }
.mapNotNull { Folders.toFolder(it) }
.toList()
}
override suspend fun getDocumentsInFolder(folderId: Long): List<Document> = dbQuery {
TODO("Not yet implemented")
val toList = FolderDocuments.selectAll().where {
FolderDocuments.folderId eq folderId
}.map {
it[documentId]
}.toList()
Documents.selectAll().where {
Documents.id inList toList
}.map {
Documents.toDocument(it)
}
}
override suspend fun addDocumentToFolder(folderId: Long, documentId: Long) = dbQuery {