Commit 94e94277 by 胡明森

添加删除消息接口

parent d8563272
......@@ -64,7 +64,7 @@ public class MessageApi {
return Response.success(messagePageDTO);
}
@ApiOperation("消息详情")
@ApiOperation("删除消息")
@GetMapping("/message/{messageId}")
public Response getTopic(@PathVariable("messageId") String messageId) {
try {
......@@ -77,5 +77,29 @@ public class MessageApi {
}
@ApiOperation("删除所有消息")
@DeleteMapping("/message")
public Response delAllMessage(@CurrentSubject Subject subject) {
messageService.deleteAllMessage((String) subject.getId());
return Response.success();
}
@ApiOperation("删除消息")
@DeleteMapping("/message/{messageId}")
public Response delMessage(@PathVariable("messageId") String messageId, @CurrentSubject Subject subject) {
try {
messageService.deleteMessage(messageId, (String) subject.getId());
return Response.success();
} catch (MessageServiceException e) {
e.printStackTrace();
return Response.error(e);
}
}
}
......@@ -6,6 +6,8 @@ import cn.meteor.beyondclouds.modules.message.exception.MessageServiceException;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import java.io.Serializable;
/**
* <p>
* 服务类
......@@ -45,4 +47,17 @@ public interface IMessageService extends IService<Message> {
Message getMessage(String messageId) throws MessageServiceException;
/**
* 删除单个消息
* @param messageId
* @param userId
* @throws MessageServiceException
*/
void deleteMessage(String messageId, String userId) throws MessageServiceException;
/**
* 删除所有消息
* @param userId
*/
void deleteAllMessage(String userId);
}
......@@ -65,4 +65,32 @@ public class MessageServiceImpl extends ServiceImpl<MessageMapper, Message> impl
//2. 返回消息详情
return message;
}
@Override
public void deleteMessage(String messageId, String userId) throws MessageServiceException{
//1. 判断有没有这条消息
QueryWrapper<Message> messageQueryWrapper = new QueryWrapper<>();
messageQueryWrapper
.eq("message_id",messageId)
.eq("user_id",userId);
Message message = getOne(messageQueryWrapper);
//2. 若找不到该消息,抛出业务异常
if (message == null) {
throw new MessageServiceException(MessageErrorCode.MESSAGE_NOT_EXIST);
}
//3. 删除该条消息
removeById(messageId);
}
@Override
public void deleteAllMessage(String userId) {
QueryWrapper<Message> messageQueryWrapper = new QueryWrapper<>();
messageQueryWrapper.eq("user_id",userId);
remove(messageQueryWrapper);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment