package com.sv.oms.controller;
import com.sv.service.oms.CoachService;
import com.ydd.framework.core.common.Pagination;
import com.ydd.framework.core.common.dto.ResponseDTO;
import com.ydd.oms.controller.OmsController;
import com.sv.entity.Coach;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Controller - 教练
 *
 * @author zhaoziyu
 * @since 2018-08-06
 */
@RestController
public class CoachController extends OmsController {

	private final Logger logger = LoggerFactory.getLogger(CoachController.class);
	
	@Resource
	private CoachService coachService;

	/**
	 * 分页查询教练
	 */
	@RequestMapping(value = "/coachs", method = RequestMethod.GET)
	public ResponseDTO findPage(Pagination pagination) {
		return ResponseDTO.ok()
				.setPagination(coachService.findPage(pagination));
	}



	/**
	 * 分页查询教练
	 */
	@RequestMapping(value = "/coach/venue", method = RequestMethod.GET)
	public ResponseDTO findByVenueType(@RequestParam("venueType") Integer venueType) {
		return ResponseDTO.ok().addAttribute("coaches",coachService.findByVenueType(venueType));
	}

	/**
	 * 查询教练信息
	 */
	@RequestMapping(value = "/coach/{id}", method = RequestMethod.GET)
	public ResponseDTO findById(@PathVariable("id") Integer id) {
		return ResponseDTO.ok()
				.addAttribute("coach", coachService.findById(id));
	}

	/**
	 * 保存教练
	 */
	@RequestMapping(value = "/coach", method = RequestMethod.POST)
	public ResponseDTO save(Coach coach) {
		coachService.save(coach);
		return ResponseDTO.ok("保存成功");
	}

	/**
	 * 删除教练
	 */
	@RequestMapping(value = "/coach/delete", method = RequestMethod.POST)
	public ResponseDTO delete(@RequestParam("id[]") Integer[] ids) {
		coachService.deleteByIds(ids);
		return ResponseDTO.ok("删除成功");
	}

}
