diff --git a/src/main/kotlin/org/echo/application/in/Controller.kt b/src/main/kotlin/org/echo/application/in/Controller.kt index 706d6f9..bae6eca 100644 --- a/src/main/kotlin/org/echo/application/in/Controller.kt +++ b/src/main/kotlin/org/echo/application/in/Controller.kt @@ -1,11 +1,27 @@ package org.echo.application.`in` +import echo.org.domain.FolderParam +import echo.org.domain.MoveParam +import org.echo.domian.FolderService +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController @RestController @RequestMapping("/cloud/folder") -class FolderController ( +class FolderController( + val folderService: FolderService +) { -) {} \ No newline at end of file + @PostMapping("/save") + suspend fun saveFolder(@RequestBody param: FolderParam) { + folderService.saveFolder(param) + } + + @PostMapping("/move") + suspend fun moveFolder(@RequestBody param: MoveParam) { + folderService.moveFolder(param) + } +} \ No newline at end of file diff --git a/src/main/kotlin/org/echo/domian/BaseEntity.kt b/src/main/kotlin/org/echo/domian/BaseEntity.kt index 9396f66..223a8dd 100644 --- a/src/main/kotlin/org/echo/domian/BaseEntity.kt +++ b/src/main/kotlin/org/echo/domian/BaseEntity.kt @@ -16,12 +16,12 @@ open class BaseType( open class BaseDoc( @Id - var id: Long, - var name: String, - var authorId: Long, - var createdAt: LocalDateTime, - var updatedAt: LocalDateTime, - var filePath: String + var id: Long?, + var name: String?, + var authorId: Long?, + var createdAt: LocalDateTime?, + var updatedAt: LocalDateTime?, + var filePath: String? ) val SUCCESS: String = "操作成功" diff --git a/src/main/kotlin/org/echo/domian/Documents.kt b/src/main/kotlin/org/echo/domian/Documents.kt index 1f0cad2..04f6860 100644 --- a/src/main/kotlin/org/echo/domian/Documents.kt +++ b/src/main/kotlin/org/echo/domian/Documents.kt @@ -13,7 +13,7 @@ class Document( createdAt: LocalDateTime, updatedAt: LocalDateTime, filePath: String, - @MappedCollection(idColumn = "base_doc_id") + @MappedCollection(idColumn = "document_id") var fileType: BaseType, val fileSize: String, val title: String, diff --git a/src/main/kotlin/org/echo/domian/Folder.kt b/src/main/kotlin/org/echo/domian/Folder.kt index a76ca60..e35192f 100644 --- a/src/main/kotlin/org/echo/domian/Folder.kt +++ b/src/main/kotlin/org/echo/domian/Folder.kt @@ -5,8 +5,8 @@ import java.time.LocalDateTime data class FolderParam( - val id: Long, - val name: String, + val id: Long?, + val name: String?, val parentFolderId: Long?, val color: String?, val icon: String?, @@ -15,6 +15,13 @@ data class FolderParam( val permissions: String? ) +data class MoveParam( + val originFolderId: Long, + val targetFolderId: Long, + val documentIdList: List, + val folderIdList: List +) + fun FolderParam.toFolder(authorId: Long, filePath: String): Folder { return Folder( id = this.id, @@ -34,12 +41,12 @@ fun FolderParam.toFolder(authorId: Long, filePath: String): Folder { @Table("folder") class Folder( - id: Long, - name: String, - authorId: Long, - createdAt: LocalDateTime, - updatedAt: LocalDateTime, - filePath: String, + id: Long?, + name: String?, + authorId: Long?, + createdAt: LocalDateTime?, + updatedAt: LocalDateTime?, + filePath: String?, var parentFolderId: Long?, var color: String?, var icon: String?, @@ -89,7 +96,10 @@ interface FolderRepository { suspend fun addDocumentToFolder(folderId: Long, documentIdList: List) // Remove a document from a folder - suspend fun moveDocument(originFolderId: Long, targetFolderId: Long, documentIdList: List) + suspend fun moveDocument( + originFolderId: Long, targetFolderId: Long, documentIdList: List, + folderIdList: List + ) // Search folders by name or tags suspend fun searchFolders(query: String): List diff --git a/src/main/kotlin/org/echo/domian/Service.kt b/src/main/kotlin/org/echo/domian/Service.kt index dc3636f..f0204cf 100644 --- a/src/main/kotlin/org/echo/domian/Service.kt +++ b/src/main/kotlin/org/echo/domian/Service.kt @@ -1,9 +1,6 @@ package org.echo.domian -import echo.org.domain.FolderParam -import echo.org.domain.FolderRepository -import echo.org.domain.toFolder -import echo.org.domain.update +import echo.org.domain.* import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import org.springframework.stereotype.Service @@ -18,10 +15,12 @@ class FolderService( val (id, username, _) = currentUser withContext(Dispatchers.IO) { // 检查是否是编辑现有文件夹 - folderRepository.getFolderById(param.id)?.let { - // 更新现有文件夹 - val updatedFolder = it.update(param) - folderRepository.saveFolder(updatedFolder) + param.id?.let { + folderRepository.getFolderById(it)?.let { + // 更新现有文件夹 + val updatedFolder = it.update(param) + folderRepository.saveFolder(updatedFolder) + } } ?: run { // 获取父文件夹路径 val parentFolderPath = param.parentFolderId?.let { @@ -34,7 +33,12 @@ class FolderService( } } - suspend fun moveFolder(param: FolderParam) { - + suspend fun moveFolder(param: MoveParam) { + folderRepository.moveDocument( + param.originFolderId, + param.targetFolderId, + param.documentIdList, + param.folderIdList + ) } } \ No newline at end of file diff --git a/src/main/kotlin/org/echo/instructure/Repository.kt b/src/main/kotlin/org/echo/instructure/Repository.kt index 98d078b..3e383e1 100644 --- a/src/main/kotlin/org/echo/instructure/Repository.kt +++ b/src/main/kotlin/org/echo/instructure/Repository.kt @@ -46,7 +46,8 @@ class FolderRepositoryImpl( override suspend fun getSubfolders(folderId: Long): List? = withContext(Dispatchers.IO) { jdbcFolderRepository.findByIdOrNull(folderId) - .let { it?.let { subFolder -> jdbcFolderRepository.findByParentFolderId(subFolder.id) } } + .let { it?.let { subFolder -> subFolder.id?.let { + it1 -> jdbcFolderRepository.findByParentFolderId(it1) } } } } override suspend fun getDocumentsInFolder(folderId: Long): List = withContext(Dispatchers.IO) { @@ -64,12 +65,14 @@ class FolderRepositoryImpl( } } - override suspend fun moveDocument(originFolderId: Long, targetFolderId: Long, documentIdList: List): Unit = + override suspend fun moveDocument(originFolderId: Long, targetFolderId: Long, documentIdList: List, + folderIdList:List): Unit = withContext(Dispatchers.IO) { - val idList = documentIdList.toMutableList() + val docIdList = documentIdList.toMutableList() + val folderIds = folderIdList.toMutableList() val targetFolder = jdbcFolderRepository.findByIdOrNull(targetFolderId) targetFolder?.let { - jdbcDocumentRepository.findByIdIn(idList) + jdbcDocumentRepository.findByIdIn(docIdList) .let { it.forEach { doc -> doc.filePath = targetFolder.filePath + File.separator + doc.name @@ -77,7 +80,7 @@ class FolderRepositoryImpl( } jdbcDocumentRepository.saveAll(it) } - jdbcFolderRepository.findByIdIn(idList) + jdbcFolderRepository.findByIdIn(folderIds) .let { it.forEach { doc -> doc.filePath = targetFolder.filePath + File.separator + doc.name diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 3f488c4..a265e22 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,5 +1,5 @@ server: - port: 7891 + port: 8080 spring: application: