package com.ruoyi.post.frequency.postlike.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.post.frequency.postlike.entity.PostLike;
import com.ruoyi.post.frequency.postlike.service.PostLikeService;
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-09
 */
@RestController
@RequestMapping("/frequency/poslike")
public class PostLikeController extends BaseController
{
    @Autowired
    private PostLikeService postLikeService;

    /**
     * 查询帖子点赞列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:poslike:list')")
    @PostMapping("/list")
    public TableDataInfo<PostLike> list(@RequestBody PostLike postLike)
    {
        startPage();
        List<PostLike> list = postLikeService.selectPostLikeList(postLike);
        return getDataTable(list);
    }

    /**
     * 导出帖子点赞列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:poslike:export')")
    @Log(title = "帖子点赞", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PostLike postLike)
    {
        List<PostLike> list = postLikeService.selectPostLikeList(postLike);
        ExcelUtil<PostLike> util = new ExcelUtil<PostLike>(PostLike.class);
        return util.exportExcel(list, "帖子点赞数据");
    }

    /**
     * 获取帖子点赞详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:poslike:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<PostLike> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(postLikeService.selectPostLikeById(id));
    }

    /**
     * 新增帖子点赞
     */
    @PreAuthorize("@ss.hasPermi('frequency:poslike:add')")
    @Log(title = "帖子点赞", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PostLike postLike)
    {
        return toAjax(postLikeService.insertPostLike(postLike));
    }

    /**
     * 修改帖子点赞
     */
    @PreAuthorize("@ss.hasPermi('frequency:poslike:edit')")
    @Log(title = "帖子点赞", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PostLike postLike)
    {
        return toAjax(postLikeService.updatePostLike(postLike));
    }

    /**
     * 删除帖子点赞
     */
    @PreAuthorize("@ss.hasPermi('frequency:poslike:remove')")
    @Log(title = "帖子点赞", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(postLikeService.deletePostLikeByIds(ids));
    }
}
