package com.ym.mec.collectfee.controller;


import com.ym.mec.collectfee.common.web.BaseController;
import com.ym.mec.collectfee.entity.ApplyInfo;
import com.ym.mec.collectfee.service.ApplyInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController()
@RequestMapping("user")
@Api("用户服务")
public class UserController extends BaseController {

    @Autowired
    private ApplyInfoService applyInfoService;


    /**
     * 查询用户详情
     * @param phone
     * @param clazzId
     * @return
     */
    @GetMapping("/getUserDetailByPhone")
    @ApiOperation(value = "根据乐团编号、用户手机，查询用户详情")
    @ApiImplicitParams({ @ApiImplicitParam(name = "phone", value = "用户手机", required = true, dataType = "String"),
            @ApiImplicitParam(name = "clazzId", value = "乐团编号", required = true, dataType = "Integer")})
    public Object getUserDetailByPhone(String phone,Integer clazzId){
        if(StringUtils.isEmpty(phone) || clazzId == null){
            return failed("参数校验异常");
        }
        ApplyInfo userByPhone = applyInfoService.findUserByPhone(phone, clazzId);
        return succeed(userByPhone);
    }

    /**
     * 用户报名
     * @param applyInfo
     * @return
     */
    @ApiOperation(value = "学生报名乐团")
    @PostMapping("/userApply")
    public Object userApply(ApplyInfo applyInfo){
        if(applyInfo != null){
            applyInfoService.insert(applyInfo);
            return succeed();
        }
        return failed();
    }

}
