package com.sqx.modules.post.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sqx.common.utils.Result;
import com.sqx.modules.app.annotation.Login;
import com.sqx.modules.post.entity.ViewPost;
import com.sqx.modules.post.service.ViewPostService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@RestController
@RequestMapping("/app/viewPost")
public class ViewPostController {
    @Autowired
    private ViewPostService viewPostService;
    @Login
    @GetMapping("getViewPost")
    @ApiOperation("获取查看的岗位列表")
    public Result getViewPost(@RequestAttribute("userId") Long userId){

        return  Result.success().put("data",viewPostService.getViewPostList(userId));

    }

    @Login
    @GetMapping("getCollectPost")
    @ApiOperation("获取收藏的岗位列表")
    public Result getCollectPost(@RequestAttribute("userId") Long userId) {

        return  Result.success().put("data",viewPostService.getCollectPost(userId));
    }
    @Login
    @PostMapping("collectPost")
    @ApiOperation("是否收藏岗位")
    public Result  collectPost(@RequestAttribute("userId") Integer userId,Integer postId,Integer isCollect){
        QueryWrapper<ViewPost> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId).eq("post_id",postId);
        ViewPost viewPost = viewPostService.getOne(queryWrapper);
        viewPost.setIsCollect(isCollect);
        viewPostService.saveOrUpdate(viewPost);
        return  Result.success();
    }

    @Login
    @PostMapping("pushPost")
    @ApiOperation("投送简历")
    public Result pushPost(@RequestAttribute("userId")  Long userId, String postId) {
        QueryWrapper<ViewPost> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId).eq("post_id", postId);
        ViewPost viewPost = viewPostService.getOne(queryWrapper);
        viewPost.setIsPush(1);
        viewPost.setCreatTime(String.valueOf(LocalDateTime.now()));
        viewPostService.saveOrUpdate(viewPost);
        return Result.success();
    }
    @Login
    @GetMapping("gerPushPost")
    @ApiOperation("获取收藏的岗位列表")
    public Result getPushPost(@RequestAttribute("userId") Long userId) {
        return  Result.success().put("data",viewPostService.getPushPost(userId));
    }
}
