package com.fs.course.controller;

import com.fs.common.annotation.Log;
import com.fs.common.core.controller.BaseController;
import com.fs.common.core.domain.AjaxResult;
import com.fs.common.core.page.TableDataInfo;
import com.fs.common.enums.BusinessType;
import com.fs.common.utils.poi.ExcelUtil;
import com.fs.course.domain.FsUserCourseFavorite;
import com.fs.course.service.IFsUserCourseFavoriteService;
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 fs
 * @date 2024-05-15
 */
@RestController
@RequestMapping("/course/userCourseFavorite")
public class FsUserCourseFavoriteController extends BaseController
{
    @Autowired
    private IFsUserCourseFavoriteService fsUserCourseFavoriteService;

    /**
     * 查询课程收藏列表
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseFavorite:list')")
    @GetMapping("/list")
    public TableDataInfo list(FsUserCourseFavorite fsUserCourseFavorite)
    {
        startPage();
        List<FsUserCourseFavorite> list = fsUserCourseFavoriteService.selectFsUserCourseFavoriteList(fsUserCourseFavorite);
        return getDataTable(list);
    }

    /**
     * 导出课程收藏列表
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseFavorite:export')")
    @Log(title = "课程收藏", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FsUserCourseFavorite fsUserCourseFavorite)
    {
        List<FsUserCourseFavorite> list = fsUserCourseFavoriteService.selectFsUserCourseFavoriteList(fsUserCourseFavorite);
        ExcelUtil<FsUserCourseFavorite> util = new ExcelUtil<FsUserCourseFavorite>(FsUserCourseFavorite.class);
        return util.exportExcel(list, "课程收藏数据");
    }

    /**
     * 获取课程收藏详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseFavorite:query')")
    @GetMapping(value = "/{favoriteId}")
    public AjaxResult getInfo(@PathVariable("favoriteId") Long favoriteId)
    {
        return AjaxResult.success(fsUserCourseFavoriteService.selectFsUserCourseFavoriteByFavoriteId(favoriteId));
    }

    /**
     * 新增课程收藏
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseFavorite:add')")
    @Log(title = "课程收藏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FsUserCourseFavorite fsUserCourseFavorite)
    {
        return toAjax(fsUserCourseFavoriteService.insertFsUserCourseFavorite(fsUserCourseFavorite));
    }

    /**
     * 修改课程收藏
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseFavorite:edit')")
    @Log(title = "课程收藏", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FsUserCourseFavorite fsUserCourseFavorite)
    {
        return toAjax(fsUserCourseFavoriteService.updateFsUserCourseFavorite(fsUserCourseFavorite));
    }

    /**
     * 删除课程收藏
     */
    @PreAuthorize("@ss.hasPermi('course:userCourseFavorite:remove')")
    @Log(title = "课程收藏", businessType = BusinessType.DELETE)
	@DeleteMapping("/{favoriteIds}")
    public AjaxResult remove(@PathVariable Long[] favoriteIds)
    {
        return toAjax(fsUserCourseFavoriteService.deleteFsUserCourseFavoriteByFavoriteIds(favoriteIds));
    }
}
