Added ambiguity to accepting PUT updates from admin end.
All checks were successful
Build & Deploy Backend / build (push) Successful in 51s
Build & Deploy Backend / deploy (push) Successful in 31s

This commit is contained in:
2025-10-29 12:03:24 +08:00
parent b0e1928ca3
commit 89c88d6de9
2 changed files with 12 additions and 2 deletions

View File

@@ -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; }
}

View File

@@ -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);