package com.yonge.cooleshow.admin.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.yonge.cooleshow.biz.dal.entity.SysUserContracts;
import com.yonge.cooleshow.biz.dal.service.SysUserContractsService;
import com.yonge.cooleshow.common.controller.BaseController;
import com.yonge.cooleshow.common.entity.HttpResponseResult;

@RequestMapping("sysUserContracts")
@Api(tags = "用户协议服务")
@RestController
public class SysUserContractsController extends BaseController {

	@Autowired
	private SysUserContractsService sysUserContractsService;
	
    @ApiOperation(value = "查询学生最新协议")
    @GetMapping("/getLatest")
    @PreAuthorize("@pcs.hasPermissions('sysUserContracts/getLatest')")
	public HttpResponseResult<SysUserContracts> getLatest(Long userId) {
		
		SysUserContracts sysUserContracts = sysUserContractsService.getLatestUserContract(userId);

		if(sysUserContracts == null){
			return failed("该学员尚未签署协议");
		}

		return succeed(sysUserContracts);
	}

}
