package com.starry.admin.modules.clerk.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.starry.admin.modules.clerk.module.entity.PlayCustomArticleInfoEntity;
import com.starry.admin.modules.clerk.service.IPlayCustomArticleInfoService;
import com.starry.common.annotation.Log;
import com.starry.common.enums.BusinessType;
import com.starry.common.result.R;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 陪聊点赞动态信息Controller
 *
 * @author admin
 * @since 2024-05-04
 */
@RestController
@RequestMapping("/custom/article")
public class PlayCustomArticleInfoController {
    @Resource
    private IPlayCustomArticleInfoService playCustomArticleInfoService;

    /**
     * 查询陪聊点赞动态信息列表
     */
    @GetMapping("/list")
    public R list(PlayCustomArticleInfoEntity playCustomArticleInfo) {
        IPage<PlayCustomArticleInfoEntity> list = playCustomArticleInfoService.selectPlayCustomArticleInfoByPage(playCustomArticleInfo);
        return R.ok(list);
    }

    /**
     * 获取陪聊点赞动态信息详细信息
     */
    @PreAuthorize("@customSs.hasPermission('play:info:query')")
    @GetMapping(value = "/{id}")
    public R getInfo(@PathVariable("id") String id) {
        return R.ok(playCustomArticleInfoService.selectPlayCustomArticleInfoById(id));
    }

    /**
     * 新增陪聊点赞动态信息
     */
    @PreAuthorize("@customSs.hasPermission('play:info:create')")
    @Log(title = "陪聊点赞动态信息", businessType = BusinessType.INSERT)
    @PostMapping("/create")
    public R create(@RequestBody PlayCustomArticleInfoEntity playCustomArticleInfo) {
        boolean success = playCustomArticleInfoService.create(playCustomArticleInfo);
        if (success) {
            return R.ok();
        }
        return R.error("添加失败");
    }

    /**
     * 修改陪聊点赞动态信息
     */
    @PreAuthorize("@customSs.hasPermission('play:info:edit')")
    @Log(title = "陪聊点赞动态信息", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/update/{id}")
    public R update(@PathVariable String id, @RequestBody PlayCustomArticleInfoEntity playCustomArticleInfo) {
        playCustomArticleInfo.setId(id);
        boolean success = playCustomArticleInfoService.update(playCustomArticleInfo);
        if (success) {
            return R.ok();
        }
        return R.error("修改失败");
    }

    /**
     * 删除陪聊点赞动态信息
     */
    @PreAuthorize("@customSs.hasPermission('play:info:remove')")
    @Log(title = "陪聊点赞动态信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.ok(playCustomArticleInfoService.deletePlayCustomArticleInfoByIds(ids));
    }
}
