package cn.com.ty.lift.ud.userCollect.controller;

import cn.com.ty.lift.ud.common.BaseController;
import cn.com.ty.lift.ud.userCollect.controller.query.UserCollectQuery;
import cn.com.ty.lift.ud.userCollect.mapper.entity.UserCollectDto;
import cn.com.ty.lift.ud.userCollect.mapper.entity.UserCollectEntity;
import cn.com.ty.lift.ud.userCollect.service.IUserCollectService;
import cn.com.xwy.boot.web.dto.RestResponse;
import com.baomidou.mybatisplus.extension.service.IService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 我的收藏 API
 *
 * @author Xson
 * @date 2020-04-28
 */
@Api(tags = "我的收藏 API- 小陶")
@RestController
@RequestMapping("/api/userCollects")
public class UserCollectController extends BaseController<UserCollectEntity, UserCollectQuery> {

    private final Logger log = LoggerFactory.getLogger(UserCollectController.class);

    private @Autowired
    IUserCollectService userCollectService;

    @Override
    protected IService<UserCollectEntity> getService() {
        return userCollectService;
    }

    @ApiOperation(value = "查看是否被收藏-app")
    @PostMapping("/isCollect")
    public RestResponse isCollect(@RequestBody UserCollectDto userCollect) {
        UserCollectEntity collect = userCollectService.isCollect(userCollect);
        if(null == collect){
            return RestResponse.success(null, "未收藏");
        }else{
            return RestResponse.success(null, "已收藏");
        }
    }


    /**
     * 查询收藏的问题
     * @param query
     * @return
     */
    @ApiOperation(value = "查询收藏的问题")
    @PostMapping("/query-question")
    public RestResponse getQuestion(@RequestBody UserCollectQuery query) {
        if(query.getPageNum() < 1){
            return RestResponse.fail("error", "当前页不能小于1");
        }else{
            return userCollectService.selectQuestionById(query);
        }
    }

    /**
     * 查询收藏的视频
     * @param query
     * @return
     */
    @ApiOperation(value = "查询收藏的视频")
    @PostMapping("/query-schoolVideo")
    public RestResponse getSchoolVideo(@RequestBody UserCollectQuery query) {
        if(query.getPageNum() < 1){
            return RestResponse.fail("error", "当前页不能小于1");
        }else{
            return userCollectService.selectSchoolVideoById(query);
        }
    }

    /**
     * 查询收藏的职位
     * @param query
     * @return
     */
    @ApiOperation(value = "查询收藏的职位")
    @PostMapping("/query-recruitmentInfo")
    public RestResponse getRecruitmentInfo(@RequestBody UserCollectQuery query) {
        if(query.getPageNum() < 1){
            return RestResponse.fail("error", "当前页不能小于1");
        }else{
            return userCollectService.selectRecruitmentInfoById(query);
        }
    }

    /**
     * 查询收藏的商品
     * @param query
     * @return
     */
    @ApiOperation(value = "查询收藏的商品")
    @PostMapping("/query-shopping")
    public RestResponse getShopping(@RequestBody UserCollectQuery query) {
        if(query.getPageNum() < 1){
            return RestResponse.fail("error", "当前页不能小于1");
        }else{
            return userCollectService.selectShoppingById(query);
        }
    }

    /**
     * 查询收藏的资料
     * @param query
     * @return
     */
    @ApiOperation(value = "查询收藏的资料")
    @PostMapping("/query-attachment-file")
    public RestResponse getAttachmentFile(@RequestBody UserCollectQuery query) {
        if(query.getPageNum() < 1){
            return RestResponse.fail("error", "当前页不能小于1");
        }else{
            return userCollectService.selectAttachmentFileById(query);
        }
    }
}