package com.miaxis.app.controller.user;

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.SysUser;
import com.miaxis.common.core.domain.entity.UserInfo;
import com.miaxis.common.core.page.ResponsePageInfo;
import com.miaxis.common.utils.SecurityUtils;
import com.miaxis.common.utils.StringUtils;
import com.miaxis.user.dto.UserDto;
import com.miaxis.user.dto.UserInfoUpdateDto;
import com.miaxis.user.service.IUserInfoService;
import com.miaxis.user.vo.UserVo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 【用户信息】Controller
 *
 * @author wwl
 * @date 2020-12-23
 */
@RestController
@RequestMapping(Constants.STUDENT_PREFIX+"/user/info")
@Api(tags={"【小程序-普通用户信息】"})
public class UserInfoController extends BaseController{

    @Autowired
    private IUserInfoService userInfoService;

    /**
     * 修改用户信息
     */
    @PostMapping
    @ApiOperation("修改用户信息")
    public Response edit(@RequestBody UserInfoUpdateDto userInfoUpdateDto){

        UserInfo userInfo= SecurityUtils.getLoginUser().getStudent();
        if (userInfo!= null){
            if (!StringUtils.isEmpty(userInfoUpdateDto.getHeadImage())){
                userInfo.setHeadImage(userInfoUpdateDto.getHeadImage());
            }
            if (!StringUtils.isEmpty(userInfoUpdateDto.getNickName())){
                userInfo.setNickName(userInfoUpdateDto.getNickName());
            }
        }
        //更新数据库
        userInfoService.updateById(userInfo);
        return Response.success("更新成功");
    }




}
