package com.sv.api.controller;

import com.sv.entity.MemberAuth;
import com.sv.service.api.MemberAuthService;
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 - 用户auth表
 *
 * @author lihong
 * @since 2018-08-02
 */
@RestController
public class MemberAuthController extends BaseApiController {

	private final Logger logger = LoggerFactory.getLogger(MemberAuthController.class);
	
	@Resource
	private MemberAuthService memberAuthService;

	/**
	 * 分页查询用户auth表
	 */
	@RequestMapping(value = "/member/auths", method = RequestMethod.GET)
	public ResponseDTO findPage(Pagination pagination) {
		return ResponseDTO.ok()
				.setPagination(memberAuthService.findPage(pagination));
	}

	/**
	 * 查询用户auth表信息
	 */
	@RequestMapping(value = "/member/auth/{id}", method = RequestMethod.GET)
	public ResponseDTO findById(@PathVariable("id") Integer id) {
		return ResponseDTO.ok()
				.addAttribute("memberAuth", memberAuthService.findById(id));
	}

	/**
	 * 保存用户auth表
	 */
	@RequestMapping(value = "/member/auth", method = RequestMethod.POST)
	public ResponseDTO save(MemberAuth memberAuth) {
		memberAuthService.save(memberAuth);
		return ResponseDTO.ok("保存成功");
	}

	/**
	 * 删除用户auth表
	 */
	@RequestMapping(value = "/member/auth/delete", method = RequestMethod.POST)
	public ResponseDTO delete(@RequestParam("id[]") Integer[] ids) {
		memberAuthService.deleteByIds(ids);
		return ResponseDTO.ok("删除成功");
	}

}
