package com.jxy.marketall.controller;

import com.github.pagehelper.PageHelper;
import com.jxy.common.core.utils.StringUtils;
import com.jxy.common.core.web.Result.AjaxResult;
import com.jxy.common.core.web.controller.BaseController;
import com.jxy.common.core.web.page.TableDataInfo;
import com.jxy.common.security.annotation.RequiresLogin;
import com.jxy.marketall.dto.SubscriptionContentDto;
import com.jxy.marketall.service.MsgSubService;
import com.jxy.marketall.vo.IdVo;
import com.jxy.marketall.vo.PageVo;
import com.jxy.marketall.vo.SubscriptionContentVo;
import io.swagger.annotations.ApiOperation;
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;

import java.util.List;

/**
 * @Description 统一请求接口
 * @Date 2022/5/27 9:54
 * @Author 杜懿
 */
@RestController
@RequestMapping("/msgSub")
public class MsgSubscriptionController extends BaseController {

    @Autowired
    private MsgSubService msgSubService;

    @PostMapping("/subscript")
    @ApiOperation(value = "指标订阅")
    @RequiresLogin
    public AjaxResult subscript(@RequestBody  SubscriptionContentVo vo){

        return  msgSubService.subscriptionMsg(vo);

    }

    @PostMapping("/list")
    @ApiOperation(value = "查看用户订阅指标列表 分页")
    @RequiresLogin
    public TableDataInfo list(@RequestBody(required = false) PageVo vo){

        if(StringUtils.isNull(vo)){
            vo = new PageVo();
        }
        PageHelper.startPage(vo.getPage(),vo.getLimit());
        List<SubscriptionContentDto> list = msgSubService.getUserSubscriptList(vo);
        return  getDataTable(list);

    }

    @PostMapping("/cancel")
    @ApiOperation(value = "取消指标订阅")
    @RequiresLogin
    public AjaxResult cancel(@RequestBody IdVo vo){

        return  msgSubService.cancelSubscription(vo);

    }


}
