/**
 * Copyright 2008-2009. Chongqing Communications Industry Services Co.,Ltd Information Technology Branch. All rights reserved. <a>http://www.cqcis.com</a>
 */
package com.crunii.micro.service.sysmgr.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.crunii.micro.common.dto.PageReq;
import com.crunii.micro.common.dto.PageRsp;
import com.crunii.micro.common.dto.Result;
import com.crunii.micro.service.sysmgr.dto.pub.PubC;
import com.crunii.micro.service.sysmgr.dto.pub.PubInfo;
import com.crunii.micro.service.sysmgr.dto.pub.PubReq;
import com.crunii.micro.service.sysmgr.dto.pub.PubU;
import com.crunii.micro.service.sysmgr.service.PublishService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * @author 田平 create 2023-02-21 10:48:26
 */
@Api(value = "发布相关")
@Controller
@RequestMapping("/auth/PubController")
public class PubController {
	@Autowired
	private PublishService publishService;

	@ApiOperation(value = "发布分页")
	@RequestMapping(path = "/pagePub", method = RequestMethod.POST)
	@ResponseBody
	public Result<PageRsp<PubInfo>> pagePub(@RequestBody @ApiParam PageReq<PubReq> req) {
		Result<PageRsp<PubInfo>> result=new Result<>();
		result.setData(publishService.pagePub(req));
		return result;
	}

	@ApiOperation(value = "创建发布")
	@RequestMapping(path = "/createPub", method = RequestMethod.POST)
	@ResponseBody
	public Result<String> createPub(@RequestBody @ApiParam PubC pubC) {
		Result<String> result = new Result<String>();
		publishService.createPub(pubC);
		return result;
	}

	@ApiOperation(value = "更新发布")
	@RequestMapping(path = "/updatePub", method = RequestMethod.POST)
	@ResponseBody
	public Result<String> updatePub(@RequestBody @ApiParam PubU pubU) {
		Result<String> result = new Result<String>();
		publishService.updatePub(pubU);
		return result;
	}

	@ApiOperation(value = "根据发布Id获取发布内容")
	@GetMapping(path = "/getPubContent")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "pubId", value = "发布Id", required = true)
	})
	@ResponseBody
	public Result<String> getPubContent(int pubId) {
		Result<String> result = new Result<String>();
		result.setData(publishService.getPubContent(pubId));
		return result;
	}

}
