package com.red.circle.console.app.command.admin;

import com.red.circle.console.app.convertor.UserAppConvertor;
import com.red.circle.console.app.dto.cmd.admin.AccountInfoCmd;
import com.red.circle.console.infra.database.rds.entity.admin.User;
import com.red.circle.console.infra.database.rds.service.admin.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 修改账号信息.
 *
 * @author pengliang on 2023/5/12
 */
@Component
@RequiredArgsConstructor
public class AccountInfoUpdateCmdExe {

  private final UserService userService;
  private final UserAppConvertor userAppConvertor;

  public void execute(AccountInfoCmd cmd) {
    User user = userAppConvertor.toUser(cmd);
    user.setId(cmd.requiredReqUserId().intValue());
    userService.updateSelectiveById(user);
  }

}
