package com.sv.api.controller;

import com.sv.entity.MemberToken;
import com.sv.service.api.MemberTokenService;
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 - 用户token
 *
 * @author lihong
 * @since 2018-08-02
 */
@RestController
public class MemberTokenController extends BaseApiController {

	private final Logger logger = LoggerFactory.getLogger(MemberTokenController.class);
	
	@Resource
	private MemberTokenService memberTokenService;

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

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

	/**
	 * 保存用户token
	 */
	@RequestMapping(value = "/member/token", method = RequestMethod.POST)
	public ResponseDTO save(MemberToken memberToken) {
		memberTokenService.save(memberToken);
		return ResponseDTO.ok("保存成功");
	}

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

}
