package com.railway.web.controller.business.push;

import com.railway.business.push.domain.BusPushMsg;
import com.railway.business.push.service.IBusPushMsgService;
import com.railway.common.core.controller.BaseController;
import com.railway.common.core.domain.AjaxResult;
import com.railway.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Api(value = "rest/push/bus/push/msg", tags = "个推消息表")
@RestController
@Validated
@RequestMapping(value = "business/push/bus/push/msg")
public class BusPushMsgController extends BaseController {
    @Autowired
    private IBusPushMsgService busPushMsgService;

    @ApiOperation(value = "新增")
    @PostMapping("/add")
    public AjaxResult add(@Validated @RequestBody BusPushMsg busPushMsg) {
        return toAjax(busPushMsgService.create(busPushMsg));
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("/{ids}")
    public AjaxResult delete(@PathVariable(value = "ids") String[] ids) {
        return toAjax(busPushMsgService.delete(ids));
    }

    @ApiOperation(value = "更新")
    @PutMapping("/update")
    public AjaxResult update(@RequestBody @Valid BusPushMsg busPushMsg) {
        return toAjax(busPushMsgService.update(busPushMsg));
    }

    @ApiOperation(value = "单个")
    @GetMapping(value = {"/", "/{id}"})
    public AjaxResult getInfo(@PathVariable(value = "id") String id) {
        BusPushMsg info = busPushMsgService.getInfo(id);
        AjaxResult ajax = AjaxResult.success();
        ajax.put("info",info);
        return ajax;
    }

    @ApiOperation(value = "列表")
    @GetMapping(value = "list")
    public TableDataInfo getList(BusPushMsg busPushMsg) {
        startPage();
        List<BusPushMsg> list = busPushMsgService.getList(busPushMsg);
        return getDataTable(list);
    }

    @ApiOperation(value = "最近的5条消息")
    @GetMapping(value = "getListTop5")
    public AjaxResult getListTop5(BusPushMsg busPushMsg) {
        List<BusPushMsg> list = busPushMsgService.getListTop5(busPushMsg);
        AjaxResult ajax = AjaxResult.success();
        ajax.put("rows",list);
        return ajax;
    }

}
