package com.purui.prims.headless.server.rest;

import com.purui.prims.auth.api.authentication.pojo.User;
import com.purui.prims.auth.api.authentication.utils.UserHolder;
import com.purui.prims.headless.api.pojo.Collect;
import com.purui.prims.headless.server.service.CollectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
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 javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/***
 * 创建收藏指标的逻辑
 */
@RestController
@RequestMapping("/api/semantic/collect")
@Api(tags = "指标收藏管理")
public class CollectController {


    private CollectService collectService;

    public CollectController(CollectService collectService) {
        this.collectService = collectService;
    }

    @ApiOperation(value = "收藏")
    @PostMapping("/createCollectionIndicators")
    public boolean createCollectionIndicators(@RequestBody Collect collectDO,
                                              HttpServletRequest request,
                                              HttpServletResponse response) {
        User user = UserHolder.findUser(request, response);
        return collectService.createCollectionIndicators(user, collectDO);
    }

    @ApiOperation(value = "取消收藏")
    @DeleteMapping("/deleteCollectionIndicators/{id}")
    public boolean deleteCollectionIndicators(@PathVariable Long id,
                                              HttpServletRequest request,
                                              HttpServletResponse response) {
        User user = UserHolder.findUser(request, response);
        return collectService.deleteCollectionIndicators(user, id);
    }

    @ApiOperation(value = "批量取消收藏")
    @PostMapping("/deleteCollectionIndicators")
    public boolean deleteCollectionIndicators(@RequestBody Collect collectDO,
                                              HttpServletRequest request,
                                              HttpServletResponse response) {
        User user = UserHolder.findUser(request, response);
        return collectService.deleteCollectionIndicators(user, collectDO);
    }

}
