package com.jxy.marketall.controller;

import com.jxy.common.core.annotation.RateLimiter;
import com.jxy.common.core.enums.LimitType;
import com.jxy.common.core.utils.StringUtils;
import com.jxy.common.core.web.Result.AjaxResult;
import com.jxy.common.security.annotation.RequiresLogin;
import com.jxy.marketall.service.MessageService;
import com.jxy.marketall.vo.*;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.SQLException;

/**
 * @Description 统一请求接口
 * @Date 2022/5/27 9:54
 * @Author 杜懿
 */
@RestController
@RequestMapping(value = {"/msgBorad","/msgBroad"})
@Api(tags = "留言接口")
public class MessageController {

    @Autowired
    private MessageService messageService;


    @PostMapping("/submitMsg")
    @RequiresLogin
    public AjaxResult submitMsg(@RequestBody SubmitMsgVo vo){

        try {
            messageService.submitMsg(vo);
            return  AjaxResult.success("留言成功");
        } catch (Exception e) {
            return AjaxResult.error("留言失败"+e);
        }
    }

    @PostMapping("/getPageMsg")
    @RequiresLogin
    public AjaxResult getPageMsg(@RequestBody PageMsgVo vo){

        return  messageService.getPageMsg(vo);
    }

    @PostMapping("/getAllMsg")
    @RequiresLogin
    public AjaxResult getAllMsg(@RequestBody(required = false) AllMsgVo vo){
        if(StringUtils.isNull(vo)){vo = new AllMsgVo();}

        return  messageService.getAllMsg(vo);
    }

    @PostMapping("/getDailyMsgCount")
    @RequiresLogin
    public AjaxResult getDailyMsgCount(@RequestBody(required = false)QueryVo vo){
        if(StringUtils.isNull(vo)){vo = new QueryVo();}

        return  messageService.getDailyMsgCount(vo);
    }

    @PostMapping("/responMsg")
    @RequiresLogin
    public AjaxResult responMsg(@RequestBody ResponMsgVo vo){

        return  messageService.responMsg(vo);
    }

    @PostMapping("/getPrivateMsg")
    @RequiresLogin
    public AjaxResult getPrivateMsg(@RequestBody PrivateMsgVo vo){

        return  messageService.getPrivateMsg(vo);
    }

    @PostMapping("/getPageDetail")
    @RequiresLogin
    public AjaxResult getPageDetail(@RequestBody PageMsgVo vo){

        return  messageService.getPageDetail(vo);
    }

    @PostMapping("/comment")
    @RequiresLogin
    public AjaxResult comment(@RequestBody PageCommentVo vo){

        return  messageService.changePageChooseByUser(vo);
    }

}
