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.DashboardFavoriteService;
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-04-24
 */
@Api(description = "看板收藏相关接口")
@RestController
@RequestMapping("/dashboard/favorite")
public class DashboardFavoriteController {

    @Autowired
    private DashboardFavoriteService dashboardFavoriteService;

    @GetMapping("/list")
    @CheckToken
    @ApiOperation(value = "收藏列表", notes = "我的收藏列表", response = RepEntity.class)
    public RepEntity list(@RequestHeader String token){
        return new RepEntity(RepCode.success, dashboardFavoriteService.list(token));
    }

    @PostMapping("/save/{id}")
    @CheckToken
    @ApiOperation(value = "加入收藏", notes = "加入我的收藏", response = RepEntity.class)
    public RepEntity save(@RequestHeader String token, @PathVariable("id") Long dashboardId){
        dashboardFavoriteService.save(token, dashboardId);
        return new RepEntity(RepCode.success);
    }

    @PostMapping("/delete/{id}")
    @CheckToken
    @ApiOperation(value = "取消收藏", notes = "取消我的收藏", response = RepEntity.class)
    public RepEntity delete(@RequestHeader String token, @PathVariable("id") Long dashboardId){
        dashboardFavoriteService.delete(token, dashboardId);
        return new RepEntity(RepCode.success);
    }

}
