package com.ruoyi.abuwx.controller;

import com.ruoyi.abuwx.domain.UserFavorite;
import com.ruoyi.abuwx.service.IUserFavoriteService;
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/favorite")
public class UserFavoriteController extends BaseController
{
    @Autowired
    private IUserFavoriteService userFavoriteService;

    /**
     * 查询用户收藏记录列表
     */
    @PreAuthorize("@ss.hasPermi('user:favorite:list')")
    @GetMapping("/list")
    public TableDataInfo list(UserFavorite userFavorite)
    {
        startPage();
        List<UserFavorite> list = userFavoriteService.selectUserFavoriteList(userFavorite);
        return getDataTable(list);
    }

    /**
     * 收藏
     */
    @PreAuthorize("@ss.hasPermi('user:favorite:add')")
    @Log(title = "收藏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestParam Long userId, @RequestParam Long contentType,@RequestParam Long contentId)
    {
        return toAjax(userFavoriteService.favoriteContent(userId,contentType,contentId));
    }

    /**
     * 取消收藏
     */
    @PreAuthorize("@ss.hasPermi('user:favorite:cancel')")
    @Log(title = "取消收藏", businessType = BusinessType.DELETE)
	@PostMapping("/cancel")
    public AjaxResult unFavorite(@RequestParam Long userId, @RequestParam Long contentType, @RequestParam Long contentId)
    {
        return toAjax(userFavoriteService.unFavorite(userId,contentType,contentId));
    }
}
