package com.bjtdba.userCenter.controller;

import com.bjtdba.entity.userCenter.UserVideoLike;
import com.bjtdba.userCenter.service.UserVideoLikeService;
import com.bjtdba.utils.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Map;

/**
 * 用户点赞记录表(UserVideoLike)表控制层
 *
 * @author 何海强
 * @since 2022-11-12 14:14:10
 */
@RestController
@RequestMapping("userCenter_service/userVideoLike")
public class UserVideoLikeController {

    @Autowired
    private  UserVideoLikeService userVideoLikeService;


    /**
     * 点赞
     */
    @PostMapping("/addLike")
    public Object addLike(@RequestHeader Map<String,String> Hmap,@RequestBody Map<String,String> map){

        if(!Hmap.containsKey("uid")){
            return ResponseUtil.fail("uid 参数错误");
        }

        if(!map.containsKey("vid")){
            return ResponseUtil.fail("参数错误");
        }
        Integer vid=Integer.parseInt(map.get("vid"));
        Integer  uid=Integer.parseInt(Hmap.get("uid"));
        UserVideoLike userVideoLike=new UserVideoLike();
        userVideoLike.setVideoId(vid);
        userVideoLike.setUid(uid);
        userVideoLike.setAddtime(new Date());
        UserVideoLike userVideoLikeRes=userVideoLikeService.insert(userVideoLike);
        userVideoLikeRes.getLid();
        if(userVideoLikeRes!=null&&userVideoLikeRes.getLid()>0){
            return ResponseUtil.ok();
        }else{
            return ResponseUtil.fail("点赞失败");
        }

    }

}

