package com.pnkx.web.controller.blog.admin;

import com.pnkx.common.annotation.Log;
import com.pnkx.common.core.controller.BaseController;
import com.pnkx.common.core.domain.AjaxResult;
import com.pnkx.common.core.page.TableDataInfo;
import com.pnkx.common.enums.BusinessType;
import com.pnkx.domain.po.PxSubscribe;
import com.pnkx.service.IPxSubscribeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author by PHY
 * @Classname PxAdminSubscribeController
 * @date 2021-06-17 15:41
 */
@RestController
@RequestMapping("/admin/subscribe")
public class PxAdminSubscribeController extends BaseController {

    @Resource
    IPxSubscribeService pxSubscribeService;

    /**
     * 查询订阅列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PxSubscribe pxSubscribe) {
        startPage();
        List<PxSubscribe> list = pxSubscribeService.selectPxSubscribeList(pxSubscribe);
        return getDataTable(list);
    }

    /**
     * 获取订阅详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(pxSubscribeService.selectPxSubscribeById(id));
    }

    /**
     * 新增订阅
     */
    @Log(title = "订阅", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PxSubscribe pxSubscribe) {
        return toAjax(pxSubscribeService.insertPxSubscribe(pxSubscribe));
    }

    /**
     * 修改订阅
     */
    @Log(title = "订阅", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PxSubscribe pxSubscribe) {
        return toAjax(pxSubscribeService.updatePxSubscribe(pxSubscribe));
    }

    /**
     * 删除订阅
     */
    @Log(title = "订阅", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(pxSubscribeService.deletePxSubscribeByIds(ids));
    }
}
