package com.miaxis.app.controller.wx;

import com.miaxis.common.constant.Constants;
import com.miaxis.common.core.controller.BaseController;
import com.miaxis.common.core.domain.Response;
import com.miaxis.common.core.domain.entity.UserInfo;
import com.miaxis.common.utils.SecurityUtils;
import com.miaxis.user.service.IUserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequiredArgsConstructor
@RequestMapping(Constants.STUDENT_PREFIX+"/user")
@Api(tags = {"【H5-用户信息】"})
@Slf4j
public class UserInfoController extends BaseController {

    @Autowired
    private IUserInfoService userInfoService;



    @GetMapping(value = "/info")
    @ApiOperation("获取用户信息")
    public Response<UserInfo> getInfo(){
        Long userId  = SecurityUtils.getLoginUser().getStudent().getId();
        return Response.success(userInfoService.getById(userId));
    }


    @PutMapping(value = "/realname")
    @ApiOperation("更新用户信息真实姓名")
    public Response updaterealname(String  realName){
        Long userId  = SecurityUtils.getLoginUser().getStudent().getId();
        UserInfo userInfo = userInfoService.getById(userId);
        userInfo.setRealName(realName);
        return Response.success(userInfoService.updateById(userInfo));
    }











}
