添加禁言逻辑

This commit is contained in:
柏码の讲师 2025-01-03 00:53:14 +08:00
parent 14587dceaa
commit f5941c8570

View File

@ -1,11 +1,13 @@
package com.example.controller;
import com.example.entity.RestBean;
import com.example.entity.dto.Account;
import com.example.entity.dto.Interact;
import com.example.entity.vo.request.AddCommentVO;
import com.example.entity.vo.request.TopicCreateVO;
import com.example.entity.vo.request.TopicUpdateVO;
import com.example.entity.vo.response.*;
import com.example.service.AccountService;
import com.example.service.TopicService;
import com.example.service.WeatherService;
import com.example.utils.Const;
@ -29,6 +31,9 @@ public class ForumController {
@Resource
TopicService topicService;
@Resource
AccountService accountService;
@Resource
ControllerUtils utils;
@ -51,6 +56,10 @@ public class ForumController {
@PostMapping("/create-topic")
public RestBean<Void> createTopic(@Valid @RequestBody TopicCreateVO vo,
@RequestAttribute(Const.ATTR_USER_ID) int id) {
Account account = accountService.findAccountById(id);
if (account.isMute()) {
return RestBean.forbidden("您已被禁言,无法创建新的主题");
}
return utils.messageHandle(() -> topicService.createTopic(id, vo));
}
@ -94,6 +103,10 @@ public class ForumController {
@PostMapping("/add-comment")
public RestBean<Void> addComment(@Valid @RequestBody AddCommentVO vo,
@RequestAttribute(Const.ATTR_USER_ID) int id){
Account account = accountService.findAccountById(id);
if (account.isMute()) {
return RestBean.forbidden("您已被禁言,无法创建新的回复");
}
return utils.messageHandle(() -> topicService.createComment(id, vo));
}