Commit 798bc5de by 段启岩

Merge remote-tracking branch 'origin/fix-issue#59'

parents f4ae8662 be797c0c
package cn.meteor.beyondclouds.modules.message.api;
import cn.meteor.beyondclouds.core.annotation.CurrentSubject;
import cn.meteor.beyondclouds.core.api.Response;
import cn.meteor.beyondclouds.core.authentication.Subject;
import cn.meteor.beyondclouds.core.exception.ServiceException;
import cn.meteor.beyondclouds.modules.message.service.IMessageService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMapping;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
......@@ -14,10 +21,25 @@ import org.springframework.stereotype.Controller;
* @author 段启岩
* @since 2020-02-12
*/
@Controller
@RestController
@Api(tags = "消息API")
@RequestMapping("/api")
public class MessageApi {
private IMessageService messageService;
@Autowired
public void setMessageService(IMessageService messageService) {
this.messageService = messageService;
}
@ApiOperation("标记信息为已读")
@PutMapping("/message/{messageId}/read")
public Response readMessage(@PathVariable(name = "messageId") String messageId) throws ServiceException {
messageService.readMessage(messageId);
return Response.success();
}
}
package cn.meteor.beyondclouds.modules.message.enums;
import cn.meteor.beyondclouds.core.IErrorCode;
/**
* @program: beyond-clouds
* @description:
* @author: Mr.Zhang
* @create: 2020-02-12 10:28
**/
public enum MessageErrorCode implements IErrorCode {
MESSAGE_NOT_EXIST(1001, "该消息不存在");
MessageErrorCode(long code, String msg) {
this.code = code;
this.msg = msg;
}
private long code;
private String msg;
@Override
public long code() {
return code;
}
@Override
public String msg() {
return msg;
}
}
package cn.meteor.beyondclouds.modules.message.service;
import cn.meteor.beyondclouds.core.exception.ServiceException;
import cn.meteor.beyondclouds.modules.message.entity.Message;
import com.baomidou.mybatisplus.extension.service.IService;
......@@ -13,4 +14,10 @@ import com.baomidou.mybatisplus.extension.service.IService;
*/
public interface IMessageService extends IService<Message> {
/**
* 标记一个信息为已读
* @param messageId
*/
void readMessage(String messageId) throws ServiceException;
}
package cn.meteor.beyondclouds.modules.message.service.impl;
import cn.meteor.beyondclouds.core.exception.ServiceException;
import cn.meteor.beyondclouds.modules.message.entity.Message;
import cn.meteor.beyondclouds.modules.message.enums.MessageErrorCode;
import cn.meteor.beyondclouds.modules.message.mapper.MessageMapper;
import cn.meteor.beyondclouds.modules.message.service.IMessageService;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
......@@ -17,4 +20,15 @@ import org.springframework.stereotype.Service;
@Service
public class MessageServiceImpl extends ServiceImpl<MessageMapper, Message> implements IMessageService {
@Override
public void readMessage(String messageId) throws ServiceException {
Message message = getById(messageId);
if(message == null){
throw new ServiceException(MessageErrorCode.MESSAGE_NOT_EXIST);
}
message.setStatus(1);
updateById(message);
}
}
......@@ -4,7 +4,7 @@ spring:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/beyond_clouds?useUnicode=true&characterEncoding=UTF-8&useSSL=false&allowPublicKeyRetrieval=true
username: root
password: 100Centa30821%mysql
password: 2018006709
# 邮箱
mail:
......
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