package com.ruoyi.post.frequency.postcomment.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.postcomment.entity.PostComment;
import com.ruoyi.post.frequency.postcomment.service.PostCommentService;
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/poscomment")
public class PostCommentController extends BaseController
{
    @Autowired
    private PostCommentService postCommentService;

    /**
     * 查询帖子评论列表
     */
//    @PreAuthorize("@ss.hasPermi('frequency:poscomment:list')")
    @PostMapping("/list")
    public TableDataInfo<PostComment> list(@RequestBody PostComment postComment)
    {
        startPage();
        List<PostComment> list = postCommentService.selectPostCommentList(postComment);
        return getDataTable(list);
    }

    /**
     * 导出帖子评论列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:poscomment:export')")
    @Log(title = "帖子评论", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PostComment postComment)
    {
        List<PostComment> list = postCommentService.selectPostCommentList(postComment);
        ExcelUtil<PostComment> util = new ExcelUtil<PostComment>(PostComment.class);
        return util.exportExcel(list, "帖子评论数据");
    }

    /**
     * 获取帖子评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:poscomment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<PostComment> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(postCommentService.selectPostCommentById(id));
    }

    /**
     * 新增帖子评论
     */
    @PreAuthorize("@ss.hasPermi('frequency:poscomment:add')")
    @Log(title = "帖子评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PostComment postComment)
    {
        return toAjax(postCommentService.insertPostComment(postComment));
    }

    /**
     * 修改帖子评论
     */
    @PreAuthorize("@ss.hasPermi('frequency:poscomment:edit')")
    @Log(title = "帖子评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PostComment postComment)
    {
        return toAjax(postCommentService.updatePostComment(postComment));
    }

    /**
     * 删除帖子评论
     */
    @PreAuthorize("@ss.hasPermi('frequency:poscomment:remove')")
    @Log(title = "帖子评论", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}/{delFlag}")
    public AjaxResult remove(@PathVariable("ids") Long[] ids,@PathVariable("delFlag") Integer delFlag)
    {
        return toAjax(postCommentService.deleteCommentByIds(ids,delFlag));
    }
}
