Skip to content

Commit

Permalink
feat: 作业作者的评论内容长度限制改为500字
Browse files Browse the repository at this point in the history
  • Loading branch information
dragove committed Sep 5, 2024
1 parent 13b1803 commit dc05f14
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/plus/maa/backend/MainApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) {
runApplication<MainApplication>(*args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
// 指定了回复对象但该对象不存在时抛出异常
Expand Down

0 comments on commit dc05f14

Please sign in to comment.