备份代码
This commit is contained in:
parent
72ba4fb18c
commit
d17dbeeda4
|
@ -1,15 +1,11 @@
|
|||
package echo.org
|
||||
|
||||
import echo.org.application.route.DocumentModule
|
||||
|
||||
import echo.org.instructure.AliyunOss
|
||||
import echo.org.instructure.DatabaseSingleton
|
||||
import echo.org.plugins.configureRouting
|
||||
import echo.org.plugins.configureSecurity
|
||||
import echo.org.plugins.configureSerialization
|
||||
import echo.org.plugins.configureTemplating
|
||||
import echo.org.plugins.*
|
||||
import io.ktor.server.application.*
|
||||
import org.koin.ktor.ext.inject
|
||||
import org.koin.ktor.plugin.Koin
|
||||
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
io.ktor.server.netty.EngineMain.main(args)
|
||||
|
@ -17,16 +13,13 @@ fun main(args: Array<String>) {
|
|||
}
|
||||
|
||||
fun Application.module() {
|
||||
// Initialize Koin
|
||||
install(Koin) {
|
||||
modules(DocumentModule)
|
||||
}
|
||||
AliyunOss.init()
|
||||
configureSecurity()
|
||||
configureSerialization()
|
||||
configureRouting()
|
||||
configureTemplating()
|
||||
initDatabase()
|
||||
configureKoin()
|
||||
}
|
||||
|
||||
fun Application.initDatabase() {
|
||||
|
|
|
@ -17,16 +17,10 @@ import java.net.URLEncoder
|
|||
import java.nio.charset.StandardCharsets
|
||||
import java.time.LocalDateTime
|
||||
|
||||
val DocumentModule = module {
|
||||
single<DocumentRepository> { DocumentRepositoryImpl() }
|
||||
single<FileOSS> { AliyunOssFileServiceImpl() }
|
||||
}
|
||||
|
||||
fun Route.handleDocuments() {
|
||||
|
||||
val documentRepository by inject<DocumentRepository>()
|
||||
val fileOSS by inject<FileOSS>()
|
||||
|
||||
route("/documents") {
|
||||
get("") {
|
||||
val res = documentRepository.pageQuery(DocumentQueryParam())
|
||||
|
|
|
@ -50,10 +50,10 @@ interface FolderRepository {
|
|||
suspend fun getDocumentsInFolder(folderId: Long): List<Document>
|
||||
|
||||
// Add a document to a folder
|
||||
suspend fun addDocumentToFolder(folderId: Long, documentId: Long)
|
||||
suspend fun addDocumentToFolder(folderId: Long, documentIdList: List<Long>)
|
||||
|
||||
// Remove a document from a folder
|
||||
suspend fun removeDocumentFromFolder(folderId: Long, documentId: Long)
|
||||
suspend fun removeDocumentFromFolder(folderId: Long, documentIdList: List<Long>)
|
||||
|
||||
// Search folders by name or tags
|
||||
suspend fun searchFolders(query: String): List<Folder>
|
||||
|
|
|
@ -10,6 +10,7 @@ import echo.org.instructure.Folders.id
|
|||
import echo.org.instructure.Folders.parentFolderId
|
||||
import org.jetbrains.exposed.sql.*
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.inList
|
||||
import org.jetbrains.exposed.sql.javatime.CurrentDateTime
|
||||
import org.jetbrains.exposed.sql.javatime.datetime
|
||||
import java.time.LocalDateTime
|
||||
|
@ -115,12 +116,18 @@ class FolderRepositoryImpl : FolderRepository {
|
|||
}
|
||||
}
|
||||
|
||||
override suspend fun addDocumentToFolder(folderId: Long, documentId: Long) = dbQuery {
|
||||
TODO("Not yet implemented")
|
||||
override suspend fun addDocumentToFolder(folderId: Long, documentIdList: List<Long>): Unit = dbQuery {
|
||||
FolderDocuments.batchInsert(documentIdList) {
|
||||
this[FolderDocuments.folderId] = folderId
|
||||
this[documentId] = documentId
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun removeDocumentFromFolder(folderId: Long, documentId: Long) = dbQuery {
|
||||
TODO("Not yet implemented")
|
||||
override suspend fun removeDocumentFromFolder(folderId: Long, documentIdList: List<Long>): Unit = dbQuery {
|
||||
FolderDocuments.deleteWhere {
|
||||
(FolderDocuments.folderId eq folderId) and
|
||||
(documentId inList documentIdList)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun searchFolders(query: String): List<Folder> = dbQuery {
|
||||
|
@ -128,5 +135,4 @@ class FolderRepositoryImpl : FolderRepository {
|
|||
(Folders.name like "%$query%") or (Folders.tags like "%$query%")
|
||||
}.map { Folders.toFolder(it) }
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package echo.org.plugins
|
||||
|
||||
import echo.org.application.route.handleDocuments
|
||||
import echo.org.domain.DocumentRepository
|
||||
import echo.org.domain.FileOSS
|
||||
import echo.org.instructure.AliyunOssFileServiceImpl
|
||||
import echo.org.instructure.DocumentRepositoryImpl
|
||||
import io.ktor.server.application.*
|
||||
import io.ktor.server.http.content.*
|
||||
import io.ktor.server.routing.*
|
||||
import org.koin.dsl.module
|
||||
import org.koin.ktor.plugin.Koin
|
||||
|
||||
|
||||
val DocumentModule = module {
|
||||
single<DocumentRepository> { DocumentRepositoryImpl() }
|
||||
single<FileOSS> { AliyunOssFileServiceImpl() }
|
||||
|
||||
}
|
||||
|
||||
|
||||
fun Application.configureKoin() {
|
||||
// Initialize Koin
|
||||
install(Koin) {
|
||||
modules(DocumentModule)
|
||||
}
|
||||
}
|
|
@ -1,17 +1,12 @@
|
|||
package echo.org
|
||||
|
||||
import echo.org.application.route.DocumentModule
|
||||
import echo.org.instructure.Documents
|
||||
|
||||
import echo.org.plugins.*
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.client.statement.*
|
||||
import io.ktor.http.*
|
||||
import io.ktor.server.application.*
|
||||
|
||||
import io.ktor.server.testing.*
|
||||
import org.jetbrains.exposed.sql.SchemaUtils
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import org.koin.dsl.module
|
||||
import org.koin.ktor.plugin.Koin
|
||||
import kotlin.test.*
|
||||
|
||||
class ApplicationTest {
|
||||
|
|
Loading…
Reference in New Issue