package com.ruoyi.abuwx.controller;

import com.ruoyi.abuwx.domain.UserLike;
import com.ruoyi.abuwx.service.IUserLikeService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户点赞记录Controller
 *
 * @author lujie
 * @date 2025-02-05
 */
@RestController
@RequestMapping("/user/like")
public class UserLikeController extends BaseController
{
    @Autowired
    private IUserLikeService userLikeService;

    /**
     * 查询用户点赞记录列表
     */
    @PreAuthorize("@ss.hasPermi('user:like:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserLike userLike)
    {
        startPage();
        List<UserLike> list = userLikeService.selectUserLikeList(userLike);
        return getDataTable(list);
    }

    /**
     * 点赞
     */
    @PreAuthorize("@ss.hasPermi('user:like:add')")
    @Log(title = "点赞", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestParam Long userId, @RequestParam Long contentType,@RequestParam Long contentId)
    {
        return toAjax(userLikeService.likeContent(userId,contentType,contentId));
    }

    /**
     * 取消点赞
     */
    @PreAuthorize("@ss.hasPermi('user:like:cancel')")
    @Log(title = "取消点赞", businessType = BusinessType.DELETE)
    @PostMapping("/cancel")
    public AjaxResult cancelLikeContent(@RequestParam Long userId, @RequestParam Long contentType,@RequestParam Long contentId)
    {
        return toAjax(userLikeService.unlikeContent(userId,contentType,contentId));
    }
}
