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

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.starry.admin.modules.play.module.entity.PlayNoticeInfoEntity;
import com.starry.admin.modules.play.module.vo.PlayNoticeInfoAddVo;
import com.starry.admin.modules.play.service.IPlayNoticeInfoService;
import com.starry.common.annotation.Log;
import com.starry.common.enums.BusinessType;
import com.starry.common.result.R;
import com.starry.common.utils.ConvertUtil;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 公告Controller
 *
 * @author admin
 * @since 2024-04-06
 */
@RestController
@RequestMapping("/play/notice")
public class PlayNoticeInfoController {
    @Resource
    private IPlayNoticeInfoService playNoticeInfoService;


    /**
     * 查询公告列表
     */
    @GetMapping("/listAll")
    public R listAll(PlayNoticeInfoEntity playNoticeInfo) {
        IPage<PlayNoticeInfoEntity> list = playNoticeInfoService.selectPlayNoticeInfoByPage(playNoticeInfo);
        return R.ok(list);
    }

    /**
     * 查询公告列表
     */
    @GetMapping("/list")
    public R list(PlayNoticeInfoEntity playNoticeInfo) {
        IPage<PlayNoticeInfoEntity> list = playNoticeInfoService.selectPlayNoticeInfoByPage(playNoticeInfo);
        return R.ok(list);
    }

    /**
     * 获取公告详细信息
     */
    @GetMapping(value = "/{id}")
    public R getInfo(@PathVariable("id") String id) {
        return R.ok(playNoticeInfoService.selectPlayNoticeInfoById(id));
    }

    /**
     * 新增公告
     */
    @Log(title = "公告", businessType = BusinessType.INSERT)
    @PostMapping("/create")
    public R create(@Validated @RequestBody PlayNoticeInfoAddVo vo) {
        PlayNoticeInfoEntity entity = ConvertUtil.entityToVo(vo, PlayNoticeInfoEntity.class);
        boolean success = playNoticeInfoService.create(entity);
        if (success) {
            return R.ok();
        }
        return R.error("添加失败");
    }


    /**
     * 删除公告
     */
    @Log(title = "公告", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.ok(playNoticeInfoService.deletePlayNoticeInfoByIds(ids));
    }
}
