package com.ruoyi.frequency.worklike.controller;

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 com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.frequency.worklike.entity.WorkLike;
import com.ruoyi.frequency.worklike.service.WorkLikeService;
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 liwenlong
 * @date 2023-10-12
 */
@RestController
@RequestMapping("/frequency/worklike")
public class WorkLikeController extends BaseController
{
    @Autowired
    private WorkLikeService workLikeService;

    /**
     * 查询作品点赞列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:worklike:list')")
    @GetMapping("/list")
    public TableDataInfo<WorkLike> list(WorkLike workLike)
    {
        startPage();
        List<WorkLike> list = workLikeService.selectWorkLikeList(workLike);
        return getDataTable(list);
    }

    /**
     * 导出作品点赞列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:worklike:export')")
    @Log(title = "作品点赞", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WorkLike workLike)
    {
        List<WorkLike> list = workLikeService.selectWorkLikeList(workLike);
        ExcelUtil<WorkLike> util = new ExcelUtil<WorkLike>(WorkLike.class);
        return util.exportExcel(list, "作品点赞数据");
    }

    /**
     * 获取作品点赞详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:worklike:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<WorkLike> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(workLikeService.selectWorkLikeById(id));
    }

    /**
     * 新增作品点赞
     */
    @PreAuthorize("@ss.hasPermi('frequency:worklike:add')")
    @Log(title = "作品点赞", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkLike workLike)
    {
        return toAjax(workLikeService.insertWorkLike(workLike));
    }

    /**
     * 修改作品点赞
     */
    @PreAuthorize("@ss.hasPermi('frequency:worklike:edit')")
    @Log(title = "作品点赞", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkLike workLike)
    {
        return toAjax(workLikeService.updateWorkLike(workLike));
    }

    /**
     * 删除作品点赞
     */
    @PreAuthorize("@ss.hasPermi('frequency:worklike:remove')")
    @Log(title = "作品点赞", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(workLikeService.deleteWorkLikeByIds(ids));
    }
}
