Added ambiguity to accepting PUT updates from admin end.
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
package com.psg.dlsysinfo.dl_sysinfo_server.dto;
|
package com.psg.dlsysinfo.dl_sysinfo_server.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
public class UserDTO {
|
public class UserDTO {
|
||||||
private Long id;
|
private Long id;
|
||||||
private String username;
|
private String username;
|
||||||
@@ -9,6 +12,7 @@ public class UserDTO {
|
|||||||
private String email;
|
private String email;
|
||||||
private String role;
|
private String role;
|
||||||
private String clientIdentifier;
|
private String clientIdentifier;
|
||||||
|
private Long clientId; // Accept clientId from frontend
|
||||||
private String clientName;
|
private String clientName;
|
||||||
private boolean enabled;
|
private boolean enabled;
|
||||||
|
|
||||||
@@ -37,6 +41,7 @@ public class UserDTO {
|
|||||||
public String getEmail() { return email; }
|
public String getEmail() { return email; }
|
||||||
public String getRole() { return role; }
|
public String getRole() { return role; }
|
||||||
public String getClientIdentifier() { return clientIdentifier; }
|
public String getClientIdentifier() { return clientIdentifier; }
|
||||||
|
public Long getClientId() { return clientId; }
|
||||||
public boolean isEnabled() { return enabled; }
|
public boolean isEnabled() { return enabled; }
|
||||||
public String getClientName() { return clientName; }
|
public String getClientName() { return clientName; }
|
||||||
|
|
||||||
@@ -49,6 +54,7 @@ public class UserDTO {
|
|||||||
public void setEmail(String email) { this.email = email; }
|
public void setEmail(String email) { this.email = email; }
|
||||||
public void setRole(String role) { this.role = role; }
|
public void setRole(String role) { this.role = role; }
|
||||||
public void setClientIdentifier(String clientIdentifier) { this.clientIdentifier = clientIdentifier; }
|
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 setEnabled(boolean enabled) { this.enabled = enabled; }
|
||||||
public void setClientName(String clientName) { this.clientName = clientName; }
|
public void setClientName(String clientName) { this.clientName = clientName; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -196,8 +196,12 @@ public class UserService implements CustomUserDetailsService {
|
|||||||
// Update enabled state
|
// Update enabled state
|
||||||
user.setEnabled(userDto.isEnabled());
|
user.setEnabled(userDto.isEnabled());
|
||||||
|
|
||||||
// Update client if provided
|
// Update client if provided (support both clientId and clientIdentifier)
|
||||||
if (userDto.getClientIdentifier() != null) {
|
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())
|
Client client = clientRepository.findByClientIdentifier(userDto.getClientIdentifier())
|
||||||
.orElseThrow(() -> new IllegalArgumentException("Client not found with identifier: " + userDto.getClientIdentifier()));
|
.orElseThrow(() -> new IllegalArgumentException("Client not found with identifier: " + userDto.getClientIdentifier()));
|
||||||
user.setClient(client);
|
user.setClient(client);
|
||||||
|
|||||||
Reference in New Issue
Block a user