fix: member editing unimplemented
This commit is contained in:
@@ -44,14 +44,6 @@ public class CredentialController {
|
||||
);
|
||||
}
|
||||
|
||||
@GetMapping("/test/{userId}")
|
||||
public ResponseEntity<String> test(@PathVariable("userId") UUID userId) {
|
||||
CorePrincipal principal = (CorePrincipal) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
return ResponseEntity.ok(
|
||||
userId.equals(principal.getUserId()) ? "OK" : "NO"
|
||||
);
|
||||
}
|
||||
|
||||
@GetMapping("/user/{userId}")
|
||||
public ResponseEntity<List<CredentialDto>> getByUserId(@PathVariable("userId") UUID userId) {
|
||||
CorePrincipal principal = (CorePrincipal) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
@@ -85,11 +77,24 @@ public class CredentialController {
|
||||
}
|
||||
return ResponseEntity.ok(
|
||||
CredentialMapper.toDto(
|
||||
credentialService.update(credentialId, CredentialMapper.toEntity(dto))
|
||||
credentialService.update(credentialId, CredentialMapper.toEntity(dto))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@PutMapping("/{credential_id}/full")
|
||||
@PreAuthorize("hasRole('ADMIN')")
|
||||
public ResponseEntity<CredentialDto> updateFull(
|
||||
@PathVariable("credential_id") UUID credentialId,
|
||||
@RequestBody CredentialDto dto
|
||||
) {
|
||||
return ResponseEntity.ok(
|
||||
CredentialMapper.toDto(
|
||||
credentialService.update(credentialId, CredentialMapper.toEntity(dto))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@GetMapping("/{service_id}/{user_id}/status")
|
||||
public ResponseEntity<Byte> getStatus(@PathVariable("user_id") UUID userId, @PathVariable("service_id") Byte serviceId) {
|
||||
return ResponseEntity.ok(credentialService.getStatus(userId, serviceId));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.miarma.backend.huertos.client;
|
||||
|
||||
import net.miarma.backend.huertos.dto.MemberDto;
|
||||
import net.miarma.backend.huertos.dto.RequestMetadataDto;
|
||||
import net.miarma.backend.huertos.model.RequestMetadata;
|
||||
import net.miarma.backend.huertos.util.UsernameGenerator;
|
||||
@@ -66,7 +67,6 @@ public class HuertosWebClient {
|
||||
}
|
||||
|
||||
public UserWithCredentialDto createUser(RequestMetadataDto metadataDto) {
|
||||
// 1. Crear el usuario
|
||||
CreateUserDto userDto = new CreateUserDto(metadataDto.displayName(), null);
|
||||
HttpEntity<CreateUserDto> userRequestEntity = new HttpEntity<>(userDto);
|
||||
|
||||
@@ -116,6 +116,34 @@ public class HuertosWebClient {
|
||||
return new UserWithCredentialDto(createdUser, createdCred);
|
||||
}
|
||||
|
||||
public void updateUser(UUID userId, UserWithCredentialDto dto) {
|
||||
HttpEntity<UserDto> userRequestEntity = new HttpEntity<>(dto.user());
|
||||
ResponseEntity<Void> userResponse = restTemplate.exchange(
|
||||
coreUrl + "/users/{user_id}",
|
||||
HttpMethod.PUT,
|
||||
userRequestEntity,
|
||||
Void.class,
|
||||
userId
|
||||
);
|
||||
|
||||
if (!userResponse.getStatusCode().is2xxSuccessful()) {
|
||||
handleError(userResponse);
|
||||
}
|
||||
|
||||
HttpEntity<CredentialDto> credRequestEntity = new HttpEntity<>(dto.account());
|
||||
ResponseEntity<Void> credResponse = restTemplate.exchange(
|
||||
coreUrl + "/credentials/{credential_id}/full",
|
||||
HttpMethod.PUT,
|
||||
credRequestEntity,
|
||||
Void.class,
|
||||
dto.account().getCredentialId()
|
||||
);
|
||||
|
||||
if (!credResponse.getStatusCode().is2xxSuccessful()) {
|
||||
handleError(credResponse);
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteUser(UUID userId) {
|
||||
ResponseEntity<Void> response = restTemplate.exchange(
|
||||
coreUrl + "/users/{user_id}",
|
||||
|
||||
@@ -122,4 +122,13 @@ public class MemberController {
|
||||
public ResponseEntity<MemberDto> getByDni(@PathVariable("dni") String dni) {
|
||||
return ResponseEntity.ok(memberService.getByDni(dni));
|
||||
}
|
||||
|
||||
@PutMapping("/{user_id:[0-9a-fA-F\\-]{36}}")
|
||||
@PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')")
|
||||
public ResponseEntity<MemberDto> update(
|
||||
@PathVariable("user_id") UUID userId,
|
||||
@RequestBody MemberDto changes
|
||||
) {
|
||||
return ResponseEntity.ok(memberService.update(userId, changes));
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,10 @@
|
||||
import net.miarma.backend.huertos.mapper.UserMetadataMapper;
|
||||
import net.miarma.backend.huertos.mapper.IncomeMapper;
|
||||
import net.miarma.backend.huertos.mapper.view.VIncomesWithInfoMapper;
|
||||
import net.miarma.backend.huertos.model.UserMetadata;
|
||||
import net.miarma.backend.huertos.security.NameCensorer;
|
||||
import net.miarma.backlib.dto.CredentialDto;
|
||||
import net.miarma.backlib.dto.UserDto;
|
||||
import net.miarma.backlib.dto.UserWithCredentialDto;
|
||||
import net.miarma.backlib.exception.NotFoundException;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
@@ -199,4 +202,14 @@
|
||||
.map(DropdownDtoMapper::toDto)
|
||||
.toList();
|
||||
}
|
||||
|
||||
public MemberDto update(UUID userId, MemberDto changes) {
|
||||
try {
|
||||
huertosWebClient.updateUser(userId, new UserWithCredentialDto(changes.user(), changes.account()));
|
||||
metadataService.update(userId, UserMetadataMapper.fromDto(changes.metadata()));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("No se pudo actualizar el socio");
|
||||
}
|
||||
return changes;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ public class UserMetadataService {
|
||||
if (changes.getType() != null) metadata.setType(changes.getType());
|
||||
if (changes.getRole() != null) metadata.setRole(changes.getRole());
|
||||
if (changes.getNotes() != null) metadata.setNotes(changes.getNotes());
|
||||
if (changes.getAssignedAt() != null) metadata.setAssignedAt(changes.getAssignedAt());
|
||||
metadata.setAssignedAt(changes.getAssignedAt());
|
||||
if (changes.getDeactivatedAt() != null) metadata.setDeactivatedAt(changes.getDeactivatedAt());
|
||||
|
||||
return repository.save(metadata);
|
||||
|
||||
Reference in New Issue
Block a user