package com.sv.api.controller;

import com.sv.entity.Platform;
import com.sv.service.common.PlatformService;
import com.ydd.framework.core.common.Pagination;
import com.ydd.framework.core.common.dto.ResponseDTO;
import com.ydd.framework.core.controller.BaseApiController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Controller - 平台信息表
 *
 * @author lihong
 * @since 2018-08-02
 */
@RestController
public class PlatformController extends BaseApiController {

	private final Logger logger = LoggerFactory.getLogger(PlatformController.class);
	
	@Resource
	private PlatformService platformService;

	/**
	 * 分页查询平台信息表
	 */
	@RequestMapping(value = "/platforms", method = RequestMethod.GET)
	public ResponseDTO findPage(Pagination pagination) {
		return ResponseDTO.ok()
				.setPagination(platformService.findPage(pagination));
	}

	/**
	 * 查询平台信息表信息
	 */
	@RequestMapping(value = "/platform/{id}", method = RequestMethod.GET)
	public ResponseDTO findById(@PathVariable("id") Integer id) {
		return ResponseDTO.ok()
				.addAttribute("platform", platformService.findById(id));
	}

	/**
	 * 保存平台信息表
	 */
	@RequestMapping(value = "/platform", method = RequestMethod.POST)
	public ResponseDTO save(Platform platform) {
		platformService.save(platform);
		return ResponseDTO.ok("保存成功");
	}

	/**
	 * 删除平台信息表
	 */
	@RequestMapping(value = "/platform/delete", method = RequestMethod.POST)
	public ResponseDTO delete(@RequestParam("id[]") Integer[] ids) {
		platformService.deleteByIds(ids);
		return ResponseDTO.ok("删除成功");
	}

}
