备份代码
This commit is contained in:
parent
896df778c6
commit
72ba4fb18c
|
@ -5,6 +5,7 @@ import echo.org.domain.Folder
|
||||||
import echo.org.domain.FolderRepository
|
import echo.org.domain.FolderRepository
|
||||||
import echo.org.domain.FolderVO
|
import echo.org.domain.FolderVO
|
||||||
import echo.org.instructure.DatabaseSingleton.dbQuery
|
import echo.org.instructure.DatabaseSingleton.dbQuery
|
||||||
|
import echo.org.instructure.FolderDocuments.documentId
|
||||||
import echo.org.instructure.Folders.id
|
import echo.org.instructure.Folders.id
|
||||||
import echo.org.instructure.Folders.parentFolderId
|
import echo.org.instructure.Folders.parentFolderId
|
||||||
import org.jetbrains.exposed.sql.*
|
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 {
|
class FolderRepositoryImpl : FolderRepository {
|
||||||
override suspend fun createFolder(folderVO: FolderVO): Folder = dbQuery {
|
override suspend fun createFolder(folderVO: FolderVO): Folder = dbQuery {
|
||||||
Folders.insert {
|
Folders.insert {
|
||||||
|
@ -90,12 +98,21 @@ class FolderRepositoryImpl : FolderRepository {
|
||||||
|
|
||||||
override suspend fun getSubfolders(folderId: Long): List<Folder> = dbQuery {
|
override suspend fun getSubfolders(folderId: Long): List<Folder> = dbQuery {
|
||||||
Folders.selectAll().where { parentFolderId eq folderId }
|
Folders.selectAll().where { parentFolderId eq folderId }
|
||||||
.mapNotNull { Folders.toFolder(it) }
|
.mapNotNull { Folders.toFolder(it) }
|
||||||
.toList()
|
.toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun getDocumentsInFolder(folderId: Long): List<Document> = dbQuery {
|
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 {
|
override suspend fun addDocumentToFolder(folderId: Long, documentId: Long) = dbQuery {
|
||||||
|
|
Loading…
Reference in New Issue