package com.ruoyi.mall.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mall.domain.BusinessArticleLike;
import com.ruoyi.mall.service.IBusinessArticleLikeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 帖子点赞Controller
 * 
 * @author ruoyi
 * @date 2023-10-18
 */
@RestController
@RequestMapping("/system/ArticleLike")
public class BusinessArticleLikeController extends BaseController
{
    @Autowired
    private IBusinessArticleLikeService businessArticleLikeService;

    /**
     * 查询帖子点赞列表
     */
    @PreAuthorize("@ss.hasPermi('system:ArticleLike:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusinessArticleLike businessArticleLike)
    {
        startPage();
        List<BusinessArticleLike> list = businessArticleLikeService.selectBusinessArticleLikeList(businessArticleLike);
        return getDataTable(list);
    }

    /**
     * 导出帖子点赞列表
     */
    @PreAuthorize("@ss.hasPermi('system:ArticleLike:export')")
    @Log(title = "帖子点赞", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusinessArticleLike businessArticleLike)
    {
        List<BusinessArticleLike> list = businessArticleLikeService.selectBusinessArticleLikeList(businessArticleLike);
        ExcelUtil<BusinessArticleLike> util = new ExcelUtil<BusinessArticleLike>(BusinessArticleLike.class);
        util.exportExcel(response, list, "帖子点赞数据");
    }

    /**
     * 获取帖子点赞详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:ArticleLike:query')")
    @GetMapping(value = "/{likeId}")
    public AjaxResult getInfo(@PathVariable("likeId") Long likeId)
    {
        return AjaxResult.success(businessArticleLikeService.selectBusinessArticleLikeByLikeId(likeId));
    }

    /**
     * 新增帖子点赞
     */
    @PreAuthorize("@ss.hasPermi('system:ArticleLike:add')")
    @Log(title = "帖子点赞", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusinessArticleLike businessArticleLike)
    {
        return toAjax(businessArticleLikeService.insertBusinessArticleLike(businessArticleLike));
    }

    /**
     * 修改帖子点赞
     */
    @PreAuthorize("@ss.hasPermi('system:ArticleLike:edit')")
    @Log(title = "帖子点赞", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusinessArticleLike businessArticleLike)
    {
        return toAjax(businessArticleLikeService.updateBusinessArticleLike(businessArticleLike));
    }

    /**
     * 删除帖子点赞
     */
    @PreAuthorize("@ss.hasPermi('system:ArticleLike:remove')")
    @Log(title = "帖子点赞", businessType = BusinessType.DELETE)
	@DeleteMapping("/{likeIds}")
    public AjaxResult remove(@PathVariable Long[] likeIds)
    {
        return toAjax(businessArticleLikeService.deleteBusinessArticleLikeByLikeIds(likeIds));
    }
}
