package com.sqx.modules.myCollection.controller;


import com.sqx.common.utils.Result;
import com.sqx.modules.app.annotation.Login;
import com.sqx.modules.myCollection.entity.MyCollection;
import com.sqx.modules.myCollection.service.MyCollectionService;
import com.sqx.modules.resumes.entity.PostPush;
import com.sqx.modules.resumes.entity.Resumes;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 收藏管理
 * </p>
 *
 * @author www.javacoder.top
 * @since 2023-01-17
 */
@RestController
@RequestMapping("/app/myCollection/")
public class MyCollectionController {
    @Autowired
    private MyCollectionService collectionService;

    @Login
    @PostMapping(value = "saveCollection")
    @ApiOperation("添加我的收藏")
    public Result save(@RequestAttribute("userId") Long userId, MyCollection collection) {
        collection.setUserId(userId);
        return collectionService.saveCollection(collection);
    }


    @Login
    @GetMapping(value = "getMyCollectionListV2")
    @ApiOperation("获取我的收藏列表")
    public Result getMyCollectionListV2(Integer page, Integer limit, @RequestAttribute("userId") Long userId, MyCollection collection, PostPush postPush) {
        collection.setUserId(userId);
        collection.setType(1);
        return Result.success().put("data", collectionService.getMyCollectionListV2(page, limit, collection, postPush));
    }


    @Login
    @GetMapping(value = "getCompanyCollectionList")
    @ApiOperation("企业获取我的收藏列表")
    public Result getCompanyCollectionList(Integer page, Integer limit, @RequestAttribute("userId") Long userId, MyCollection collection, Resumes resumes) {
        collection.setUserId(userId);
        collection.setType(2);
        return Result.success().put("data", collectionService.getCompanyCollectionList(page, limit, collection, resumes,userId));
    }

    @Login
    @GetMapping(value = "getMyCollectionList")
    @ApiOperation("获取我的收藏列表")
    public Result getMyCollectionList(Integer page, Integer limit, @RequestAttribute("userId") Long userId, MyCollection collection) {
        collection.setUserId(userId);
        collection.setType(1);
        return Result.success().put("data", collectionService.getMyCollectionList(page, limit, collection));
    }
    @Login
    @GetMapping(value = "deleteMyCollection")
    @ApiOperation("删除我的收藏")
    public Result deleteMyCollection(Long collectionId) {
        return collectionService.removeById(collectionId) ? Result.success() : Result.error();
    }
}

