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.UserCmd;
import com.red.circle.console.infra.database.rds.entity.admin.User;
import com.red.circle.console.infra.database.rds.service.admin.UserRoleService;
import com.red.circle.console.infra.database.rds.service.admin.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 修改用户.
 *
 * @author pengliang on 2023/5/15
 */
@Component
@RequiredArgsConstructor
public class UserUpdateCmdExe {

  private final UserService userService;
  private final UserRoleService userRoleService;
  private final UserAppConvertor userAppConvertor;

  public void execute(UserCmd cmd) {
    User user = userAppConvertor.toUser(cmd);
    userService.updateSelectiveById(user);
    userRoleService.saveUserRoles(cmd.getId(), cmd.getRoleIds());
  }

}
