package com.usoftchina.bi.server.controller.dashboard;

import com.usoftchina.bi.core.base.RepCode;
import com.usoftchina.bi.core.base.RepEntity;
import com.usoftchina.bi.server.model.pojo.annotation.CheckToken;
import com.usoftchina.bi.server.service.dashboard.DefaultDashboardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 设置首页默认报表
 * @Author chenwei
 * @Date 2019-05-31
 */
@RestController
@Api(description = "设置首页默认报表相关接口")
@RequestMapping("/home/defaultDashboard")
public class DefaultDashboardController {

    @Autowired
    private DefaultDashboardService defaultDashboardService;

    @GetMapping("/read/{userId}")
    @CheckToken
    @ApiOperation(value = "查看用户设置的首页默认报表", notes = "查看用户设置的首页默认报表", response = RepEntity.class)
    public RepEntity read(@RequestHeader String token, @PathVariable("userId") int userId){
        return new RepEntity(RepCode.success, defaultDashboardService.read(userId));
    }

    @PostMapping("/save/{userId}/{dashboardId}")
    @CheckToken
    @ApiOperation(value = "设置首页默认报表", notes = "设置首页默认报表", response = RepEntity.class)
    public RepEntity save(@RequestHeader String token, @PathVariable("userId") int userId, @PathVariable("dashboardId") int dashboardId){
        defaultDashboardService.save(userId, dashboardId);
        return new RepEntity(RepCode.success, null);
    }

    @PostMapping("/delete/{userId}/{dashboardId}")
    @CheckToken
    @ApiOperation(value = "取消首页默认报表", notes = "取消首页默认报表", response = RepEntity.class)
    public RepEntity delete(@RequestHeader String token, @PathVariable("userId") int userId, @PathVariable("dashboardId") int dashboardId){
        defaultDashboardService.delete(dashboardId);
        return new RepEntity(RepCode.success, null);
    }

}
