package com.persagy.dmp.sender.controller;

import com.persagy.dmp.common.constant.ResponseCode;
import com.persagy.dmp.common.exception.BusinessException;
import com.persagy.dmp.common.model.response.CommonResult;
import com.persagy.dmp.message.model.vo.MessageVO;
import com.persagy.dmp.sender.service.IMessageSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 消息发送 Controller
 * @author linhuili
 * @date 2021-09-26
 */
@RestController
@RequestMapping("/message")
public class MessageSenderController {

    @Autowired
    private IMessageSender messageSender;

    /**
     * 消息发送
     * @param messageVO
     */
    @PostMapping("/send")
    public CommonResult<MessageVO> send(@RequestBody MessageVO messageVO) throws Exception{
       if(messageVO == null){
           throw new BusinessException(ResponseCode.A0400.getCode(), "消息体不能为空!");
       }
       messageSender.send(messageVO);
       return CommonResult.success(messageVO);
    }

}
