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.common.utils.StringUtils;
import com.miaxis.user.dto.UserInfoUpdateDto;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequiredArgsConstructor
@RequestMapping(Constants.STUDENT_PREFIX+"/xcx/user")
@Api(tags = {"【小程序-用户信息】"})
@Slf4j
public class XcXUserInfoController 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("更新成功");
    }











}
