From dc05f14cf0411b599c789ff4c7409db0abe97f77 Mon Sep 17 00:00:00 2001 From: dragove Date: Fri, 6 Sep 2024 00:37:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BD=9C=E4=B8=9A=E4=BD=9C=E8=80=85?= =?UTF-8?q?=E7=9A=84=E8=AF=84=E8=AE=BA=E5=86=85=E5=AE=B9=E9=95=BF=E5=BA=A6?= =?UTF-8?q?=E9=99=90=E5=88=B6=E6=94=B9=E4=B8=BA500=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/plus/maa/backend/MainApplication.kt | 2 +- .../maa/backend/controller/request/comments/CommentsAddDTO.kt | 4 +++- .../kotlin/plus/maa/backend/service/CommentsAreaService.kt | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/plus/maa/backend/MainApplication.kt b/src/main/kotlin/plus/maa/backend/MainApplication.kt index 4c5d416b..5fce564b 100644 --- a/src/main/kotlin/plus/maa/backend/MainApplication.kt +++ b/src/main/kotlin/plus/maa/backend/MainApplication.kt @@ -14,7 +14,7 @@ import org.springframework.security.config.annotation.method.configuration.Enabl @SpringBootApplication @ConfigurationPropertiesScan @EnableMethodSecurity -class MainApplication +open class MainApplication fun main(args: Array) { runApplication(*args) diff --git a/src/main/kotlin/plus/maa/backend/controller/request/comments/CommentsAddDTO.kt b/src/main/kotlin/plus/maa/backend/controller/request/comments/CommentsAddDTO.kt index 01354209..97e62b21 100644 --- a/src/main/kotlin/plus/maa/backend/controller/request/comments/CommentsAddDTO.kt +++ b/src/main/kotlin/plus/maa/backend/controller/request/comments/CommentsAddDTO.kt @@ -10,8 +10,10 @@ import org.hibernate.validator.constraints.Length data class CommentsAddDTO( /** * 评论内容 + * 500字长度为对作者的限制,对于非作者限制为150字 + * 在业务层中实现 */ - @field:Length(min = 1, max = 150, message = "评论内容不可超过150字,请删减") + @field:Length(min = 1, max = 500, message = "评论内容不可超过500字,请删减") @field:NotBlank(message = "请填写评论内容") val message: String, /** diff --git a/src/main/kotlin/plus/maa/backend/service/CommentsAreaService.kt b/src/main/kotlin/plus/maa/backend/service/CommentsAreaService.kt index 51577c26..7aa30634 100644 --- a/src/main/kotlin/plus/maa/backend/service/CommentsAreaService.kt +++ b/src/main/kotlin/plus/maa/backend/service/CommentsAreaService.kt @@ -52,6 +52,9 @@ class CommentsAreaService( sensitiveWordService.validate(commentsAddDTO.message) val copilotId = commentsAddDTO.copilotId val copilot = copilotRepository.findByCopilotId(copilotId).requireNotNull { "作业不存在" } + if (userId != copilot.uploaderId) { + require(commentsAddDTO.message.length <= 150) { "评论内容不可超过150字,请删减" } + } val parentCommentId = commentsAddDTO.fromCommentId?.ifBlank { null } // 指定了回复对象但该对象不存在时抛出异常