diff --git a/src/main/java/com/psg/dlsysinfo/dl_sysinfo_server/dto/UserDTO.java b/src/main/java/com/psg/dlsysinfo/dl_sysinfo_server/dto/UserDTO.java index 9e3a2a1..8c9b13c 100644 --- a/src/main/java/com/psg/dlsysinfo/dl_sysinfo_server/dto/UserDTO.java +++ b/src/main/java/com/psg/dlsysinfo/dl_sysinfo_server/dto/UserDTO.java @@ -1,5 +1,8 @@ package com.psg.dlsysinfo.dl_sysinfo_server.dto; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + +@JsonIgnoreProperties(ignoreUnknown = true) public class UserDTO { private Long id; private String username; @@ -9,6 +12,7 @@ public class UserDTO { private String email; private String role; private String clientIdentifier; + private Long clientId; // Accept clientId from frontend private String clientName; private boolean enabled; @@ -37,6 +41,7 @@ public class UserDTO { public String getEmail() { return email; } public String getRole() { return role; } public String getClientIdentifier() { return clientIdentifier; } + public Long getClientId() { return clientId; } public boolean isEnabled() { return enabled; } public String getClientName() { return clientName; } @@ -49,6 +54,7 @@ public class UserDTO { public void setEmail(String email) { this.email = email; } public void setRole(String role) { this.role = role; } public void setClientIdentifier(String clientIdentifier) { this.clientIdentifier = clientIdentifier; } + public void setClientId(Long clientId) { this.clientId = clientId; } public void setEnabled(boolean enabled) { this.enabled = enabled; } public void setClientName(String clientName) { this.clientName = clientName; } } diff --git a/src/main/java/com/psg/dlsysinfo/dl_sysinfo_server/service/UserService.java b/src/main/java/com/psg/dlsysinfo/dl_sysinfo_server/service/UserService.java index 5aa4213..67f9385 100644 --- a/src/main/java/com/psg/dlsysinfo/dl_sysinfo_server/service/UserService.java +++ b/src/main/java/com/psg/dlsysinfo/dl_sysinfo_server/service/UserService.java @@ -196,8 +196,12 @@ public class UserService implements CustomUserDetailsService { // Update enabled state user.setEnabled(userDto.isEnabled()); - // Update client if provided - if (userDto.getClientIdentifier() != null) { + // Update client if provided (support both clientId and clientIdentifier) + if (userDto.getClientId() != null) { + Client client = clientRepository.findById(userDto.getClientId()) + .orElseThrow(() -> new IllegalArgumentException("Client not found with id: " + userDto.getClientId())); + user.setClient(client); + } else if (userDto.getClientIdentifier() != null) { Client client = clientRepository.findByClientIdentifier(userDto.getClientIdentifier()) .orElseThrow(() -> new IllegalArgumentException("Client not found with identifier: " + userDto.getClientIdentifier())); user.setClient(client);