Compare commits

5 Commits

Author SHA1 Message Date
Jose
39d75aecf9 add: pastes entity, controller and service 2026-03-05 18:37:49 +01:00
Jose
6949d8e083 fix: cache evict when updating 2026-03-04 22:55:07 +01:00
Jose
db27bcc1f7 fix: member editing unimplemented 2026-03-04 22:10:45 +01:00
Jose
e0807e4539 Merge remote-tracking branch 'origin/dev' into dev 2026-02-24 02:40:44 +01:00
Jose
fbdaa35087 Add: complete MPaste service rewritten in Spring 2026-02-24 02:40:31 +01:00
9 changed files with 82 additions and 15 deletions

View File

@@ -6,5 +6,9 @@ cd ..
cd huertos/ cd huertos/
mvn clean package mvn clean package
cd .. cd ..
cd mpaste/
mvn clean package
cd ..
scp core/target/core-1.0.0.jar jomaa@10.0.0.254:/home/jomaa/transfer scp core/target/core-1.0.0.jar jomaa@10.0.0.254:/home/jomaa/transfer
scp huertos/target/huertos-1.0.0.jar jomaa@10.0.0.254:/home/jomaa/transfer scp huertos/target/huertos-1.0.0.jar jomaa@10.0.0.254:/home/jomaa/transfer
scp mpaste/target/mpaste-1.0.0.jar jomaa@10.0.0.254:/home/jomaa/transfer

View File

@@ -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}") @GetMapping("/user/{userId}")
public ResponseEntity<List<CredentialDto>> getByUserId(@PathVariable("userId") UUID userId) { public ResponseEntity<List<CredentialDto>> getByUserId(@PathVariable("userId") UUID userId) {
CorePrincipal principal = (CorePrincipal) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); CorePrincipal principal = (CorePrincipal) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
@@ -90,6 +82,19 @@ public class CredentialController {
); );
} }
@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") @GetMapping("/{service_id}/{user_id}/status")
public ResponseEntity<Byte> getStatus(@PathVariable("user_id") UUID userId, @PathVariable("service_id") Byte serviceId) { public ResponseEntity<Byte> getStatus(@PathVariable("user_id") UUID userId, @PathVariable("service_id") Byte serviceId) {
return ResponseEntity.ok(credentialService.getStatus(userId, serviceId)); return ResponseEntity.ok(credentialService.getStatus(userId, serviceId));

View File

@@ -1,5 +1,6 @@
package net.miarma.backend.huertos.client; 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.dto.RequestMetadataDto;
import net.miarma.backend.huertos.model.RequestMetadata; import net.miarma.backend.huertos.model.RequestMetadata;
import net.miarma.backend.huertos.util.UsernameGenerator; import net.miarma.backend.huertos.util.UsernameGenerator;
@@ -66,7 +67,6 @@ public class HuertosWebClient {
} }
public UserWithCredentialDto createUser(RequestMetadataDto metadataDto) { public UserWithCredentialDto createUser(RequestMetadataDto metadataDto) {
// 1. Crear el usuario
CreateUserDto userDto = new CreateUserDto(metadataDto.displayName(), null); CreateUserDto userDto = new CreateUserDto(metadataDto.displayName(), null);
HttpEntity<CreateUserDto> userRequestEntity = new HttpEntity<>(userDto); HttpEntity<CreateUserDto> userRequestEntity = new HttpEntity<>(userDto);
@@ -116,6 +116,34 @@ public class HuertosWebClient {
return new UserWithCredentialDto(createdUser, createdCred); 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) { public void deleteUser(UUID userId) {
ResponseEntity<Void> response = restTemplate.exchange( ResponseEntity<Void> response = restTemplate.exchange(
coreUrl + "/users/{user_id}", coreUrl + "/users/{user_id}",

View File

@@ -122,4 +122,13 @@ public class MemberController {
public ResponseEntity<MemberDto> getByDni(@PathVariable("dni") String dni) { public ResponseEntity<MemberDto> getByDni(@PathVariable("dni") String dni) {
return ResponseEntity.ok(memberService.getByDni(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));
}
} }

View File

@@ -8,9 +8,13 @@
import net.miarma.backend.huertos.mapper.UserMetadataMapper; import net.miarma.backend.huertos.mapper.UserMetadataMapper;
import net.miarma.backend.huertos.mapper.IncomeMapper; import net.miarma.backend.huertos.mapper.IncomeMapper;
import net.miarma.backend.huertos.mapper.view.VIncomesWithInfoMapper; 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.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.dto.UserWithCredentialDto;
import net.miarma.backlib.exception.NotFoundException; import net.miarma.backlib.exception.NotFoundException;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -199,4 +203,15 @@
.map(DropdownDtoMapper::toDto) .map(DropdownDtoMapper::toDto)
.toList(); .toList();
} }
@CacheEvict(value = "members", allEntries = true)
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;
}
} }

View File

@@ -92,7 +92,7 @@ public class UserMetadataService {
if (changes.getType() != null) metadata.setType(changes.getType()); if (changes.getType() != null) metadata.setType(changes.getType());
if (changes.getRole() != null) metadata.setRole(changes.getRole()); if (changes.getRole() != null) metadata.setRole(changes.getRole());
if (changes.getNotes() != null) metadata.setNotes(changes.getNotes()); 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()); if (changes.getDeactivatedAt() != null) metadata.setDeactivatedAt(changes.getDeactivatedAt());
return repository.save(metadata); return repository.save(metadata);

View File

@@ -36,14 +36,17 @@ public class PasteController {
} }
@GetMapping("/{paste_key}") @GetMapping("/{paste_key}")
public ResponseEntity<PasteDto.Response> getByKey(@PathVariable("paste_key") String pasteKey, @RequestBody PastePassword dto) { public ResponseEntity<PasteDto.Response> getByKey(
@PathVariable("paste_key") String pasteKey,
@RequestParam(value = "password", required = false) String password
) {
return ResponseEntity.ok( return ResponseEntity.ok(
PasteMapper.toResponse(pasteService.getByKey(pasteKey, dto.password())) PasteMapper.toResponse(pasteService.getByKey(pasteKey, password))
); );
} }
@PostMapping @PostMapping
public ResponseEntity<PasteDto.Response> create(PasteDto.Request request) { public ResponseEntity<PasteDto.Response> create(@RequestBody PasteDto.Request request) {
return ResponseEntity.ok( return ResponseEntity.ok(
PasteMapper.toResponse( PasteMapper.toResponse(
pasteService.create( pasteService.create(

View File

@@ -22,7 +22,7 @@ public class Paste {
@Transient @Transient
private UUID ownerId; private UUID ownerId;
@Column(name = "paste_key", updatable = false, insertable = false, unique = true, nullable = false) @Column(name = "paste_key", updatable = false, unique = true, nullable = false)
private String pasteKey; private String pasteKey;
@Column(nullable = false) @Column(nullable = false)

View File

@@ -3,6 +3,7 @@ package net.miarma.backend.mpaste.service;
import jakarta.transaction.Transactional; import jakarta.transaction.Transactional;
import net.miarma.backend.mpaste.model.Paste; import net.miarma.backend.mpaste.model.Paste;
import net.miarma.backend.mpaste.repository.PasteRepository; import net.miarma.backend.mpaste.repository.PasteRepository;
import net.miarma.backend.mpaste.util.PasteKeyGenerator;
import net.miarma.backend.mpaste.validation.PasteValidator; import net.miarma.backend.mpaste.validation.PasteValidator;
import net.miarma.backlib.exception.ForbiddenException; import net.miarma.backlib.exception.ForbiddenException;
import net.miarma.backlib.exception.NotFoundException; import net.miarma.backlib.exception.NotFoundException;
@@ -62,6 +63,8 @@ public class PasteService {
public Paste create(Paste paste) { public Paste create(Paste paste) {
PasteValidator.validate(paste); PasteValidator.validate(paste);
paste.setPasteId(UUID.randomUUID());
paste.setPasteKey(PasteKeyGenerator.generate(6));
return pasteRepository.save(paste); return pasteRepository.save(paste);
} }