From 3573f862eba1af73c110490999b0ae240e2f681c Mon Sep 17 00:00:00 2001 From: Jose Date: Sat, 7 Mar 2026 00:03:50 +0100 Subject: [PATCH] moved: huertos to its own repo --- build-upload.sh | 12 +- cine/.gitignore | 1 - cine/cine.iml | 9 - cine/pom.xml | 59 ----- huertos/.gitignore | 1 - huertos/huertos.iml | 9 - huertos/pom.xml | 102 -------- .../backend/huertos/HuertosApplication.java | 16 -- .../huertos/client/CoreAuthClient.java | 73 ------ .../huertos/client/HuertosWebClient.java | 219 ------------------ .../backend/huertos/config/CacheConfig.java | 26 --- .../huertos/config/RestTemplateConfig.java | 48 ---- .../huertos/config/SecurityConfig.java | 70 ------ .../controller/AnnouncementController.java | 69 ------ .../huertos/controller/BalanceController.java | 47 ---- .../huertos/controller/ExpenseController.java | 74 ------ .../controller/HuertosAuthController.java | 41 ---- .../huertos/controller/IncomeController.java | 114 --------- .../huertos/controller/MemberController.java | 134 ----------- .../huertos/controller/RequestController.java | 152 ------------ .../backend/huertos/dto/AnnouncementDto.java | 89 ------- .../backend/huertos/dto/BalanceDto.java | 43 ---- .../backend/huertos/dto/DropdownDto.java | 6 - .../backend/huertos/dto/ExpenseDto.java | 130 ----------- .../huertos/dto/HuertosLoginResponse.java | 12 - .../miarma/backend/huertos/dto/IncomeDto.java | 139 ----------- .../miarma/backend/huertos/dto/MemberDto.java | 8 - .../backend/huertos/dto/MemberProfileDto.java | 20 -- .../backend/huertos/dto/RequestCountDto.java | 5 - .../backend/huertos/dto/RequestDto.java | 113 --------- .../huertos/dto/RequestMetadataDto.java | 20 -- .../huertos/dto/RequestWithMetadataDto.java | 15 -- .../backend/huertos/dto/UserMetadataDto.java | 106 --------- .../huertos/dto/WaitlistCensoredDto.java | 13 -- .../dto/view/VBalanceWithTotalsDto.java | 79 ------- .../huertos/dto/view/VIncomesWithInfoDto.java | 89 ------- .../huertos/mapper/AnnouncementMapper.java | 31 --- .../backend/huertos/mapper/BalanceMapper.java | 29 --- .../huertos/mapper/DropdownDtoMapper.java | 10 - .../backend/huertos/mapper/ExpenseMapper.java | 34 --- .../backend/huertos/mapper/IncomeMapper.java | 34 --- .../backend/huertos/mapper/RequestMapper.java | 44 ---- .../huertos/mapper/RequestMetadataMapper.java | 50 ---- .../mapper/RequestWithMetadataMapper.java | 19 -- .../huertos/mapper/UserMetadataMapper.java | 39 ---- .../mapper/view/VBalanceWithTotalsMapper.java | 20 -- .../mapper/view/VIncomesWithInfoMapper.java | 21 -- .../backend/huertos/model/Announcement.java | 108 --------- .../miarma/backend/huertos/model/Balance.java | 58 ----- .../miarma/backend/huertos/model/Expense.java | 109 --------- .../miarma/backend/huertos/model/Income.java | 133 ----------- .../miarma/backend/huertos/model/Request.java | 76 ------ .../huertos/model/RequestMetadata.java | 199 ---------------- .../backend/huertos/model/UserMetadata.java | 157 ------------- .../model/view/VBalanceWithTotals.java | 72 ------ .../huertos/model/view/VIncomesWithInfo.java | 87 ------- .../repository/AnnouncementRepository.java | 7 - .../huertos/repository/BalanceRepository.java | 8 - .../huertos/repository/ExpenseRepository.java | 6 - .../huertos/repository/IncomeRepository.java | 7 - .../repository/RequestMetadataRepository.java | 7 - .../huertos/repository/RequestRepository.java | 18 -- .../repository/UserMetadataRepository.java | 10 - .../view/VBalanceWithTotalsRepository.java | 12 - .../view/VIncomesWithInfoRepository.java | 12 - .../huertos/security/HuertosJwtFilter.java | 63 ----- .../huertos/security/HuertosPrincipal.java | 65 ------ .../huertos/security/NameCensorer.java | 36 --- .../huertos/service/AnnouncementService.java | 71 ------ .../huertos/service/BalanceService.java | 62 ----- .../huertos/service/CoreAuthService.java | 60 ----- .../huertos/service/ExpenseService.java | 96 -------- .../huertos/service/IncomeService.java | 128 ---------- .../huertos/service/MemberService.java | 217 ----------------- .../service/RequestAcceptanceService.java | 140 ----------- .../huertos/service/RequestService.java | 140 ----------- .../huertos/service/UserMetadataService.java | 120 ---------- .../view/VBalanceWithTotalsService.java | 24 -- .../service/view/VIncomesWithInfoService.java | 44 ---- .../huertos/util/UsernameGenerator.java | 9 - .../huertos/validation/DniValidator.java | 66 ------ .../huertos/validation/RequestValidator.java | 90 ------- .../src/main/resources/application-dev.yml | 28 --- .../src/main/resources/application-prod.yml | 27 --- huertos/src/main/resources/application.yml | 25 -- pom.xml | 2 - 86 files changed, 4 insertions(+), 5089 deletions(-) delete mode 100644 cine/.gitignore delete mode 100644 cine/cine.iml delete mode 100644 cine/pom.xml delete mode 100644 huertos/.gitignore delete mode 100644 huertos/huertos.iml delete mode 100644 huertos/pom.xml delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/HuertosApplication.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/client/CoreAuthClient.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/client/HuertosWebClient.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/config/CacheConfig.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/config/RestTemplateConfig.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/config/SecurityConfig.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/controller/AnnouncementController.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/controller/BalanceController.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/controller/ExpenseController.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/controller/HuertosAuthController.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/controller/IncomeController.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/controller/MemberController.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/controller/RequestController.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/dto/AnnouncementDto.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/dto/BalanceDto.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/dto/DropdownDto.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/dto/ExpenseDto.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/dto/HuertosLoginResponse.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/dto/IncomeDto.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/dto/MemberDto.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/dto/MemberProfileDto.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/dto/RequestCountDto.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/dto/RequestDto.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/dto/RequestMetadataDto.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/dto/RequestWithMetadataDto.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/dto/UserMetadataDto.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/dto/WaitlistCensoredDto.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/dto/view/VBalanceWithTotalsDto.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/dto/view/VIncomesWithInfoDto.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/mapper/AnnouncementMapper.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/mapper/BalanceMapper.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/mapper/DropdownDtoMapper.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/mapper/ExpenseMapper.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/mapper/IncomeMapper.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/mapper/RequestMapper.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/mapper/RequestMetadataMapper.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/mapper/RequestWithMetadataMapper.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/mapper/UserMetadataMapper.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/mapper/view/VBalanceWithTotalsMapper.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/mapper/view/VIncomesWithInfoMapper.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/model/Announcement.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/model/Balance.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/model/Expense.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/model/Income.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/model/Request.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/model/RequestMetadata.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/model/UserMetadata.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/model/view/VBalanceWithTotals.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/model/view/VIncomesWithInfo.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/repository/AnnouncementRepository.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/repository/BalanceRepository.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/repository/ExpenseRepository.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/repository/IncomeRepository.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/repository/RequestMetadataRepository.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/repository/RequestRepository.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/repository/UserMetadataRepository.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/repository/view/VBalanceWithTotalsRepository.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/repository/view/VIncomesWithInfoRepository.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/security/HuertosJwtFilter.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/security/HuertosPrincipal.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/security/NameCensorer.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/service/AnnouncementService.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/service/BalanceService.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/service/CoreAuthService.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/service/ExpenseService.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/service/IncomeService.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/service/MemberService.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/service/RequestAcceptanceService.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/service/RequestService.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/service/UserMetadataService.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/service/view/VBalanceWithTotalsService.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/service/view/VIncomesWithInfoService.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/util/UsernameGenerator.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/validation/DniValidator.java delete mode 100644 huertos/src/main/java/net/miarma/backend/huertos/validation/RequestValidator.java delete mode 100644 huertos/src/main/resources/application-dev.yml delete mode 100644 huertos/src/main/resources/application-prod.yml delete mode 100644 huertos/src/main/resources/application.yml diff --git a/build-upload.sh b/build-upload.sh index 35d21c2..4277fa5 100755 --- a/build-upload.sh +++ b/build-upload.sh @@ -1,14 +1,10 @@ #!/bin/bash -cd core/ +cd core/ || exit mvn clean package cd .. -cd huertos/ +cd mpaste/ || exit mvn clean package cd .. -cd mpaste/ -mvn clean package -cd .. -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 mpaste/target/mpaste-1.0.0.jar jomaa@10.0.0.254:/home/jomaa/transfer \ No newline at end of file +scp core/target/core-*.jar jomaa@10.0.0.254:/home/jomaa/transfer +scp mpaste/target/mpaste-*.jar jomaa@10.0.0.254:/home/jomaa/transfer \ No newline at end of file diff --git a/cine/.gitignore b/cine/.gitignore deleted file mode 100644 index b83d222..0000000 --- a/cine/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/target/ diff --git a/cine/cine.iml b/cine/cine.iml deleted file mode 100644 index 68a9707..0000000 --- a/cine/cine.iml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/cine/pom.xml b/cine/pom.xml deleted file mode 100644 index e33e655..0000000 --- a/cine/pom.xml +++ /dev/null @@ -1,59 +0,0 @@ - - 4.0.0 - - net.miarma - backend - 1.0.0 - - cine - - - - gitea - https://git.miarma.net/api/packages/Gallardo7761/maven - - - - - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-data-jpa - - - org.springframework.boot - spring-boot-starter-security - - - org.mariadb.jdbc - mariadb-java-client - runtime - - - - - io.jsonwebtoken - jjwt-api - 0.11.5 - - - io.jsonwebtoken - jjwt-impl - 0.11.5 - runtime - - - io.jsonwebtoken - jjwt-jackson - 0.11.5 - runtime - - - - \ No newline at end of file diff --git a/huertos/.gitignore b/huertos/.gitignore deleted file mode 100644 index b83d222..0000000 --- a/huertos/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/target/ diff --git a/huertos/huertos.iml b/huertos/huertos.iml deleted file mode 100644 index 68a9707..0000000 --- a/huertos/huertos.iml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/huertos/pom.xml b/huertos/pom.xml deleted file mode 100644 index 4f9636b..0000000 --- a/huertos/pom.xml +++ /dev/null @@ -1,102 +0,0 @@ - - 4.0.0 - - net.miarma - backend - 1.0.0 - - huertos - - - 25 - 25 - - - - - gitea - https://git.miarma.net/api/packages/Gallardo7761/maven - - - - - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-data-jpa - - - org.springframework.boot - spring-boot-starter-security - - - org.mariadb.jdbc - mariadb-java-client - runtime - - - org.springframework.boot - spring-boot-http-client - 4.0.1 - compile - - - - org.springframework.boot - spring-boot-starter-cache - - - com.github.ben-manes.caffeine - caffeine - - - - io.jsonwebtoken - jjwt-api - 0.11.5 - - - io.jsonwebtoken - jjwt-impl - 0.11.5 - runtime - - - io.jsonwebtoken - jjwt-jackson - 0.11.5 - runtime - - - net.miarma - backlib - 1.1.0 - compile - - - - - - - org.springframework.boot - spring-boot-maven-plugin - ${spring.boot.version} - - - - repackage - - - - - - - - - \ No newline at end of file diff --git a/huertos/src/main/java/net/miarma/backend/huertos/HuertosApplication.java b/huertos/src/main/java/net/miarma/backend/huertos/HuertosApplication.java deleted file mode 100644 index 435b0d2..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/HuertosApplication.java +++ /dev/null @@ -1,16 +0,0 @@ -package net.miarma.backend.huertos; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.cache.annotation.EnableCaching; - -@EnableCaching -@SpringBootApplication(scanBasePackages = { - "net.miarma.backend.huertos", - "net.miarma.backlib" -}) -public class HuertosApplication { - public static void main(String[] args) { - SpringApplication.run(HuertosApplication.class, args); - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/client/CoreAuthClient.java b/huertos/src/main/java/net/miarma/backend/huertos/client/CoreAuthClient.java deleted file mode 100644 index 1808fbc..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/client/CoreAuthClient.java +++ /dev/null @@ -1,73 +0,0 @@ -package net.miarma.backend.huertos.client; - -import net.miarma.backlib.dto.ApiErrorDto; -import net.miarma.backlib.dto.LoginRequest; -import net.miarma.backlib.dto.LoginResponse; -import net.miarma.backlib.exception.*; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.*; -import org.springframework.stereotype.Component; -import org.springframework.web.client.HttpClientErrorException; -import org.springframework.web.client.HttpServerErrorException; -import org.springframework.web.client.RestTemplate; - -@Component -public class CoreAuthClient { - - private final RestTemplate restTemplate; - private final String coreUrl; - - public CoreAuthClient( - @Qualifier("authRestTemplate") RestTemplate restTemplate, - @Value("${core.url}") String coreUrl - ) { - this.restTemplate = restTemplate; - this.coreUrl = coreUrl; - } - - - public LoginResponse login(LoginRequest req) { - HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_JSON); - - HttpEntity requestEntity = new HttpEntity<>(req, headers); - - ResponseEntity response = restTemplate.exchange( - coreUrl + "/auth/login", - HttpMethod.POST, - requestEntity, - LoginResponse.class - ); - - if (!response.getStatusCode().is2xxSuccessful()) { - handleError(response); - } - - return response.getBody(); - } - - private void handleError(ResponseEntity response) { - HttpStatusCode statusCode = response.getStatusCode(); - - if (statusCode.equals(HttpStatus.UNAUTHORIZED)) { - throw new UnauthorizedException("Credenciales no válidas"); - } else if (statusCode.equals(HttpStatus.FORBIDDEN)) { - throw new ForbiddenException("Esa cuenta está desactivada"); - } else if (statusCode.equals(HttpStatus.NOT_FOUND)) { - throw new NotFoundException("No encontrado"); - } else if (statusCode.equals(HttpStatus.BAD_REQUEST)) { - throw new BadRequestException("Datos de solicitud faltantes"); - } else if (statusCode.equals(HttpStatus.CONFLICT)) { - throw new ConflictException("Ya existe"); - } else if (statusCode.equals(HttpStatus.UNPROCESSABLE_CONTENT)) { - throw new ValidationException("general", "Los datos no tienen formato válido"); - } else { - if (statusCode.is4xxClientError()) { - throw new BadRequestException(response.getBody().toString()); - } else { - throw new RuntimeException("Error desconocido"); - } - } - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/client/HuertosWebClient.java b/huertos/src/main/java/net/miarma/backend/huertos/client/HuertosWebClient.java deleted file mode 100644 index 427bf93..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/client/HuertosWebClient.java +++ /dev/null @@ -1,219 +0,0 @@ -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; -import net.miarma.backlib.dto.*; -import net.miarma.backlib.exception.*; -import net.miarma.backlib.security.PasswordGenerator; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.http.*; -import org.springframework.stereotype.Component; -import org.springframework.web.client.RestTemplate; -import tools.jackson.databind.ObjectMapper; - -import java.util.Arrays; -import java.util.List; -import java.util.UUID; - -@Component -public class HuertosWebClient { - - private final RestTemplate restTemplate; - private final String coreUrl; - private final ObjectMapper objectMapper; - - public HuertosWebClient(@Qualifier("secureRestTemplate") RestTemplate restTemplate, - @Value("${core.url}") String coreUrl, - ObjectMapper objectMapper) { - this.restTemplate = restTemplate; - this.coreUrl = coreUrl; - this.objectMapper = objectMapper; - } - - public UserWithCredentialDto getUserWithCredential(UUID userId, Byte serviceId) { - ResponseEntity response = restTemplate.exchange( - coreUrl + "/users/{user_id}/service/{service_id}", - HttpMethod.GET, - null, - UserWithCredentialDto.class, - userId, serviceId - ); - - if (!response.getStatusCode().is2xxSuccessful()) { - handleError(response); - } - - return response.getBody(); - } - - public List getAllUsersWithCredentials(Byte serviceId) { - ResponseEntity response = restTemplate.exchange( - coreUrl + "/users/service/{service_id}", - HttpMethod.GET, - null, - UserWithCredentialDto[].class, - serviceId - ); - - if (!response.getStatusCode().is2xxSuccessful()) { - handleError(response); - } - - UserWithCredentialDto[] arr = response.getBody(); - return arr == null ? List.of() : Arrays.asList(arr); - } - - public UserWithCredentialDto createUser(RequestMetadataDto metadataDto) { - CreateUserDto userDto = new CreateUserDto(metadataDto.displayName(), null); - HttpEntity userRequestEntity = new HttpEntity<>(userDto); - - ResponseEntity userResponse = restTemplate.exchange( - coreUrl + "/users", - HttpMethod.POST, - userRequestEntity, - UserDto.class - ); - - if (!userResponse.getStatusCode().is2xxSuccessful()) { - handleError(userResponse); - } - - UserDto createdUser = userResponse.getBody(); - if (createdUser == null) { - throw new RuntimeException("No se pudo crear al usuario"); - } - - CreateCredentialDto credDto = new CreateCredentialDto( - createdUser.getUserId(), - (byte) 1, - UsernameGenerator.generate(metadataDto.displayName(), metadataDto.memberNumber()), - metadataDto.email(), - PasswordGenerator.generate(8), - (byte) 1 - ); - - HttpEntity credRequestEntity = new HttpEntity<>(credDto); - - ResponseEntity credResponse = restTemplate.exchange( - coreUrl + "/credentials", - HttpMethod.POST, - credRequestEntity, - CredentialDto.class - ); - - if (!credResponse.getStatusCode().is2xxSuccessful()) { - handleError(credResponse); - } - - CredentialDto createdCred = credResponse.getBody(); - if (createdCred == null) { - throw new RuntimeException("No se pudo crear la cuenta del usuario"); - } - - return new UserWithCredentialDto(createdUser, createdCred); - } - - public void updateUser(UUID userId, UserWithCredentialDto dto) { - HttpEntity userRequestEntity = new HttpEntity<>(dto.user()); - ResponseEntity userResponse = restTemplate.exchange( - coreUrl + "/users/{user_id}", - HttpMethod.PUT, - userRequestEntity, - Void.class, - userId - ); - - if (!userResponse.getStatusCode().is2xxSuccessful()) { - handleError(userResponse); - } - - HttpEntity credRequestEntity = new HttpEntity<>(dto.account()); - ResponseEntity 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 response = restTemplate.exchange( - coreUrl + "/users/{user_id}", - HttpMethod.DELETE, - null, - Void.class, - userId - ); - - if (!response.getStatusCode().is2xxSuccessful()) { - if (response.getStatusCode() != HttpStatus.NOT_FOUND) { - handleError(response); - } - } - } - - public Byte getCredentialStatus(UUID userId, Byte serviceId) { - ResponseEntity response = restTemplate.exchange( - coreUrl + "/credentials/{service_id}/{user_id}/status", - HttpMethod.GET, - null, - Byte.class, - serviceId, userId - ); - - if (!response.getStatusCode().is2xxSuccessful()) { - handleError(response); - } - - return response.getBody(); - } - - public void updateCredentialStatus(UUID userId, Byte serviceId, Byte newStatus) { - ChangeStatusRequest req = new ChangeStatusRequest(newStatus); - HttpEntity requestEntity = new HttpEntity<>(req); - - ResponseEntity response = restTemplate.exchange( - coreUrl + "/credentials/{service_id}/{user_id}/status", - HttpMethod.PUT, - requestEntity, - Void.class, - serviceId, userId - ); - - if (!response.getStatusCode().is2xxSuccessful()) { - handleError(response); - } - } - - private void handleError(ResponseEntity response) { - HttpStatusCode statusCode = response.getStatusCode(); - - if (statusCode.equals(HttpStatus.UNAUTHORIZED)) { - throw new UnauthorizedException("Credenciales no válidas"); - } else if (statusCode.equals(HttpStatus.FORBIDDEN)) { - throw new ForbiddenException("Esa cuenta está desactivada"); - } else if (statusCode.equals(HttpStatus.NOT_FOUND)) { - throw new NotFoundException("No encontrado"); - } else if (statusCode.equals(HttpStatus.BAD_REQUEST)) { - throw new BadRequestException("Datos de solicitud faltantes"); - } else if (statusCode.equals(HttpStatus.CONFLICT)) { - throw new ConflictException("Ya existe"); - } else if (statusCode.equals(HttpStatus.UNPROCESSABLE_CONTENT)) { - throw new ValidationException("general", "Los datos no tienen formato válido"); - } else { - if (statusCode.is4xxClientError()) { - throw new BadRequestException(response.getBody().toString()); - } else { - throw new RuntimeException("Error desconocido"); - } - } - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/config/CacheConfig.java b/huertos/src/main/java/net/miarma/backend/huertos/config/CacheConfig.java deleted file mode 100644 index 07c1278..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/config/CacheConfig.java +++ /dev/null @@ -1,26 +0,0 @@ -package net.miarma.backend.huertos.config; - -import com.github.benmanes.caffeine.cache.Caffeine; -import org.springframework.cache.CacheManager; -import org.springframework.cache.caffeine.CaffeineCacheManager; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import java.util.concurrent.TimeUnit; - -@Configuration -public class CacheConfig { - @Bean - public CacheManager cacheManager() { - CaffeineCacheManager manager = new CaffeineCacheManager( - "members", "memberById", "waitlist", - "metadataByUserId", "metadataByMemberNumber", "metadataExists"); - manager.setCaffeine( - Caffeine.newBuilder() - .expireAfterWrite(10, TimeUnit.MINUTES) - .maximumSize(10_000) - ); - return manager; - } - -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/config/RestTemplateConfig.java b/huertos/src/main/java/net/miarma/backend/huertos/config/RestTemplateConfig.java deleted file mode 100644 index 73bbbea..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/config/RestTemplateConfig.java +++ /dev/null @@ -1,48 +0,0 @@ -package net.miarma.backend.huertos.config; - -import io.jsonwebtoken.io.IOException; -import net.miarma.backend.huertos.service.CoreAuthService; -import net.miarma.backlib.security.CoreAuthTokenHolder; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.http.client.ClientHttpRequestInterceptor; -import org.springframework.http.client.ClientHttpResponse; -import org.springframework.web.client.ResponseErrorHandler; -import org.springframework.web.client.RestTemplate; - -import java.util.ArrayList; -import java.util.List; - -@Configuration -public class RestTemplateConfig { - - @Bean - public RestTemplate authRestTemplate() { - RestTemplate restTemplate = new RestTemplate(); - restTemplate.setErrorHandler(new NoOpResponseErrorHandler()); - return restTemplate; - } - - @Bean - public RestTemplate secureRestTemplate(CoreAuthService coreAuthService) { - RestTemplate restTemplate = new RestTemplate(); - - restTemplate.getInterceptors().add((request, body, execution) -> { - String token = coreAuthService.getToken(); - request.getHeaders().setBearerAuth(token); - return execution.execute(request, body); - }); - - restTemplate.setErrorHandler(new NoOpResponseErrorHandler()); - - return restTemplate; - } - - public static class NoOpResponseErrorHandler implements ResponseErrorHandler { - @Override - public boolean hasError(ClientHttpResponse response) throws IOException { - return false; - } - } -} - diff --git a/huertos/src/main/java/net/miarma/backend/huertos/config/SecurityConfig.java b/huertos/src/main/java/net/miarma/backend/huertos/config/SecurityConfig.java deleted file mode 100644 index 2b3f704..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/config/SecurityConfig.java +++ /dev/null @@ -1,70 +0,0 @@ -package net.miarma.backend.huertos.config; - -import net.miarma.backend.huertos.security.HuertosJwtFilter; -import net.miarma.backlib.http.RestAccessDeniedHandler; -import net.miarma.backlib.http.RestAuthEntryPoint; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.config.Customizer; -import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.http.SessionCreationPolicy; -import org.springframework.security.web.SecurityFilterChain; -import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; -import org.springframework.web.cors.CorsConfigurationSource; - -import java.util.Optional; - -@Configuration -@EnableWebSecurity -@EnableMethodSecurity(prePostEnabled = true) -public class SecurityConfig { - - private final HuertosJwtFilter jwtFilter; - private final RestAuthEntryPoint authEntryPoint; - private final RestAccessDeniedHandler accessDeniedHandler; - private final CorsConfigurationSource corsConfigurationSource; - - public SecurityConfig( - HuertosJwtFilter jwtFilter, - RestAuthEntryPoint authEntryPoint, - RestAccessDeniedHandler accessDeniedHandler, - Optional corsConfigurationSource - ) { - this.jwtFilter = jwtFilter; - this.authEntryPoint = authEntryPoint; - this.accessDeniedHandler = accessDeniedHandler; - this.corsConfigurationSource = corsConfigurationSource.orElse(null); - } - - @Bean - public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { - if (corsConfigurationSource != null) { - http.cors(Customizer.withDefaults()); - } - - http - .csrf(csrf -> csrf.disable()) - .sessionManagement(sm -> sm.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) - .exceptionHandling(ex -> ex - .authenticationEntryPoint(authEntryPoint) - .accessDeniedHandler(accessDeniedHandler) - ) - .authorizeHttpRequests(auth -> auth - // PUBLICAS - .requestMatchers("/auth/login").permitAll() - .requestMatchers("/users/waitlist/limited").permitAll() - .requestMatchers("/requests").permitAll() - .requestMatchers("/users/latest-number").permitAll() - // PRIVADAS - .anyRequest().authenticated() - ); - - http.addFilterBefore(jwtFilter, UsernamePasswordAuthenticationFilter.class); - - return http.build(); - } -} - - diff --git a/huertos/src/main/java/net/miarma/backend/huertos/controller/AnnouncementController.java b/huertos/src/main/java/net/miarma/backend/huertos/controller/AnnouncementController.java deleted file mode 100644 index 2c183da..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/controller/AnnouncementController.java +++ /dev/null @@ -1,69 +0,0 @@ -package net.miarma.backend.huertos.controller; - -import net.miarma.backend.huertos.dto.AnnouncementDto; -import net.miarma.backend.huertos.mapper.AnnouncementMapper; -import net.miarma.backend.huertos.model.Announcement; -import net.miarma.backend.huertos.service.AnnouncementService; -import org.springframework.http.ResponseEntity; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.*; - -import java.util.List; -import java.util.Map; -import java.util.UUID; - -@RestController -@RequestMapping("/announcements") -public class AnnouncementController { - - private final AnnouncementService announcementService; - - public AnnouncementController(AnnouncementService announcementService) { - this.announcementService = announcementService; - } - - @GetMapping - public ResponseEntity> getAll() { - return ResponseEntity.ok( - announcementService.getAll() - .stream() - .map(AnnouncementMapper::toResponse) - .toList() - ); - } - - @GetMapping("/{announce_id}") - @PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')") - public ResponseEntity getById(@PathVariable("announce_id") UUID announcementId) { - Announcement announcement = announcementService.getById(announcementId); - return ResponseEntity.ok(AnnouncementMapper.toResponse(announcement)); - } - - @PutMapping("/{announce_id}") - @PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')") - public ResponseEntity update( - @PathVariable("announce_id") UUID announcementId, - @RequestBody AnnouncementDto.Request dto - ) { - return ResponseEntity.ok( - AnnouncementMapper.toResponse(announcementService.update(announcementId, AnnouncementMapper.toEntity(dto))) - ); - } - - @PostMapping - @PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')") - public ResponseEntity create(@RequestBody AnnouncementDto.Request dto) { - return ResponseEntity.ok( - AnnouncementMapper.toResponse( - announcementService.create( - AnnouncementMapper.toEntity(dto) - ))); - } - - @DeleteMapping("/{announce_id}") - @PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')") - public ResponseEntity> delete(@PathVariable("announce_id") UUID announcementId) { - announcementService.delete(announcementId); - return ResponseEntity.ok(Map.of("message", "Deleted announcement: " + announcementId)); - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/controller/BalanceController.java b/huertos/src/main/java/net/miarma/backend/huertos/controller/BalanceController.java deleted file mode 100644 index dbe20d6..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/controller/BalanceController.java +++ /dev/null @@ -1,47 +0,0 @@ -package net.miarma.backend.huertos.controller; - -import net.miarma.backend.huertos.dto.BalanceDto; -import net.miarma.backend.huertos.dto.view.VBalanceWithTotalsDto; -import net.miarma.backend.huertos.mapper.BalanceMapper; -import net.miarma.backend.huertos.mapper.view.VBalanceWithTotalsMapper; -import net.miarma.backend.huertos.model.Balance; -import net.miarma.backend.huertos.service.BalanceService; -import org.springframework.http.ResponseEntity; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("/balance") -public class BalanceController { - private final BalanceService balanceService; - - public BalanceController(BalanceService balanceService) { - this.balanceService = balanceService; - } - - @GetMapping - @PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')") - public ResponseEntity getBalance() { - Balance balance = balanceService.get(); - return ResponseEntity.ok(BalanceMapper.toDto(balance)); - } - - @GetMapping("/with-totals") - @PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')") - public ResponseEntity getWithTotals() { - return ResponseEntity.ok(VBalanceWithTotalsMapper.toDto(balanceService.getWithTotals())); - } - - @PostMapping - @PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')") - public ResponseEntity setBalance(BalanceDto dto) { - return ResponseEntity.ok( - BalanceMapper.toDto( - balanceService.create(BalanceMapper.toEntity(dto)) - ) - ); - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/controller/ExpenseController.java b/huertos/src/main/java/net/miarma/backend/huertos/controller/ExpenseController.java deleted file mode 100644 index 4aab85c..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/controller/ExpenseController.java +++ /dev/null @@ -1,74 +0,0 @@ -package net.miarma.backend.huertos.controller; - -import net.miarma.backend.huertos.dto.ExpenseDto; -import net.miarma.backend.huertos.mapper.ExpenseMapper; -import net.miarma.backend.huertos.model.Expense; -import net.miarma.backend.huertos.service.ExpenseService; -import org.springframework.http.ResponseEntity; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.*; - -import java.util.List; -import java.util.Map; -import java.util.UUID; - -@RestController -@RequestMapping("/expenses") -public class ExpenseController { - private ExpenseService expenseService; - - public ExpenseController(ExpenseService expenseService) { - this.expenseService = expenseService; - } - - @GetMapping - @PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')") - public ResponseEntity> getAll() { - return ResponseEntity.ok( - expenseService.getAll() - .stream() - .map(ExpenseMapper::toResponse) - .toList() - ); - } - - @PostMapping - @PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')") - public ResponseEntity create(@RequestBody ExpenseDto.Request dto) { - return ResponseEntity.ok( - ExpenseMapper.toResponse( - expenseService.create( - ExpenseMapper.toEntity(dto) - ))); - } - - @GetMapping("/{expense_id}") - @PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')") - public ResponseEntity getById(@PathVariable("expense_id") UUID expenseId) { - Expense expense = expenseService.getById(expenseId); - return ResponseEntity.ok(ExpenseMapper.toResponse(expense)); - } - - @PutMapping("/{expense_id}") - @PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')") - public ResponseEntity update( - @PathVariable("expense_id") UUID expenseId, - @RequestBody ExpenseDto.Request dto - ) { - Expense updated = expenseService.update( - expenseId, - ExpenseMapper.toEntity(dto) - ); - - return ResponseEntity.ok( - ExpenseMapper.toResponse(updated) - ); - } - - @DeleteMapping("/{expense_id}") - @PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')") - public ResponseEntity> delete(@PathVariable("expense_id") UUID expenseId) { - expenseService.delete(expenseId); - return ResponseEntity.ok(Map.of("message", "Deleted expense: " + expenseId)); - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/controller/HuertosAuthController.java b/huertos/src/main/java/net/miarma/backend/huertos/controller/HuertosAuthController.java deleted file mode 100644 index 2b260ff..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/controller/HuertosAuthController.java +++ /dev/null @@ -1,41 +0,0 @@ -package net.miarma.backend.huertos.controller; - -import net.miarma.backend.huertos.client.CoreAuthClient; -import net.miarma.backend.huertos.dto.HuertosLoginResponse; -import net.miarma.backend.huertos.mapper.UserMetadataMapper; -import net.miarma.backend.huertos.model.UserMetadata; -import net.miarma.backend.huertos.service.UserMetadataService; -import net.miarma.backlib.dto.LoginRequest; -import net.miarma.backlib.dto.LoginResponse; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("/auth") -public class HuertosAuthController { - private final UserMetadataService metadataService; - private final CoreAuthClient authClient; - - public HuertosAuthController(UserMetadataService metadataService, - CoreAuthClient authClient) { - this.metadataService = metadataService; - this.authClient = authClient; - } - - @PostMapping("/login") - public ResponseEntity login(@RequestBody LoginRequest req) { - LoginResponse coreResponse = authClient.login(req); - UserMetadata metadata = metadataService.getById(coreResponse.user().getUserId()); - return ResponseEntity.ok( - new HuertosLoginResponse( - coreResponse.token(), - coreResponse.user(), - coreResponse.account(), - UserMetadataMapper.toDto(metadata) - ) - ); - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/controller/IncomeController.java b/huertos/src/main/java/net/miarma/backend/huertos/controller/IncomeController.java deleted file mode 100644 index 26794a5..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/controller/IncomeController.java +++ /dev/null @@ -1,114 +0,0 @@ -package net.miarma.backend.huertos.controller; - -import net.miarma.backend.huertos.dto.IncomeDto; -import net.miarma.backend.huertos.dto.view.VIncomesWithInfoDto; -import net.miarma.backend.huertos.mapper.IncomeMapper; -import net.miarma.backend.huertos.mapper.view.VIncomesWithInfoMapper; -import net.miarma.backend.huertos.model.Income; -import net.miarma.backend.huertos.service.IncomeService; -import net.miarma.backend.huertos.service.view.VIncomesWithInfoService; -import net.miarma.backlib.security.JwtService; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.*; - -import java.util.List; -import java.util.Map; -import java.util.UUID; - -@RestController -@RequestMapping("/incomes") -public class IncomeController { - private IncomeService incomeService; - private VIncomesWithInfoService vIncomesWithInfoService; - private JwtService jwtService; - - public IncomeController(IncomeService incomeService, VIncomesWithInfoService vIncomesWithInfoService, JwtService jwtService) { - this.incomeService = incomeService; - this.vIncomesWithInfoService = vIncomesWithInfoService; - this.jwtService = jwtService; - } - - @GetMapping - @PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')") - public ResponseEntity> getAll() { - return ResponseEntity.ok( - incomeService.getAll() - .stream() - .map(IncomeMapper::toResponse) - .toList() - ); - } - - @GetMapping("/with-info") - @PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')") - public ResponseEntity> getAllWithInfo() { - return ResponseEntity.ok( - vIncomesWithInfoService.getAll() - .stream() - .map(VIncomesWithInfoMapper::toResponse) - .toList() - ); - } - - @GetMapping("/mine") - public ResponseEntity> getMine(@RequestHeader("Authorization") String authHeader) { - if (authHeader == null || !authHeader.startsWith("Bearer ")) { - return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build(); - } - - String token = authHeader.substring(7); - - UUID userId; - try { - userId = jwtService.getUserId(token); - } catch (Exception e) { - return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build(); - } - - return ResponseEntity.ok( - incomeService.getByUserId(userId) - .stream() - .map(IncomeMapper::toResponse) - .toList() - ); - } - - @PostMapping - @PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')") - public ResponseEntity create(@RequestBody IncomeDto.Request dto) { - return ResponseEntity.ok( - IncomeMapper.toResponse( - incomeService.create( - IncomeMapper.toEntity(dto) - ))); - } - - @GetMapping("/{income_id}") - @PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')") - public ResponseEntity getById(@PathVariable("income_id") UUID incomeId) { - Income income = incomeService.getById(incomeId); - return ResponseEntity.ok(IncomeMapper.toResponse(income)); - } - - @PutMapping("/{income_id}") - @PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')") - public ResponseEntity update( - @PathVariable("income_id") UUID incomeId, - @RequestBody IncomeDto.Request dto - ) { - IO.println(dto.getCreatedAt()); - return ResponseEntity.ok( - IncomeMapper.toResponse( - incomeService.update( - incomeId, IncomeMapper.toEntity(dto)))); - } - - @DeleteMapping("/{income_id}") - @PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')") - public ResponseEntity> delete(@PathVariable("income_id") UUID incomeId) { - incomeService.delete(incomeId); - return ResponseEntity.ok(Map.of("message", "Deleted income: " + incomeId)); - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/controller/MemberController.java b/huertos/src/main/java/net/miarma/backend/huertos/controller/MemberController.java deleted file mode 100644 index 15b5995..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/controller/MemberController.java +++ /dev/null @@ -1,134 +0,0 @@ -package net.miarma.backend.huertos.controller; - -import net.miarma.backend.huertos.dto.*; -import net.miarma.backend.huertos.dto.view.VIncomesWithInfoDto; -import net.miarma.backend.huertos.mapper.IncomeMapper; -import net.miarma.backend.huertos.mapper.RequestMapper; -import net.miarma.backend.huertos.security.HuertosPrincipal; -import net.miarma.backend.huertos.service.IncomeService; -import net.miarma.backend.huertos.service.MemberService; -import net.miarma.backend.huertos.service.RequestService; -import net.miarma.backlib.security.JwtService; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.web.bind.annotation.*; - -import java.util.List; -import java.util.UUID; - -@RestController -@RequestMapping("/users") -public class MemberController { - - private final MemberService memberService; - - public MemberController(MemberService memberService) { - this.memberService = memberService; - } - - @GetMapping - @PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')") - public ResponseEntity> getAll() { - return ResponseEntity.ok(memberService.getAll()); - } - - @GetMapping("/me") - public ResponseEntity getMe(Authentication authentication) { - if (!(authentication.getPrincipal() instanceof HuertosPrincipal principal)) { - throw new IllegalStateException("Tipo de autenticación inválida"); - } - - return ResponseEntity.ok( - memberService.getMyProfile(principal.getUserId()) - ); - } - - @GetMapping("/dropdown") - @PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')") - public ResponseEntity> getDropdown() { - return ResponseEntity.ok(memberService.getDropdown()); - } - - @GetMapping("/{user_id:[0-9a-fA-F\\-]{36}}") - @PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')") - public ResponseEntity getById(@PathVariable("user_id") UUID userId) { - return ResponseEntity.ok(memberService.getById(userId)); - } - - @GetMapping("/latest-number") - public ResponseEntity getLatestNumber() { - return ResponseEntity.ok(memberService.getLatestMemberNumber()); - } - - @GetMapping("/waitlist") - @PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')") - public ResponseEntity> getWaitlist() { - return ResponseEntity.ok(memberService.getWaitlist()); - } - - @GetMapping("/waitlist/limited") - public ResponseEntity> getWaitlistLimited() { - return ResponseEntity.ok(memberService.getWaitlistLimited()); - } - - @GetMapping("/number/{member_number}") - @PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')") - public ResponseEntity getByMemberNumber(@PathVariable("member_number") Integer memberNumber) { - return ResponseEntity.ok(memberService.getByMemberNumber(memberNumber)); - } - - @GetMapping("/number/{member_number}/incomes") - @PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')") - public ResponseEntity> getMemberIncomes(@PathVariable("member_number") Integer memberNumber) { - return ResponseEntity.ok(memberService.getIncomes(memberNumber)); - } - - @GetMapping("/number/{member_number}/has-paid") - public ResponseEntity getMemberHasPaid(@PathVariable("member_number") Integer memberNumber) { - return ResponseEntity.ok(memberService.hasPaid(memberNumber)); - } - - @GetMapping("/number/{member_number}/has-collaborator") - public ResponseEntity getMemberHasCollaborator(@PathVariable("member_number") Integer memberNumber) { - return ResponseEntity.ok(memberService.hasCollaborator(memberNumber)); - } - - @GetMapping("/number/{member_number}/has-greenhouse") - public ResponseEntity getMemberHasGreenhouse(@PathVariable("member_number") Integer memberNumber) { - return ResponseEntity.ok(memberService.hasGreenhouse(memberNumber)); - } - - @GetMapping("/number/{member_number}/has-collaborator-request") - public ResponseEntity getMemberHasCollaboratorRequest(@PathVariable("member_number") Integer memberNumber) { - return ResponseEntity.ok(memberService.hasCollaboratorRequest(memberNumber)); - } - - @GetMapping("/number/{member_number}/has-greenhouse-request") - public ResponseEntity getMemberHasGreenhouseRequest(@PathVariable("member_number") Integer memberNumber) { - return ResponseEntity.ok(memberService.hasGreenhouseRequest(memberNumber)); - } - - @GetMapping("/plot/{plot_number}") - @PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')") - public ResponseEntity getByPlotNumber(@PathVariable("plot_number") Integer plotNumber) { - return ResponseEntity.ok(memberService.getByPlotNumber(plotNumber)); - } - - @GetMapping("/dni/{dni}") - @PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')") - public ResponseEntity 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 update( - @PathVariable("user_id") UUID userId, - @RequestBody MemberDto changes - ) { - return ResponseEntity.ok(memberService.update(userId, changes)); - } -} \ No newline at end of file diff --git a/huertos/src/main/java/net/miarma/backend/huertos/controller/RequestController.java b/huertos/src/main/java/net/miarma/backend/huertos/controller/RequestController.java deleted file mode 100644 index a438f44..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/controller/RequestController.java +++ /dev/null @@ -1,152 +0,0 @@ -package net.miarma.backend.huertos.controller; - -import net.miarma.backend.huertos.dto.*; -import net.miarma.backend.huertos.mapper.RequestMapper; -import net.miarma.backend.huertos.mapper.RequestMetadataMapper; -import net.miarma.backend.huertos.mapper.RequestWithMetadataMapper; -import net.miarma.backend.huertos.model.Request; -import net.miarma.backend.huertos.service.RequestAcceptanceService; -import net.miarma.backend.huertos.service.RequestService; -import net.miarma.backlib.security.JwtService; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.web.bind.annotation.*; - -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.stream.Collectors; - -@RestController -@RequestMapping("/requests") -public class RequestController { - - private final RequestService requestService; - private final RequestAcceptanceService requestAcceptanceService; - private final JwtService jwtService; - - public RequestController(RequestService requestService, - RequestAcceptanceService requestAcceptanceService, - JwtService jwtService) { - this.requestService = requestService; - this.requestAcceptanceService = requestAcceptanceService; - this.jwtService = jwtService; - } - - @GetMapping - @PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')") - public ResponseEntity> getAll() { - return ResponseEntity.ok( - requestService.getAll() - .stream() - .map(RequestMapper::toResponse) - .toList() - ); - } - - @PostMapping - public ResponseEntity create(@RequestBody RequestDto.Request dto) { - return ResponseEntity.ok( - RequestMapper.toResponse( - requestService.create( - RequestMapper.toEntity(dto) - ))); - } - - @GetMapping("/count") - @PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')") - public ResponseEntity getRequestCount() { - return ResponseEntity.ok( - requestService.getAll() - .stream() - .map(RequestMapper::toResponse) - .collect(Collectors.collectingAndThen( - Collectors.counting(), - RequestCountDto::new - )) - ); - } - - @GetMapping("/mine") - public ResponseEntity> getMine(@RequestHeader("Authorization") String authHeader) { - if (authHeader == null || !authHeader.startsWith("Bearer ")) { - return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build(); - } - - String token = authHeader.substring(7); - - UUID userId; - try { - userId = jwtService.getUserId(token); - } catch (Exception e) { - return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build(); - } - - return ResponseEntity.ok( - requestService.getByUserId(userId) - .stream() - .map(RequestMapper::toResponse) - .toList() - ); - } - - @GetMapping("/full") - @PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')") - public ResponseEntity> getAllWithMetadata() { - return ResponseEntity.ok( - requestService.getAll() - .stream() - .map(RequestWithMetadataMapper::toDto) - .toList() - ); - } - - @GetMapping("/full/{request_id}") - @PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')") - public ResponseEntity getByIdWithMetadata( - @PathVariable("request_id") UUID requestId) { - Request request = requestService.getById(requestId); - return ResponseEntity.ok(RequestWithMetadataMapper.toDto(request)); - } - - @GetMapping("/{request_id}") - @PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')") - public ResponseEntity getById(@PathVariable("request_id") UUID requestId) { - Request request = requestService.getById(requestId); - return ResponseEntity.ok(RequestMapper.toResponse(request)); - } - - @PutMapping("/{request_id}") - @PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')") - public ResponseEntity update( - @PathVariable("request_id") UUID requestId, - @RequestBody RequestDto.Request dto - ) { - return ResponseEntity.ok( - RequestMapper.toResponse(requestService.update(requestId, RequestMapper.toEntity(dto))) - ); - } - - @PutMapping("/{request_id}/accept") - @PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')") - public ResponseEntity> acceptRequest(@PathVariable("request_id") UUID requestId) { - Request r = requestAcceptanceService.acceptRequest(requestId); - requestAcceptanceService.handleSideEffects(r); - return ResponseEntity.ok(Map.of("message", "Accepted request: " + r.getRequestId())); - } - - @PutMapping("/{request_id}/reject") - @PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')") - public ResponseEntity> rejectRequest(@PathVariable("request_id") UUID requestId) { - Request r = requestService.reject(requestId); - return ResponseEntity.ok(Map.of("message", "Denied request: " + r.getRequestId())); - } - - @DeleteMapping("/{request_id}") - @PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')") - public ResponseEntity> delete(@PathVariable("request_id") UUID requestId) { - requestService.delete(requestId); - return ResponseEntity.ok(Map.of("message", "Deleted request: " + requestId)); - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/dto/AnnouncementDto.java b/huertos/src/main/java/net/miarma/backend/huertos/dto/AnnouncementDto.java deleted file mode 100644 index 85e48bf..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/dto/AnnouncementDto.java +++ /dev/null @@ -1,89 +0,0 @@ -package net.miarma.backend.huertos.dto; - -import java.time.Instant; -import java.util.UUID; - -public class AnnouncementDto { - public static class Request { - private String body; - private Byte priority; - private UUID publishedBy; - - public String getBody() { - return body; - } - - public void setBody(String body) { - this.body = body; - } - - public Byte getPriority() { - return priority; - } - - public void setPriority(Byte priority) { - this.priority = priority; - } - - public UUID getPublishedBy() { - return publishedBy; - } - - public void setPublishedBy(UUID publishedBy) { - this.publishedBy = publishedBy; - } - } - - public static class Response { - private UUID announceId; - private String body; - private Byte priority; - private UUID publishedBy; - private String publishedByName; - private Instant createdAt; - - public UUID getAnnounceId() { - return announceId; - } - - public void setAnnounceId(UUID announceId) { - this.announceId = announceId; - } - - public String getBody() { - return body; - } - - public void setBody(String body) { - this.body = body; - } - - public Byte getPriority() { - return priority; - } - - public void setPriority(Byte priority) { - this.priority = priority; - } - - public UUID getPublishedBy() { - return publishedBy; - } - - public void setPublishedBy(UUID publishedBy) { - this.publishedBy = publishedBy; - } - - public String getPublishedByName() { return publishedByName; } - - public void setPublishedByName(String publishedByName) { this.publishedByName = publishedByName; } - - public Instant getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Instant createdAt) { - this.createdAt = createdAt; - } - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/dto/BalanceDto.java b/huertos/src/main/java/net/miarma/backend/huertos/dto/BalanceDto.java deleted file mode 100644 index f13803f..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/dto/BalanceDto.java +++ /dev/null @@ -1,43 +0,0 @@ -package net.miarma.backend.huertos.dto; - -import java.math.BigDecimal; -import java.time.Instant; - -public class BalanceDto { - private Byte id; - private BigDecimal initialBank; - private BigDecimal initialCash; - private Instant createdAt; - - public Byte getId() { - return id; - } - - public void setId(Byte id) { - this.id = id; - } - - public BigDecimal getInitialBank() { - return initialBank; - } - - public void setInitialBank(BigDecimal initialBank) { - this.initialBank = initialBank; - } - - public BigDecimal getInitialCash() { - return initialCash; - } - - public void setInitialCash(BigDecimal initialCash) { - this.initialCash = initialCash; - } - - public Instant getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Instant createdAt) { - this.createdAt = createdAt; - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/dto/DropdownDto.java b/huertos/src/main/java/net/miarma/backend/huertos/dto/DropdownDto.java deleted file mode 100644 index 3290a5c..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/dto/DropdownDto.java +++ /dev/null @@ -1,6 +0,0 @@ -package net.miarma.backend.huertos.dto; - -import java.util.UUID; - -public record DropdownDto(UUID userId, Integer memberNumber, String displayName) { -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/dto/ExpenseDto.java b/huertos/src/main/java/net/miarma/backend/huertos/dto/ExpenseDto.java deleted file mode 100644 index 42299b5..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/dto/ExpenseDto.java +++ /dev/null @@ -1,130 +0,0 @@ -package net.miarma.backend.huertos.dto; - -import java.math.BigDecimal; -import java.time.Instant; -import java.util.UUID; - -public class ExpenseDto { - public static class Request { - private String concept; - private BigDecimal amount; - private String supplier; - private String invoice; - private Byte type; - private Instant createdAt; - - public String getConcept() { - return concept; - } - - public void setConcept(String concept) { - this.concept = concept; - } - - public BigDecimal getAmount() { - return amount; - } - - public void setAmount(BigDecimal amount) { - this.amount = amount; - } - - public String getSupplier() { - return supplier; - } - - public void setSupplier(String supplier) { - this.supplier = supplier; - } - - public String getInvoice() { - return invoice; - } - - public void setInvoice(String invoice) { - this.invoice = invoice; - } - - public Byte getType() { - return type; - } - - public void setType(Byte type) { - this.type = type; - } - - public Instant getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Instant createdAt) { - this.createdAt = createdAt; - } - } - - public static class Response { - private UUID expenseId; - private String concept; - private BigDecimal amount; - private String supplier; - private String invoice; - private Byte type; - private Instant createdAt; - - public UUID getExpenseId() { - return expenseId; - } - - public void setExpenseId(UUID expenseId) { - this.expenseId = expenseId; - } - - public String getConcept() { - return concept; - } - - public void setConcept(String concept) { - this.concept = concept; - } - - public BigDecimal getAmount() { - return amount; - } - - public void setAmount(BigDecimal amount) { - this.amount = amount; - } - - public String getSupplier() { - return supplier; - } - - public void setSupplier(String supplier) { - this.supplier = supplier; - } - - public String getInvoice() { - return invoice; - } - - public void setInvoice(String invoice) { - this.invoice = invoice; - } - - public Byte getType() { - return type; - } - - public void setType(Byte type) { - this.type = type; - } - - public Instant getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Instant createdAt) { - this.createdAt = createdAt; - } - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/dto/HuertosLoginResponse.java b/huertos/src/main/java/net/miarma/backend/huertos/dto/HuertosLoginResponse.java deleted file mode 100644 index 93e74fe..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/dto/HuertosLoginResponse.java +++ /dev/null @@ -1,12 +0,0 @@ -package net.miarma.backend.huertos.dto; - -import net.miarma.backlib.dto.CredentialDto; -import net.miarma.backlib.dto.UserDto; - -public record HuertosLoginResponse( - String token, - UserDto user, - CredentialDto account, - UserMetadataDto metadata -) { -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/dto/IncomeDto.java b/huertos/src/main/java/net/miarma/backend/huertos/dto/IncomeDto.java deleted file mode 100644 index 274ec64..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/dto/IncomeDto.java +++ /dev/null @@ -1,139 +0,0 @@ -package net.miarma.backend.huertos.dto; - -import java.math.BigDecimal; -import java.time.Instant; -import java.util.UUID; - -public class IncomeDto { - public static class Request { - private UUID userId; - private Integer memberNumber; - private String concept; - private BigDecimal amount; - private Byte type; - private Byte frequency; - private Instant createdAt; - - public Integer getMemberNumber() { - return memberNumber; - } - - public void setMemberNumber(Integer memberNumber) { - this.memberNumber = memberNumber; - } - - public UUID getUserId() { - return userId; - } - - public void setUserId(UUID userId) { - this.userId = userId; - } - - public String getConcept() { - return concept; - } - - public void setConcept(String concept) { - this.concept = concept; - } - - public BigDecimal getAmount() { - return amount; - } - - public void setAmount(BigDecimal amount) { - this.amount = amount; - } - - public Byte getType() { - return type; - } - - public void setType(Byte type) { - this.type = type; - } - - public Byte getFrequency() { - return frequency; - } - - public void setFrequency(Byte frequency) { - this.frequency = frequency; - } - - public Instant getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Instant createdAt) { - this.createdAt = createdAt; - } - } - - public static class Response { - private UUID incomeId; - private UUID userId; - private String concept; - private BigDecimal amount; - private Byte type; - private Byte frequency; - private Instant createdAt; - - public UUID getIncomeId() { - return incomeId; - } - - public void setIncomeId(UUID incomeId) { - this.incomeId = incomeId; - } - - public UUID getUserId() { - return userId; - } - - public void setUserId(UUID userId) { - this.userId = userId; - } - - public String getConcept() { - return concept; - } - - public void setConcept(String concept) { - this.concept = concept; - } - - public BigDecimal getAmount() { - return amount; - } - - public void setAmount(BigDecimal amount) { - this.amount = amount; - } - - public Byte getType() { - return type; - } - - public void setType(Byte type) { - this.type = type; - } - - public Byte getFrequency() { - return frequency; - } - - public void setFrequency(Byte frequency) { - this.frequency = frequency; - } - - public Instant getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Instant createdAt) { - this.createdAt = createdAt; - } - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/dto/MemberDto.java b/huertos/src/main/java/net/miarma/backend/huertos/dto/MemberDto.java deleted file mode 100644 index 4440c5e..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/dto/MemberDto.java +++ /dev/null @@ -1,8 +0,0 @@ -package net.miarma.backend.huertos.dto; - -import net.miarma.backlib.dto.CredentialDto; -import net.miarma.backlib.dto.UserDto; - -public record MemberDto(UserDto user, - CredentialDto account, - UserMetadataDto metadata) {} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/dto/MemberProfileDto.java b/huertos/src/main/java/net/miarma/backend/huertos/dto/MemberProfileDto.java deleted file mode 100644 index 4717fcf..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/dto/MemberProfileDto.java +++ /dev/null @@ -1,20 +0,0 @@ -package net.miarma.backend.huertos.dto; - -import net.miarma.backend.huertos.dto.view.VIncomesWithInfoDto; -import net.miarma.backlib.dto.CredentialDto; -import net.miarma.backlib.dto.UserDto; - -import java.util.List; - -public record MemberProfileDto( - UserDto user, - CredentialDto account, - UserMetadataDto metadata, - List requests, - List payments, - boolean hasCollaborator, - boolean hasGreenhouse, - boolean hasCollaboratorRequest, - boolean hasGreenhouseRequest -) { -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/dto/RequestCountDto.java b/huertos/src/main/java/net/miarma/backend/huertos/dto/RequestCountDto.java deleted file mode 100644 index 5c30653..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/dto/RequestCountDto.java +++ /dev/null @@ -1,5 +0,0 @@ -package net.miarma.backend.huertos.dto; - -public record RequestCountDto(Long count) { - -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/dto/RequestDto.java b/huertos/src/main/java/net/miarma/backend/huertos/dto/RequestDto.java deleted file mode 100644 index 2e4f71d..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/dto/RequestDto.java +++ /dev/null @@ -1,113 +0,0 @@ -package net.miarma.backend.huertos.dto; - -import jakarta.annotation.Nullable; - -import java.time.Instant; -import java.util.UUID; - -public class RequestDto { - public static class Request { - private Byte type; - private UUID userId; - private String name; - private RequestMetadataDto metadata; - - public Byte getType() { - return type; - } - - public void setType(Byte type) { - this.type = type; - } - - public UUID getUserId() { - return userId; - } - - public void setUserId(UUID userId) { - this.userId = userId; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public RequestMetadataDto getMetadata() { - return metadata; - } - - public void setMetadata(RequestMetadataDto metadata) { - this.metadata = metadata; - } - } - - public static class Response { - private UUID requestId; - private Byte type; - private Byte status; - private UUID userId; - private String name; - private RequestMetadataDto metadata; - private Instant createdAt; - - public UUID getRequestId() { - return requestId; - } - - public void setRequestId(UUID requestId) { - this.requestId = requestId; - } - - public Byte getType() { - return type; - } - - public void setType(Byte type) { - this.type = type; - } - - public Byte getStatus() { - return status; - } - - public void setStatus(Byte status) { - this.status = status; - } - - public UUID getUserId() { - return userId; - } - - public void setUserId(UUID userId) { - this.userId = userId; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public RequestMetadataDto getMetadata() { - return metadata; - } - - public void setMetadata(RequestMetadataDto metadata) { - this.metadata = metadata; - } - - public Instant getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Instant createdAt) { - this.createdAt = createdAt; - } - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/dto/RequestMetadataDto.java b/huertos/src/main/java/net/miarma/backend/huertos/dto/RequestMetadataDto.java deleted file mode 100644 index b9ed47a..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/dto/RequestMetadataDto.java +++ /dev/null @@ -1,20 +0,0 @@ -package net.miarma.backend.huertos.dto; - -import java.time.Instant; - -public record RequestMetadataDto( - Long id, - String displayName, - String dni, - String phone, - String email, - String username, - String address, - String zipCode, - String city, - Integer memberNumber, - Integer plotNumber, - Byte type, - Instant createdAt -) {} - diff --git a/huertos/src/main/java/net/miarma/backend/huertos/dto/RequestWithMetadataDto.java b/huertos/src/main/java/net/miarma/backend/huertos/dto/RequestWithMetadataDto.java deleted file mode 100644 index 6a452e5..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/dto/RequestWithMetadataDto.java +++ /dev/null @@ -1,15 +0,0 @@ -package net.miarma.backend.huertos.dto; - -import java.time.Instant; -import java.util.UUID; - -public record RequestWithMetadataDto( - UUID requestId, - UUID userId, - String name, - Byte type, - Byte status, - Instant createdAt, - RequestMetadataDto metadata -) {} - diff --git a/huertos/src/main/java/net/miarma/backend/huertos/dto/UserMetadataDto.java b/huertos/src/main/java/net/miarma/backend/huertos/dto/UserMetadataDto.java deleted file mode 100644 index 9c40b91..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/dto/UserMetadataDto.java +++ /dev/null @@ -1,106 +0,0 @@ -package net.miarma.backend.huertos.dto; - -import java.time.Instant; -import java.util.UUID; - -public class UserMetadataDto { - private UUID userId; - private Integer memberNumber; - private Integer plotNumber; - private String dni; - private String phone; - private Byte type; - private Byte role; - private String notes; - private Instant createdAt; - private Instant assignedAt; - private Instant deactivatedAt; - - public UUID getUserId() { - return userId; - } - - public void setUserId(UUID userId) { - this.userId = userId; - } - - public Integer getMemberNumber() { - return memberNumber; - } - - public void setMemberNumber(Integer memberNumber) { - this.memberNumber = memberNumber; - } - - public Integer getPlotNumber() { - return plotNumber; - } - - public void setPlotNumber(Integer plotNumber) { - this.plotNumber = plotNumber; - } - - public String getDni() { - return dni; - } - - public void setDni(String dni) { - this.dni = dni; - } - - public String getPhone() { - return phone; - } - - public void setPhone(String phone) { - this.phone = phone; - } - - public Byte getType() { - return type; - } - - public void setType(Byte type) { - this.type = type; - } - - public Byte getRole() { - return role; - } - - public void setRole(Byte role) { - this.role = role; - } - - public String getNotes() { - return notes; - } - - public void setNotes(String notes) { - this.notes = notes; - } - - public Instant getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Instant createdAt) { - this.createdAt = createdAt; - } - - public Instant getAssignedAt() { - return assignedAt; - } - - public void setAssignedAt(Instant assignedAt) { - this.assignedAt = assignedAt; - } - - public Instant getDeactivatedAt() { - return deactivatedAt; - } - - public void setDeactivatedAt(Instant deactivatedAt) { - this.deactivatedAt = deactivatedAt; - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/dto/WaitlistCensoredDto.java b/huertos/src/main/java/net/miarma/backend/huertos/dto/WaitlistCensoredDto.java deleted file mode 100644 index c1de35b..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/dto/WaitlistCensoredDto.java +++ /dev/null @@ -1,13 +0,0 @@ -package net.miarma.backend.huertos.dto; - -public class WaitlistCensoredDto { - private String name; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/dto/view/VBalanceWithTotalsDto.java b/huertos/src/main/java/net/miarma/backend/huertos/dto/view/VBalanceWithTotalsDto.java deleted file mode 100644 index 1cd6dbb..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/dto/view/VBalanceWithTotalsDto.java +++ /dev/null @@ -1,79 +0,0 @@ -package net.miarma.backend.huertos.dto.view; - -import java.math.BigDecimal; -import java.time.Instant; - -public class VBalanceWithTotalsDto { - private Byte id; - private BigDecimal initialBank; - private BigDecimal initialCash; - private BigDecimal totalBankExpenses; - private BigDecimal totalCashExpenses; - private BigDecimal totalBankIncomes; - private BigDecimal totalCashIncomes; - private Instant createdAt; - - public Byte getId() { - return id; - } - - public void setId(Byte id) { - this.id = id; - } - - public BigDecimal getInitialBank() { - return initialBank; - } - - public void setInitialBank(BigDecimal initialBank) { - this.initialBank = initialBank; - } - - public BigDecimal getInitialCash() { - return initialCash; - } - - public void setInitialCash(BigDecimal initialCash) { - this.initialCash = initialCash; - } - - public BigDecimal getTotalBankExpenses() { - return totalBankExpenses; - } - - public void setTotalBankExpenses(BigDecimal totalBankExpenses) { - this.totalBankExpenses = totalBankExpenses; - } - - public BigDecimal getTotalCashExpenses() { - return totalCashExpenses; - } - - public void setTotalCashExpenses(BigDecimal totalCashExpenses) { - this.totalCashExpenses = totalCashExpenses; - } - - public BigDecimal getTotalBankIncomes() { - return totalBankIncomes; - } - - public void setTotalBankIncomes(BigDecimal totalBankIncomes) { - this.totalBankIncomes = totalBankIncomes; - } - - public BigDecimal getTotalCashIncomes() { - return totalCashIncomes; - } - - public void setTotalCashIncomes(BigDecimal totalCashIncomes) { - this.totalCashIncomes = totalCashIncomes; - } - - public Instant getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Instant createdAt) { - this.createdAt = createdAt; - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/dto/view/VIncomesWithInfoDto.java b/huertos/src/main/java/net/miarma/backend/huertos/dto/view/VIncomesWithInfoDto.java deleted file mode 100644 index 0c2428f..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/dto/view/VIncomesWithInfoDto.java +++ /dev/null @@ -1,89 +0,0 @@ -package net.miarma.backend.huertos.dto.view; - -import java.math.BigDecimal; -import java.time.Instant; -import java.util.UUID; - -public class VIncomesWithInfoDto { - private UUID incomeId; - private UUID userId; - private String displayName; - private Integer memberNumber; - private String concept; - private BigDecimal amount; - private Byte type; - private Byte frequency; - private Instant createdAt; - - public UUID getIncomeId() { - return incomeId; - } - - public void setIncomeId(UUID incomeId) { - this.incomeId = incomeId; - } - - public UUID getUserId() { - return userId; - } - - public void setUserId(UUID userId) { - this.userId = userId; - } - - public String getDisplayName() { - return displayName; - } - - public Integer getMemberNumber() { - return memberNumber; - } - - public void setMemberNumber(Integer memberNumber) { - this.memberNumber = memberNumber; - } - - public void setDisplayName(String displayName) { - this.displayName = displayName; - } - - public String getConcept() { - return concept; - } - - public void setConcept(String concept) { - this.concept = concept; - } - - public BigDecimal getAmount() { - return amount; - } - - public void setAmount(BigDecimal amount) { - this.amount = amount; - } - - public Byte getType() { - return type; - } - - public void setType(Byte type) { - this.type = type; - } - - public Byte getFrequency() { - return frequency; - } - - public void setFrequency(Byte frequency) { - this.frequency = frequency; - } - - public Instant getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Instant createdAt) { - this.createdAt = createdAt; - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/mapper/AnnouncementMapper.java b/huertos/src/main/java/net/miarma/backend/huertos/mapper/AnnouncementMapper.java deleted file mode 100644 index 0d3d109..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/mapper/AnnouncementMapper.java +++ /dev/null @@ -1,31 +0,0 @@ -package net.miarma.backend.huertos.mapper; - -import net.miarma.backend.huertos.dto.AnnouncementDto; -import net.miarma.backend.huertos.model.Announcement; - -import java.time.Instant; -import java.util.UUID; - -public class AnnouncementMapper { - - public static AnnouncementDto.Response toResponse(Announcement entity) { - AnnouncementDto.Response dto = new AnnouncementDto.Response(); - dto.setAnnounceId(entity.getAnnounceId()); - dto.setBody(entity.getBody()); - dto.setPriority(entity.getPriority()); - dto.setPublishedBy(entity.getPublishedBy()); - dto.setPublishedByName(entity.getPublishedByName()); - dto.setCreatedAt(entity.getCreatedAt()); - return dto; - } - - public static Announcement toEntity(AnnouncementDto.Request dto) { - Announcement entity = new Announcement(); - entity.setAnnounceId(UUID.randomUUID()); - entity.setBody(dto.getBody()); - entity.setPriority(dto.getPriority()); - entity.setPublishedBy(dto.getPublishedBy()); - entity.setCreatedAt(Instant.now()); - return entity; - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/mapper/BalanceMapper.java b/huertos/src/main/java/net/miarma/backend/huertos/mapper/BalanceMapper.java deleted file mode 100644 index 238768c..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/mapper/BalanceMapper.java +++ /dev/null @@ -1,29 +0,0 @@ -package net.miarma.backend.huertos.mapper; - -import net.miarma.backend.huertos.dto.BalanceDto; -import net.miarma.backend.huertos.model.Balance; - -public class BalanceMapper { - - public static BalanceDto toDto(Balance balance) { - if (balance == null) return null; - - BalanceDto dto = new BalanceDto(); - dto.setId(balance.getId()); - dto.setInitialBank(balance.getInitialBank()); - dto.setInitialCash(balance.getInitialCash()); - dto.setCreatedAt(balance.getCreatedAt()); - return dto; - } - - public static Balance toEntity(BalanceDto dto) { - if (dto == null) return null; - - Balance balance = new Balance(); - balance.setId(dto.getId()); - balance.setInitialBank(dto.getInitialBank()); - balance.setInitialCash(dto.getInitialCash()); - balance.setCreatedAt(dto.getCreatedAt()); - return balance; - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/mapper/DropdownDtoMapper.java b/huertos/src/main/java/net/miarma/backend/huertos/mapper/DropdownDtoMapper.java deleted file mode 100644 index 944a9c6..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/mapper/DropdownDtoMapper.java +++ /dev/null @@ -1,10 +0,0 @@ -package net.miarma.backend.huertos.mapper; - -import net.miarma.backend.huertos.dto.DropdownDto; -import net.miarma.backend.huertos.dto.MemberDto; - -public class DropdownDtoMapper { - public static DropdownDto toDto(MemberDto dto) { - return new DropdownDto(dto.user().getUserId(), dto.metadata().getMemberNumber(), dto.user().getDisplayName()); - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/mapper/ExpenseMapper.java b/huertos/src/main/java/net/miarma/backend/huertos/mapper/ExpenseMapper.java deleted file mode 100644 index 701258c..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/mapper/ExpenseMapper.java +++ /dev/null @@ -1,34 +0,0 @@ -package net.miarma.backend.huertos.mapper; - -import net.miarma.backend.huertos.dto.ExpenseDto; -import net.miarma.backend.huertos.model.Expense; - -public class ExpenseMapper { - - public static ExpenseDto.Response toResponse(Expense entity) { - if (entity == null) return null; - - ExpenseDto.Response dto = new ExpenseDto.Response(); - dto.setExpenseId(entity.getExpenseId()); - dto.setConcept(entity.getConcept()); - dto.setAmount(entity.getAmount()); - dto.setSupplier(entity.getSupplier()); - dto.setInvoice(entity.getInvoice()); - dto.setType(entity.getType()); - dto.setCreatedAt(entity.getCreatedAt()); - return dto; - } - - public static Expense toEntity(ExpenseDto.Request dto) { - if (dto == null) return null; - - Expense entity = new Expense(); - entity.setConcept(dto.getConcept()); - entity.setAmount(dto.getAmount()); - entity.setSupplier(dto.getSupplier()); - entity.setInvoice(dto.getInvoice()); - entity.setType(dto.getType()); - entity.setCreatedAt(dto.getCreatedAt()); - return entity; - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/mapper/IncomeMapper.java b/huertos/src/main/java/net/miarma/backend/huertos/mapper/IncomeMapper.java deleted file mode 100644 index ea40403..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/mapper/IncomeMapper.java +++ /dev/null @@ -1,34 +0,0 @@ -package net.miarma.backend.huertos.mapper; - -import net.miarma.backend.huertos.dto.IncomeDto; -import net.miarma.backend.huertos.model.Income; - -public class IncomeMapper { - - public static IncomeDto.Response toResponse(Income entity) { - if (entity == null) return null; - - IncomeDto.Response dto = new IncomeDto.Response(); - dto.setIncomeId(entity.getIncomeId()); - dto.setUserId(entity.getUserId()); - dto.setConcept(entity.getConcept()); - dto.setAmount(entity.getAmount()); - dto.setType(entity.getType()); - dto.setFrequency(entity.getFrequency()); - dto.setCreatedAt(entity.getCreatedAt()); - return dto; - } - - public static Income toEntity(IncomeDto.Request dto) { - if (dto == null) return null; - - Income entity = new Income(); - entity.setUserId(dto.getUserId()); - entity.setConcept(dto.getConcept()); - entity.setAmount(dto.getAmount()); - entity.setType(dto.getType()); - entity.setFrequency(dto.getFrequency()); - entity.setCreatedAt(dto.getCreatedAt()); - return entity; - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/mapper/RequestMapper.java b/huertos/src/main/java/net/miarma/backend/huertos/mapper/RequestMapper.java deleted file mode 100644 index e7f4a33..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/mapper/RequestMapper.java +++ /dev/null @@ -1,44 +0,0 @@ -package net.miarma.backend.huertos.mapper; - -import net.miarma.backend.huertos.dto.RequestDto; -import net.miarma.backend.huertos.model.Request; - -public class RequestMapper { - - public static RequestDto.Response toResponse(Request entity) { - if (entity == null) return null; - - RequestDto.Response dto = new RequestDto.Response(); - dto.setRequestId(entity.getRequestId()); - dto.setType(entity.getType()); - dto.setStatus(entity.getStatus()); - dto.setUserId(entity.getUserId()); - dto.setCreatedAt(entity.getCreatedAt()); - - if (entity.getMetadata() != null) { - dto.setMetadata( - RequestMetadataMapper.toDto(entity.getMetadata()) - ); - } - - return dto; - } - - public static Request toEntity(RequestDto.Request dto) { - if (dto == null) return null; - - Request entity = new Request(); - entity.setType(dto.getType()); - entity.setUserId(dto.getUserId()); - entity.setName(dto.getName()); - entity.setStatus((byte) 0); - - if (dto.getMetadata() != null) { - entity.setMetadata( - RequestMetadataMapper.fromDto(dto.getMetadata()) - ); - } - - return entity; - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/mapper/RequestMetadataMapper.java b/huertos/src/main/java/net/miarma/backend/huertos/mapper/RequestMetadataMapper.java deleted file mode 100644 index 3055cf3..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/mapper/RequestMetadataMapper.java +++ /dev/null @@ -1,50 +0,0 @@ -package net.miarma.backend.huertos.mapper; - -import net.miarma.backend.huertos.dto.RequestMetadataDto; -import net.miarma.backend.huertos.model.RequestMetadata; - -public class RequestMetadataMapper { - - public static RequestMetadata fromDto(RequestMetadataDto dto) { - if (dto == null) return null; - - RequestMetadata metadata = new RequestMetadata(); - - metadata.setDisplayName(dto.displayName()); - metadata.setDni(dto.dni()); - metadata.setPhone(dto.phone()); - metadata.setEmail(dto.email()); - - metadata.setUsername(dto.username()); - metadata.setAddress(dto.address()); - metadata.setZipCode(dto.zipCode()); - metadata.setCity(dto.city()); - - metadata.setMemberNumber(dto.memberNumber()); - metadata.setPlotNumber(dto.plotNumber()); - - metadata.setType(dto.type()); - - return metadata; - } - - public static RequestMetadataDto toDto(RequestMetadata entity) { - if (entity == null) return null; - - return new RequestMetadataDto( - entity.getId(), - entity.getDisplayName(), - entity.getDni(), - entity.getPhone(), - entity.getEmail(), - entity.getUsername(), - entity.getAddress(), - entity.getZipCode(), - entity.getCity(), - entity.getMemberNumber(), - entity.getPlotNumber(), - entity.getType(), - entity.getCreatedAt() - ); - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/mapper/RequestWithMetadataMapper.java b/huertos/src/main/java/net/miarma/backend/huertos/mapper/RequestWithMetadataMapper.java deleted file mode 100644 index ab35d78..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/mapper/RequestWithMetadataMapper.java +++ /dev/null @@ -1,19 +0,0 @@ -package net.miarma.backend.huertos.mapper; - -import net.miarma.backend.huertos.dto.RequestWithMetadataDto; -import net.miarma.backend.huertos.model.Request; - -public class RequestWithMetadataMapper { - public static RequestWithMetadataDto toDto(Request r) { - if (r == null) return null; - return new RequestWithMetadataDto( - r.getRequestId(), - r.getUserId(), - r.getName(), - r.getType(), - r.getStatus(), - r.getCreatedAt(), - RequestMetadataMapper.toDto(r.getMetadata()) - ); - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/mapper/UserMetadataMapper.java b/huertos/src/main/java/net/miarma/backend/huertos/mapper/UserMetadataMapper.java deleted file mode 100644 index 5aad58c..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/mapper/UserMetadataMapper.java +++ /dev/null @@ -1,39 +0,0 @@ -package net.miarma.backend.huertos.mapper; - -import net.miarma.backend.huertos.dto.UserMetadataDto; -import net.miarma.backend.huertos.model.UserMetadata; - -public class UserMetadataMapper { - - public static UserMetadataDto toDto(UserMetadata entity) { - UserMetadataDto dto = new UserMetadataDto(); - dto.setUserId(entity.getUserId()); - dto.setMemberNumber(entity.getMemberNumber()); - dto.setPlotNumber(entity.getPlotNumber()); - dto.setDni(entity.getDni()); - dto.setPhone(entity.getPhone()); - dto.setType(entity.getType()); - dto.setRole(entity.getRole()); - dto.setNotes(entity.getNotes()); - dto.setCreatedAt(entity.getCreatedAt()); - dto.setAssignedAt(entity.getAssignedAt()); - dto.setDeactivatedAt(entity.getDeactivatedAt()); - return dto; - } - - public static UserMetadata fromDto(UserMetadataDto dto) { - UserMetadata entity = new UserMetadata(); - entity.setUserId(dto.getUserId()); - entity.setMemberNumber(dto.getMemberNumber()); - entity.setPlotNumber(dto.getPlotNumber()); - entity.setDni(dto.getDni()); - entity.setPhone(dto.getPhone()); - entity.setType(dto.getType()); - entity.setRole(dto.getRole()); - entity.setNotes(dto.getNotes()); - entity.setCreatedAt(dto.getCreatedAt()); - entity.setAssignedAt(dto.getAssignedAt()); - entity.setDeactivatedAt(dto.getDeactivatedAt()); - return entity; - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/mapper/view/VBalanceWithTotalsMapper.java b/huertos/src/main/java/net/miarma/backend/huertos/mapper/view/VBalanceWithTotalsMapper.java deleted file mode 100644 index 3d07229..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/mapper/view/VBalanceWithTotalsMapper.java +++ /dev/null @@ -1,20 +0,0 @@ -package net.miarma.backend.huertos.mapper.view; - -import net.miarma.backend.huertos.dto.view.VBalanceWithTotalsDto; -import net.miarma.backend.huertos.model.view.VBalanceWithTotals; - -public class VBalanceWithTotalsMapper { - - public static VBalanceWithTotalsDto toDto(VBalanceWithTotals entity) { - VBalanceWithTotalsDto dto = new VBalanceWithTotalsDto(); - dto.setId(entity.getId()); - dto.setInitialBank(entity.getInitialBank()); - dto.setInitialCash(entity.getInitialCash()); - dto.setTotalBankExpenses(entity.getTotalBankExpenses()); - dto.setTotalCashExpenses(entity.getTotalCashExpenses()); - dto.setTotalBankIncomes(entity.getTotalBankIncomes()); - dto.setTotalCashIncomes(entity.getTotalCashIncomes()); - dto.setCreatedAt(entity.getCreatedAt()); - return dto; - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/mapper/view/VIncomesWithInfoMapper.java b/huertos/src/main/java/net/miarma/backend/huertos/mapper/view/VIncomesWithInfoMapper.java deleted file mode 100644 index b0f6da7..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/mapper/view/VIncomesWithInfoMapper.java +++ /dev/null @@ -1,21 +0,0 @@ -package net.miarma.backend.huertos.mapper.view; - -import net.miarma.backend.huertos.dto.view.VIncomesWithInfoDto; -import net.miarma.backend.huertos.model.view.VIncomesWithInfo; - -public class VIncomesWithInfoMapper { - - public static VIncomesWithInfoDto toResponse(VIncomesWithInfo entity) { - VIncomesWithInfoDto dto = new VIncomesWithInfoDto(); - dto.setIncomeId(entity.getIncomeId()); - dto.setUserId(entity.getUserId()); - dto.setDisplayName(entity.getDisplayName()); - dto.setMemberNumber(entity.getMemberNumber()); - dto.setConcept(entity.getConcept()); - dto.setAmount(entity.getAmount()); - dto.setType(entity.getType()); - dto.setFrequency(entity.getFrequency()); - dto.setCreatedAt(entity.getCreatedAt()); - return dto; - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/model/Announcement.java b/huertos/src/main/java/net/miarma/backend/huertos/model/Announcement.java deleted file mode 100644 index 0c2cf54..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/model/Announcement.java +++ /dev/null @@ -1,108 +0,0 @@ -package net.miarma.backend.huertos.model; - -import java.time.Instant; -import java.util.UUID; - -import jakarta.persistence.*; -import net.miarma.backlib.util.UuidUtil; - -@Entity -@Table(name = "huertos_announces") -public class Announcement { - - @Id - @Column(name = "announce_id", columnDefinition = "BINARY(16)") - private byte[] announceIdBin; - - @Transient - private UUID announceId; - - @Column(name = "body", nullable = false, columnDefinition = "TEXT") - private String body; - - @Column(name = "priority", nullable = false) - private Byte priority; - - @Column(name = "published_by", columnDefinition = "BINARY(16)", nullable = false) - private byte[] publishedByBin; - - @Transient - private UUID publishedBy; - - @Column(name = "published_by_name", nullable = false) - private String publishedByName; - - @Column(name = "created_at", nullable = false) - private Instant createdAt; - - @PrePersist - @PreUpdate - private void prePersist() { - if (announceId != null) { - announceIdBin = UuidUtil.uuidToBin(announceId); - } - - if (publishedBy != null) { - publishedByBin = UuidUtil.uuidToBin(publishedBy); - } - } - - @PostLoad - private void postLoad() { - if (announceIdBin != null) { - announceId = UuidUtil.binToUUID(announceIdBin); - } - - if (publishedByBin != null) { - publishedBy = UuidUtil.binToUUID(publishedByBin); - } - } - - public UUID getAnnounceId() { - return announceId; - } - - public void setAnnounceId(UUID announceId) { - this.announceId = announceId; - } - - public String getBody() { - return body; - } - - public void setBody(String body) { - this.body = body; - } - - public Byte getPriority() { - return priority; - } - - public void setPriority(Byte priority) { - this.priority = priority; - } - - public UUID getPublishedBy() { - return publishedBy; - } - - public void setPublishedBy(UUID publishedBy) { - this.publishedBy = publishedBy; - } - - public String getPublishedByName() { - return publishedByName; - } - - public void setPublishedByName(String publishedByName) { - this.publishedByName = publishedByName; - } - - public Instant getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Instant createdAt) { - this.createdAt = createdAt; - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/model/Balance.java b/huertos/src/main/java/net/miarma/backend/huertos/model/Balance.java deleted file mode 100644 index 1beba9d..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/model/Balance.java +++ /dev/null @@ -1,58 +0,0 @@ -package net.miarma.backend.huertos.model; - -import java.math.BigDecimal; -import java.time.Instant; - -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.Table; - -@Entity -@Table(name = "huertos_balance") -public class Balance { - - @Id - private Byte id = 1; - - @Column(name = "initial_bank", nullable = false) - private BigDecimal initialBank; - - @Column(name = "initial_cash", nullable = false) - private BigDecimal initialCash; - - @Column(name = "created_at", nullable = false) - private Instant createdAt; - - public Byte getId() { - return id; - } - - public void setId(Byte id) { - this.id = id; - } - - public BigDecimal getInitialBank() { - return initialBank; - } - - public void setInitialBank(BigDecimal initialBank) { - this.initialBank = initialBank; - } - - public BigDecimal getInitialCash() { - return initialCash; - } - - public void setInitialCash(BigDecimal initialCash) { - this.initialCash = initialCash; - } - - public Instant getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Instant createdAt) { - this.createdAt = createdAt; - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/model/Expense.java b/huertos/src/main/java/net/miarma/backend/huertos/model/Expense.java deleted file mode 100644 index 081734c..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/model/Expense.java +++ /dev/null @@ -1,109 +0,0 @@ -package net.miarma.backend.huertos.model; - -import java.math.BigDecimal; -import java.time.Instant; -import java.util.UUID; - -import jakarta.persistence.*; -import net.miarma.backlib.util.UuidUtil; - -@Entity -@Table(name = "huertos_expenses") -public class Expense { - - @Id - @Column(name = "expense_id", columnDefinition = "BINARY(16)") - private byte[] expenseIdBin; - - @Transient - private UUID expenseId; - - @Column(name = "concept", nullable = false, length = 128) - private String concept; - - @Column(name = "amount", nullable = false) - private BigDecimal amount; - - @Column(name = "supplier", nullable = false, length = 128) - private String supplier; - - @Column(name = "invoice", nullable = false, length = 32) - private String invoice; - - @Column(name = "type") - private Byte type; - - @Column(name = "created_at", nullable = false) - private Instant createdAt; - - @PrePersist - @PreUpdate - private void prePersist() { - if (expenseId != null) { - expenseIdBin = UuidUtil.uuidToBin(expenseId); - } - } - - @PostLoad - private void postLoad() { - if (expenseIdBin != null) { - expenseId = UuidUtil.binToUUID(expenseIdBin); - } - } - - public UUID getExpenseId() { - return expenseId; - } - - public void setExpenseId(UUID expenseId) { - this.expenseId = expenseId; - } - - public String getConcept() { - return concept; - } - - public void setConcept(String concept) { - this.concept = concept; - } - - public BigDecimal getAmount() { - return amount; - } - - public void setAmount(BigDecimal amount) { - this.amount = amount; - } - - public String getSupplier() { - return supplier; - } - - public void setSupplier(String supplier) { - this.supplier = supplier; - } - - public String getInvoice() { - return invoice; - } - - public void setInvoice(String invoice) { - this.invoice = invoice; - } - - public Byte getType() { - return type; - } - - public void setType(Byte type) { - this.type = type; - } - - public Instant getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Instant createdAt) { - this.createdAt = createdAt; - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/model/Income.java b/huertos/src/main/java/net/miarma/backend/huertos/model/Income.java deleted file mode 100644 index 6ba6da7..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/model/Income.java +++ /dev/null @@ -1,133 +0,0 @@ -package net.miarma.backend.huertos.model; - -import java.math.BigDecimal; -import java.time.Duration; -import java.time.Instant; -import java.time.ZoneOffset; -import java.util.UUID; - -import jakarta.persistence.*; -import net.miarma.backlib.util.UuidUtil; - -@Entity -@Table(name = "huertos_incomes") -public class Income { - - @Id - @Column(name = "income_id", columnDefinition = "BINARY(16)") - private byte[] incomeIdBin; - - @Transient - private UUID incomeId; - - @Column(name = "user_id", columnDefinition = "BINARY(16)", nullable = false) - private byte[] userIdBin; - - @Transient - private UUID userId; - - @Column(name = "concept", nullable = false, length = 128) - private String concept; - - @Column(name = "amount", nullable = false) - private BigDecimal amount; - - @Column(name = "type") - private Byte type; - - @Column(name = "frequency") - private Byte frequency; - - @Column(name = "created_at", nullable = false, updatable = true) - private Instant createdAt; - - @PrePersist - @PreUpdate - private void prePersist() { - if (userId != null) { - userIdBin = UuidUtil.uuidToBin(userId); - } - - if (incomeId != null) { - incomeIdBin = UuidUtil.uuidToBin(incomeId); - } - } - - @PostLoad - private void postLoad() { - if (userIdBin != null) { - userId = UuidUtil.binToUUID(userIdBin); - } - - if (incomeIdBin != null) { - incomeId = UuidUtil.binToUUID(incomeIdBin); - } - } - - public boolean isPaid() { - Instant now = Instant.now(); - if (frequency == 0) { // BIYEARLY - return Duration.between(createdAt, now).toDays() <= 6L * 30; - } else if (frequency == 1) { // YEARLY - return Duration.between(createdAt, now).toDays() <= 12L * 30; - } else { - return false; - } - } - - public UUID getIncomeId() { - return incomeId; - } - - public void setIncomeId(UUID incomeId) { - this.incomeId = incomeId; - } - - public UUID getUserId() { - return userId; - } - - public void setUserId(UUID userId) { - this.userId = userId; - } - - public String getConcept() { - return concept; - } - - public void setConcept(String concept) { - this.concept = concept; - } - - public BigDecimal getAmount() { - return amount; - } - - public void setAmount(BigDecimal amount) { - this.amount = amount; - } - - public Byte getType() { - return type; - } - - public void setType(Byte type) { - this.type = type; - } - - public Byte getFrequency() { - return frequency; - } - - public void setFrequency(Byte frequency) { - this.frequency = frequency; - } - - public Instant getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Instant createdAt) { - this.createdAt = createdAt; - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/model/Request.java b/huertos/src/main/java/net/miarma/backend/huertos/model/Request.java deleted file mode 100644 index 9bc5dcb..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/model/Request.java +++ /dev/null @@ -1,76 +0,0 @@ -package net.miarma.backend.huertos.model; - -import java.time.Instant; -import java.util.UUID; -import jakarta.persistence.*; -import net.miarma.backlib.util.UuidUtil; - -@Entity -@Table(name = "huertos_requests") -public class Request { - - @Id - @Column(name = "request_id", columnDefinition = "BINARY(16)") - private byte[] requestIdBin; - - @Transient - private UUID requestId; - - @Column(name = "user_id", columnDefinition = "BINARY(16)") - private byte[] userIdBin; - - @Transient - private UUID userId; - - private String name; - - @Column(nullable = false) - private Byte type; - - @Column(nullable = false) - private Byte status; - - @Column(name = "created_at", nullable = false) - private Instant createdAt; - - @OneToOne(mappedBy = "request", cascade = CascadeType.ALL, fetch = FetchType.LAZY, optional = true) - private RequestMetadata metadata; - - @PrePersist - private void prePersist() { - if (requestId != null) requestIdBin = UuidUtil.uuidToBin(requestId); - if (userId != null) userIdBin = UuidUtil.uuidToBin(userId); - } - - @PostLoad - private void postLoad() { - if (requestIdBin != null) requestId = UuidUtil.binToUUID(requestIdBin); - if (userIdBin != null) userId = UuidUtil.binToUUID(userIdBin); - } - - public UUID getRequestId() { return requestId; } - public void setRequestId(UUID requestId) { this.requestId = requestId; } - - public UUID getUserId() { return userId; } - public void setUserId(UUID userId) { this.userId = userId; } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Byte getType() { return type; } - public void setType(Byte type) { this.type = type; } - - public Byte getStatus() { return status; } - public void setStatus(Byte status) { this.status = status; } - - public Instant getCreatedAt() { return createdAt; } - public void setCreatedAt(Instant createdAt) { this.createdAt = createdAt; } - - public RequestMetadata getMetadata() { return metadata; } - public void setMetadata(RequestMetadata metadata) { this.metadata = metadata; } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/model/RequestMetadata.java b/huertos/src/main/java/net/miarma/backend/huertos/model/RequestMetadata.java deleted file mode 100644 index e3c2d1b..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/model/RequestMetadata.java +++ /dev/null @@ -1,199 +0,0 @@ -package net.miarma.backend.huertos.model; - -import jakarta.persistence.*; -import net.miarma.backlib.util.UuidUtil; - -import java.time.Instant; -import java.util.UUID; - -@Entity -@Table(name = "huertos_request_metadata") -public class RequestMetadata { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @Column(name = "request_id", columnDefinition = "BINARY(16)", nullable = false, unique = true) - private byte[] requestIdBin; - - @Transient - private UUID requestId; - - @OneToOne - @JoinColumn(name = "request_id", referencedColumnName = "request_id", insertable = false, updatable = false) - private Request request; - - @Column(name = "display_name", nullable = false, length = 150) - private String displayName; - - @Column(nullable = false, length = 20) - private String dni; - - @Column(length = 30) - private String phone; - - @Column(nullable = false, length = 150) - private String email; - - @Column(length = 255) - private String address; - - @Column(name = "zip_code", length = 10) - private String zipCode; - - @Column(length = 100) - private String city; - - @Column(name = "member_number") - private Integer memberNumber; - - @Column(name = "plot_number") - private Integer plotNumber; - - @Column(nullable = false, length = 100) - private String username; - - private Byte type; - - @Column(name = "created_at", nullable = false, updatable = false) - private Instant createdAt; - - @PrePersist - private void prePersist() { - if (requestId != null) requestIdBin = UuidUtil.uuidToBin(requestId); - } - - @PostLoad - private void postLoad() { - if (requestIdBin != null) requestId = UuidUtil.binToUUID(requestIdBin); - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public byte[] getRequestIdBin() { - return requestIdBin; - } - - public void setRequestIdBin(byte[] requestIdBin) { - this.requestIdBin = requestIdBin; - } - - public UUID getRequestId() { - return requestId; - } - - public void setRequestId(UUID requestId) { - this.requestId = requestId; - } - - public Request getRequest() { - return request; - } - - public void setRequest(Request request) { - this.request = request; - } - - public String getDisplayName() { - return displayName; - } - - public void setDisplayName(String displayName) { - this.displayName = displayName; - } - - public String getDni() { - return dni; - } - - public void setDni(String dni) { - this.dni = dni; - } - - public String getPhone() { - return phone; - } - - public void setPhone(String phone) { - this.phone = phone; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - - public String getAddress() { - return address; - } - - public void setAddress(String address) { - this.address = address; - } - - public String getZipCode() { - return zipCode; - } - - public void setZipCode(String zipCode) { - this.zipCode = zipCode; - } - - public String getCity() { - return city; - } - - public void setCity(String city) { - this.city = city; - } - - public Integer getMemberNumber() { - return memberNumber; - } - - public void setMemberNumber(Integer memberNumber) { - this.memberNumber = memberNumber; - } - - public Integer getPlotNumber() { - return plotNumber; - } - - public void setPlotNumber(Integer plotNumber) { - this.plotNumber = plotNumber; - } - - public Byte getType() { - return type; - } - - public void setType(Byte type) { - this.type = type; - } - - public Instant getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Instant createdAt) { - this.createdAt = createdAt; - } - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/model/UserMetadata.java b/huertos/src/main/java/net/miarma/backend/huertos/model/UserMetadata.java deleted file mode 100644 index 997bdd4..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/model/UserMetadata.java +++ /dev/null @@ -1,157 +0,0 @@ -package net.miarma.backend.huertos.model; - -import java.time.Instant; -import java.util.UUID; - -import jakarta.persistence.*; -import net.miarma.backlib.util.UuidUtil; - -@Entity -@Table(name = "huertos_user_metadata") -public class UserMetadata { - - @Id - @Column(name = "user_id", columnDefinition = "BINARY(16)") - private byte[] userIdBin; - - @Transient - private UUID userId; - - @Column(name = "member_number", nullable = false, unique = true) - private Integer memberNumber; - - @Column(name = "plot_number", nullable = false) - private Integer plotNumber; - - @Column(name = "dni", nullable = false, unique = true, length = 9) - private String dni; - - @Column(name = "phone", nullable = false, length = 20) - private String phone; - - @Column(name = "type", nullable = false) - private Byte type; - - @Column(name = "role", nullable = false) - private Byte role; - - @Column(name = "notes") - private String notes; - - @Column(name = "created_at", nullable = false) - private Instant createdAt; - - @Column(name = "assigned_at") - private Instant assignedAt; - - @Column(name = "deactivated_at") - private Instant deactivatedAt; - - @PrePersist - @PreUpdate - private void prePersist() { - if (userId != null) { - userIdBin = UuidUtil.uuidToBin(userId); - } - } - - @PostLoad - private void postLoad() { - if (userIdBin != null) { - userId = UuidUtil.binToUUID(userIdBin); - } - } - - - public UUID getUserId() { - return userId; - } - - public void setUserId(UUID userId) { - this.userId = userId; - } - - public Integer getMemberNumber() { - return memberNumber; - } - - public void setMemberNumber(Integer memberNumber) { - this.memberNumber = memberNumber; - } - - public Integer getPlotNumber() { - return plotNumber; - } - - public void setPlotNumber(Integer plotNumber) { - this.plotNumber = plotNumber; - } - - public String getDni() { - return dni; - } - - public void setDni(String dni) { - this.dni = dni; - } - - public String getPhone() { - return phone; - } - - public void setPhone(String phone) { - this.phone = phone; - } - - public Byte getType() { - return type; - } - - public void setType(Byte type) { - this.type = type; - } - - public Byte getRole() { - return role; - } - - public void setRole(Byte role) { - this.role = role; - } - - public String getNotes() { - return notes; - } - - public void setNotes(String notes) { - this.notes = notes; - } - - public Instant getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Instant createdAt) { - this.createdAt = createdAt; - } - - public Instant getAssignedAt() { - return assignedAt; - } - - public void setAssignedAt(Instant assignedAt) { - this.assignedAt = assignedAt; - } - - public Instant getDeactivatedAt() { - return deactivatedAt; - } - - public void setDeactivatedAt(Instant deactivatedAt) { - this.deactivatedAt = deactivatedAt; - } - - public void setUserIdBin(byte[] userIdBin) { - this.userIdBin = userIdBin; - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/model/view/VBalanceWithTotals.java b/huertos/src/main/java/net/miarma/backend/huertos/model/view/VBalanceWithTotals.java deleted file mode 100644 index 0358968..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/model/view/VBalanceWithTotals.java +++ /dev/null @@ -1,72 +0,0 @@ -package net.miarma.backend.huertos.model.view; - -import jakarta.persistence.Column; -import jakarta.persistence.Entity; -import jakarta.persistence.Id; -import jakarta.persistence.Table; -import org.hibernate.annotations.Immutable; - -import java.math.BigDecimal; -import java.time.Instant; - -@Entity -@Immutable -@Table(name = "v_balance_with_totals") -public class VBalanceWithTotals { - - @Id - private Byte id; - - @Column(name = "initial_bank") - private BigDecimal initialBank; - - @Column(name = "initial_cash") - private BigDecimal initialCash; - - @Column(name = "total_bank_expenses") - private BigDecimal totalBankExpenses; - - @Column(name = "total_cash_expenses") - private BigDecimal totalCashExpenses; - - @Column(name = "total_bank_incomes") - private BigDecimal totalBankIncomes; - - @Column(name = "total_cash_incomes") - private BigDecimal totalCashIncomes; - - @Column(name = "created_at") - private Instant createdAt; - - public Byte getId() { - return id; - } - - public BigDecimal getInitialBank() { - return initialBank; - } - - public BigDecimal getInitialCash() { - return initialCash; - } - - public BigDecimal getTotalBankExpenses() { - return totalBankExpenses; - } - - public BigDecimal getTotalCashExpenses() { - return totalCashExpenses; - } - - public BigDecimal getTotalBankIncomes() { - return totalBankIncomes; - } - - public BigDecimal getTotalCashIncomes() { - return totalCashIncomes; - } - - public Instant getCreatedAt() { - return createdAt; - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/model/view/VIncomesWithInfo.java b/huertos/src/main/java/net/miarma/backend/huertos/model/view/VIncomesWithInfo.java deleted file mode 100644 index b1e5761..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/model/view/VIncomesWithInfo.java +++ /dev/null @@ -1,87 +0,0 @@ -package net.miarma.backend.huertos.model.view; - -import jakarta.persistence.*; -import net.miarma.backlib.util.UuidUtil; -import org.hibernate.annotations.Immutable; - -import java.math.BigDecimal; -import java.time.Instant; -import java.util.UUID; - -@Entity -@Immutable -@Table(name = "v_incomes_with_info") -public class VIncomesWithInfo { - - @Id - @Column(name = "income_id", columnDefinition = "BINARY(16)") - private byte[] incomeIdBin; - - @Transient - private UUID incomeId; - - @Column(name = "user_id", columnDefinition = "BINARY(16)") - private byte[] userIdBin; - - @Transient - private UUID userId; - - @Column(name = "display_name") - private String displayName; - - @Column(name = "member_number") - private Integer memberNumber; - - private String concept; - private BigDecimal amount; - private Byte type; - private Byte frequency; - - @Column(name = "created_at") - private Instant createdAt; - - @PostLoad - private void postLoad() { - if (userIdBin != null) { - userId = UuidUtil.binToUUID(userIdBin); - } - - if (incomeIdBin != null) { - incomeId = UuidUtil.binToUUID(incomeIdBin); - } - } - - public UUID getIncomeId() { - return incomeId; - } - - public UUID getUserId() { - return userId; - } - - public String getDisplayName() { - return displayName; - } - - public Integer getMemberNumber() { return memberNumber; } - - public String getConcept() { - return concept; - } - - public BigDecimal getAmount() { - return amount; - } - - public Byte getType() { - return type; - } - - public Byte getFrequency() { - return frequency; - } - - public Instant getCreatedAt() { - return createdAt; - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/repository/AnnouncementRepository.java b/huertos/src/main/java/net/miarma/backend/huertos/repository/AnnouncementRepository.java deleted file mode 100644 index 7481e64..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/repository/AnnouncementRepository.java +++ /dev/null @@ -1,7 +0,0 @@ -package net.miarma.backend.huertos.repository; - -import net.miarma.backend.huertos.model.Announcement; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface AnnouncementRepository extends JpaRepository { -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/repository/BalanceRepository.java b/huertos/src/main/java/net/miarma/backend/huertos/repository/BalanceRepository.java deleted file mode 100644 index bb96378..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/repository/BalanceRepository.java +++ /dev/null @@ -1,8 +0,0 @@ -package net.miarma.backend.huertos.repository; - -import net.miarma.backend.huertos.model.Balance; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface BalanceRepository extends JpaRepository { - -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/repository/ExpenseRepository.java b/huertos/src/main/java/net/miarma/backend/huertos/repository/ExpenseRepository.java deleted file mode 100644 index 0b6390f..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/repository/ExpenseRepository.java +++ /dev/null @@ -1,6 +0,0 @@ -package net.miarma.backend.huertos.repository; - -import net.miarma.backend.huertos.model.Expense; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface ExpenseRepository extends JpaRepository {} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/repository/IncomeRepository.java b/huertos/src/main/java/net/miarma/backend/huertos/repository/IncomeRepository.java deleted file mode 100644 index b584ac1..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/repository/IncomeRepository.java +++ /dev/null @@ -1,7 +0,0 @@ -package net.miarma.backend.huertos.repository; - -import net.miarma.backend.huertos.model.Income; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface IncomeRepository extends JpaRepository { -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/repository/RequestMetadataRepository.java b/huertos/src/main/java/net/miarma/backend/huertos/repository/RequestMetadataRepository.java deleted file mode 100644 index 49ca41f..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/repository/RequestMetadataRepository.java +++ /dev/null @@ -1,7 +0,0 @@ -package net.miarma.backend.huertos.repository; - -import net.miarma.backend.huertos.model.RequestMetadata; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface RequestMetadataRepository extends JpaRepository { -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/repository/RequestRepository.java b/huertos/src/main/java/net/miarma/backend/huertos/repository/RequestRepository.java deleted file mode 100644 index bde9669..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/repository/RequestRepository.java +++ /dev/null @@ -1,18 +0,0 @@ -package net.miarma.backend.huertos.repository; - -import net.miarma.backend.huertos.model.Request; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; - -import java.util.Optional; - -public interface RequestRepository extends JpaRepository { - @Query(""" - SELECT r FROM Request r - LEFT JOIN FETCH r.metadata - WHERE r.requestIdBin = :id - """) - Optional findByIdWithMetadata(@Param("id") byte[] id); - -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/repository/UserMetadataRepository.java b/huertos/src/main/java/net/miarma/backend/huertos/repository/UserMetadataRepository.java deleted file mode 100644 index ed54479..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/repository/UserMetadataRepository.java +++ /dev/null @@ -1,10 +0,0 @@ -package net.miarma.backend.huertos.repository; - -import net.miarma.backend.huertos.model.UserMetadata; -import org.springframework.data.jpa.repository.JpaRepository; - -import java.util.Optional; - -public interface UserMetadataRepository extends JpaRepository { - Optional findByMemberNumber(Integer memberNumber); -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/repository/view/VBalanceWithTotalsRepository.java b/huertos/src/main/java/net/miarma/backend/huertos/repository/view/VBalanceWithTotalsRepository.java deleted file mode 100644 index 232fd82..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/repository/view/VBalanceWithTotalsRepository.java +++ /dev/null @@ -1,12 +0,0 @@ -package net.miarma.backend.huertos.repository.view; - -import net.miarma.backend.huertos.model.view.VBalanceWithTotals; -import org.springframework.data.repository.Repository; - -import java.util.List; -import java.util.Optional; - -public interface VBalanceWithTotalsRepository extends Repository { - List findAll(); - Optional findById(Byte id); -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/repository/view/VIncomesWithInfoRepository.java b/huertos/src/main/java/net/miarma/backend/huertos/repository/view/VIncomesWithInfoRepository.java deleted file mode 100644 index c05f91b..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/repository/view/VIncomesWithInfoRepository.java +++ /dev/null @@ -1,12 +0,0 @@ -package net.miarma.backend.huertos.repository.view; - -import net.miarma.backend.huertos.model.view.VIncomesWithInfo; -import org.springframework.data.repository.Repository; - -import java.util.List; -import java.util.Optional; - -public interface VIncomesWithInfoRepository extends Repository { - List findAll(); - Optional findById(byte[] incomeId); -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/security/HuertosJwtFilter.java b/huertos/src/main/java/net/miarma/backend/huertos/security/HuertosJwtFilter.java deleted file mode 100644 index 0d6fb68..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/security/HuertosJwtFilter.java +++ /dev/null @@ -1,63 +0,0 @@ -package net.miarma.backend.huertos.security; - -import jakarta.servlet.FilterChain; -import jakarta.servlet.ServletException; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import net.miarma.backend.huertos.model.UserMetadata; -import net.miarma.backend.huertos.service.UserMetadataService; -import net.miarma.backlib.security.JwtService; -import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.stereotype.Component; -import org.springframework.web.filter.OncePerRequestFilter; - -import java.io.IOException; -import java.util.UUID; - -@Component -public class HuertosJwtFilter extends OncePerRequestFilter { - - private final JwtService jwtService; - private final UserMetadataService metadataService; - - public HuertosJwtFilter(JwtService jwtService, UserMetadataService metadataService) { - this.jwtService = jwtService; - this.metadataService = metadataService; - } - - @Override - protected void doFilterInternal(HttpServletRequest request, - HttpServletResponse response, - FilterChain filterChain) throws ServletException, IOException { - - String authHeader = request.getHeader("Authorization"); - if (authHeader != null && authHeader.startsWith("Bearer ")) { - String token = authHeader.substring(7); - - if (jwtService.validateToken(token)) { - UUID userId = jwtService.getUserId(token); - Byte serviceId = jwtService.getServiceId(token); - - UserMetadata metadata = metadataService.getById(userId); - - if (metadata != null) { - var principal = new HuertosPrincipal( - userId, - metadata.getRole(), - metadata.getType(), - serviceId - ); - - var auth = new UsernamePasswordAuthenticationToken( - principal, null, principal.getAuthorities() - ); - - SecurityContextHolder.getContext().setAuthentication(auth); - } - } - } - - filterChain.doFilter(request, response); - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/security/HuertosPrincipal.java b/huertos/src/main/java/net/miarma/backend/huertos/security/HuertosPrincipal.java deleted file mode 100644 index 06d3d8a..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/security/HuertosPrincipal.java +++ /dev/null @@ -1,65 +0,0 @@ -package net.miarma.backend.huertos.security; - -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.authority.SimpleGrantedAuthority; -import org.springframework.security.core.userdetails.UserDetails; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.UUID; - -public class HuertosPrincipal implements UserDetails { - - private final UUID userId; - private final Byte role; - private final Byte type; - private final Byte serviceId; - - public HuertosPrincipal(UUID userId, Byte role, Byte type, Byte serviceId) { - this.userId = userId; - this.role = role; - this.type = type; - this.serviceId = serviceId; - } - - public UUID getUserId() { return userId; } - public Byte getHuertosRole() { return role; } - public Byte getHuertosType() { return type; } - public Byte getServiceId() { return serviceId; } - - @Override - public Collection getAuthorities() { - List auth = new ArrayList<>(); - - String roleName = switch(role) { - case 0 -> "USER"; - case 1 -> "ADMIN"; - case 2 -> "DEV"; - default -> "USER"; - }; - - String typeName = switch(type) { - case 0 -> "WAIT_LIST"; - case 1 -> "MEMBER"; - case 2 -> "WITH_GREENHOUSE"; - case 3 -> "COLLABORATOR"; - case 4 -> "SUBSIDY"; - case 5 -> "DEVELOPER"; - default -> "WAIT_LIST"; - }; - - auth.add(new SimpleGrantedAuthority("ROLE_HUERTOS_ROLE_" + roleName)); - auth.add(new SimpleGrantedAuthority("ROLE_HUERTOS_TYPE_" + typeName)); - - return auth; - } - - @Override public String getPassword() { return ""; } - @Override public String getUsername() { return userId.toString(); } - @Override public boolean isAccountNonExpired() { return true; } - @Override public boolean isAccountNonLocked() { return true; } - @Override public boolean isCredentialsNonExpired() { return true; } - @Override public boolean isEnabled() { return true; } -} - diff --git a/huertos/src/main/java/net/miarma/backend/huertos/security/NameCensorer.java b/huertos/src/main/java/net/miarma/backend/huertos/security/NameCensorer.java deleted file mode 100644 index 5e144aa..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/security/NameCensorer.java +++ /dev/null @@ -1,36 +0,0 @@ -package net.miarma.backend.huertos.security; - - -/** - * Clase de utilidad para censurar nombres. - * Censura los nombres dejando las primeras 3 letras visibles y el resto con asteriscos. - * Si el nombre es muy largo, lo acorta a 16 caracteres y añade "..." al final. - * @author José Manuel Amador Gallardo - */ -public class NameCensorer { - - public static String censor(String name) { - if (name == null || name.isBlank()) return ""; - - String[] words = name.trim().split("\\s+"); - - for (int i = 0; i < words.length; i++) { - String word = words[i]; - int len = word.length(); - - if (len > 3) { - words[i] = word.substring(0, 3) + "*".repeat(len - 3); - } else if (len > 0) { - words[i] = word.charAt(0) + "*".repeat(len - 1); - } - } - - String censored = String.join(" ", words); - - if (censored.length() > 16) { - censored = censored.substring(0, 16) + "..."; - } - - return censored; - } -} \ No newline at end of file diff --git a/huertos/src/main/java/net/miarma/backend/huertos/service/AnnouncementService.java b/huertos/src/main/java/net/miarma/backend/huertos/service/AnnouncementService.java deleted file mode 100644 index 481fdbe..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/service/AnnouncementService.java +++ /dev/null @@ -1,71 +0,0 @@ -package net.miarma.backend.huertos.service; - -import jakarta.transaction.Transactional; -import net.miarma.backend.huertos.dto.AnnouncementDto; -import net.miarma.backend.huertos.model.Announcement; -import net.miarma.backend.huertos.model.Income; -import net.miarma.backend.huertos.repository.AnnouncementRepository; -import net.miarma.backlib.exception.NotFoundException; -import net.miarma.backlib.util.UuidUtil; -import org.springframework.stereotype.Service; - -import java.time.Instant; -import java.util.Comparator; -import java.util.List; -import java.util.UUID; - -@Service -@Transactional -public class AnnouncementService { - - private final AnnouncementRepository announcementRepository; - private final MemberService memberService; - - public AnnouncementService(AnnouncementRepository announcementRepository, MemberService memberService) { - this.announcementRepository = announcementRepository; - this.memberService = memberService; - } - - public List getAll() { - return announcementRepository.findAll().stream() - .sorted(Comparator.comparing(Announcement::getCreatedAt).reversed()) - .toList(); - } - - public Announcement getById(UUID announceId) { - byte[] idBytes = UuidUtil.uuidToBin(announceId); - return announcementRepository.findById(idBytes) - .orElseThrow(() -> new NotFoundException("Anuncio no encontrado")); - } - - public Announcement create(Announcement announcement) { - if (announcement.getAnnounceId() == null) { - announcement.setAnnounceId(UUID.randomUUID()); - } - announcement.setPublishedByName(memberService.getById(announcement.getPublishedBy()).user().getDisplayName()); - announcement.setCreatedAt(Instant.now()); - return announcementRepository.save(announcement); - } - - public Announcement update(UUID announceId, Announcement changes) { - Announcement announcement = getById(announceId); - - if (changes.getBody() != null) - announcement.setBody(changes.getBody()); - - if (changes.getPriority() != null) - announcement.setPriority(changes.getPriority()); - - if (changes.getPublishedBy() != null) - announcement.setPublishedBy(changes.getPublishedBy()); - - return announcementRepository.save(announcement); - } - - public void delete(UUID announceId) { - byte[] idBytes = UuidUtil.uuidToBin(announceId); - if (!announcementRepository.existsById(idBytes)) - throw new NotFoundException("Anuncio no encontrado"); - announcementRepository.deleteById(idBytes); - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/service/BalanceService.java b/huertos/src/main/java/net/miarma/backend/huertos/service/BalanceService.java deleted file mode 100644 index b97dd3d..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/service/BalanceService.java +++ /dev/null @@ -1,62 +0,0 @@ -package net.miarma.backend.huertos.service; - -import java.time.Instant; - -import net.miarma.backend.huertos.model.view.VBalanceWithTotals; -import net.miarma.backend.huertos.repository.view.VBalanceWithTotalsRepository; -import net.miarma.backlib.exception.ConflictException; -import net.miarma.backlib.exception.NotFoundException; -import org.springframework.stereotype.Service; - -import jakarta.transaction.Transactional; -import net.miarma.backend.huertos.model.Balance; -import net.miarma.backend.huertos.repository.BalanceRepository; - -@Service -@Transactional -public class BalanceService { - - private final BalanceRepository balanceRepository; - private final VBalanceWithTotalsRepository vBalanceWithTotalsRepository; - - public BalanceService(BalanceRepository balanceRepository, VBalanceWithTotalsRepository vBalanceWithTotalsRepository) { - this.balanceRepository = balanceRepository; - this.vBalanceWithTotalsRepository = vBalanceWithTotalsRepository; - } - - public Balance get() { - return balanceRepository.findById((byte) 1) - .orElseThrow(() -> new NotFoundException("Balance no encontrado")); - } - - public VBalanceWithTotals getWithTotals() { - return vBalanceWithTotalsRepository.findById((byte) 1) - .orElseThrow(() -> new NotFoundException("Balance no encontrado")); - } - - public Balance create(Balance balance) { - if (balanceRepository.existsById((byte) 1)) { - throw new ConflictException("Ya hay un valor de balance en la base de datos"); - } - balance.setId((byte) 1); - balance.setCreatedAt(Instant.now()); - return balanceRepository.save(balance); - } - - public Balance update(Balance dto) { - Balance balance = balanceRepository.findById((byte) 1) - .orElseThrow(() -> new NotFoundException("Balance no encontrado")); - - if (dto.getInitialBank() != null) balance.setInitialBank(dto.getInitialBank()); - if (dto.getInitialCash() != null) balance.setInitialCash(dto.getInitialCash()); - - return balanceRepository.save(balance); - } - - public void delete() { - if (!balanceRepository.existsById((byte) 1)) { - throw new NotFoundException("Balance no encontrado"); - } - balanceRepository.deleteById((byte) 1); - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/service/CoreAuthService.java b/huertos/src/main/java/net/miarma/backend/huertos/service/CoreAuthService.java deleted file mode 100644 index 1079b0e..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/service/CoreAuthService.java +++ /dev/null @@ -1,60 +0,0 @@ -package net.miarma.backend.huertos.service; - -import net.miarma.backend.huertos.client.HuertosWebClient; -import net.miarma.backlib.dto.LoginRequest; -import net.miarma.backlib.dto.LoginResponse; -import net.miarma.backlib.security.CoreAuthTokenHolder; -import net.miarma.backlib.security.JwtService; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Service; -import org.springframework.web.client.RestTemplate; -import tools.jackson.databind.ObjectMapper; - -import java.time.Instant; - -@Service -public class CoreAuthService { - - private final RestTemplate authRestTemplate; - private final CoreAuthTokenHolder tokenHolder; - private final JwtService jwtService; - - @Value("${huertos.user}") - private String username; - - @Value("${huertos.password}") - private String password; - - @Value("${core.url}") - private String coreUrl; - - public CoreAuthService(@Qualifier("authRestTemplate") RestTemplate authRestTemplate, - CoreAuthTokenHolder tokenHolder, - JwtService jwtService) { - this.authRestTemplate = authRestTemplate; - this.tokenHolder = tokenHolder; - this.jwtService = jwtService; - } - - public synchronized String getToken() { - if (tokenHolder.getToken() == null || tokenHolder.isExpired()) { - refreshToken(); - } - return tokenHolder.getToken(); - } - - private void refreshToken() { - var req = new LoginRequest(username, password, (byte) 1); - - LoginResponse resp = authRestTemplate.postForObject( - coreUrl + "/auth/login", - req, - LoginResponse.class - ); - - String token = resp.token(); - Instant exp = jwtService.getExpiration(token).toInstant(); - tokenHolder.setToken(token, exp); - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/service/ExpenseService.java b/huertos/src/main/java/net/miarma/backend/huertos/service/ExpenseService.java deleted file mode 100644 index e653328..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/service/ExpenseService.java +++ /dev/null @@ -1,96 +0,0 @@ -package net.miarma.backend.huertos.service; - -import jakarta.transaction.Transactional; -import net.miarma.backend.huertos.dto.ExpenseDto; -import net.miarma.backend.huertos.model.Expense; -import net.miarma.backend.huertos.model.Income; -import net.miarma.backend.huertos.repository.ExpenseRepository; -import net.miarma.backlib.exception.NotFoundException; -import net.miarma.backlib.exception.ValidationException; -import net.miarma.backlib.util.UuidUtil; -import org.springframework.stereotype.Service; - -import java.time.Instant; -import java.util.Comparator; -import java.util.List; -import java.util.UUID; - -@Service -@Transactional -public class ExpenseService { - - private final ExpenseRepository expenseRepository; - - public ExpenseService(ExpenseRepository expenseRepository) { - this.expenseRepository = expenseRepository; - } - - public List getAll() { - return expenseRepository.findAll().stream() - .sorted(Comparator.comparing(Expense::getCreatedAt).reversed()) - .toList(); - } - - public Expense getById(UUID expenseId) { - byte[] idBytes = UuidUtil.uuidToBin(expenseId); - return expenseRepository.findById(idBytes) - .orElseThrow(() -> new NotFoundException("Gasto no encontrado")); - } - - public Expense create(Expense expense) { - if (expense.getConcept() == null || expense.getConcept().isBlank()) { - throw new ValidationException("concept", "El concepto es obligatorio"); - } - if (expense.getAmount() == null) { - throw new ValidationException("amount", "La cantidad es obligatoria"); - } - if (expense.getSupplier() == null || expense.getSupplier().isBlank()) { - throw new ValidationException("supplier", "El proveedor es obligatorio"); - } - if (expense.getInvoice() == null || expense.getInvoice().isBlank()) { - throw new ValidationException("invoice", "La factura es obligatoria"); - } - if (expense.getCreatedAt() == null) { - expense.setCreatedAt(Instant.now()); - } - - expense.setExpenseId(UUID.randomUUID()); - - return expenseRepository.save(expense); - } - - public Expense update(UUID expenseId, Expense changes) { - byte[] idBytes = UuidUtil.uuidToBin(expenseId); - - Expense expense = expenseRepository.findById(idBytes) - .orElseThrow(() -> new NotFoundException("Gasto no encontrado")); - - if (changes.getConcept() != null) - expense.setConcept(changes.getConcept()); - - if (changes.getAmount() != null) - expense.setAmount(changes.getAmount()); - - if (changes.getSupplier() != null) - expense.setSupplier(changes.getSupplier()); - - if (changes.getInvoice() != null) - expense.setInvoice(changes.getInvoice()); - - if (changes.getType() != null) - expense.setType(changes.getType()); - - if (changes.getCreatedAt() != null) - expense.setCreatedAt(changes.getCreatedAt()); - - return expenseRepository.save(expense); - } - - public void delete(UUID expenseId) { - byte[] idBytes = UuidUtil.uuidToBin(expenseId); - if (!expenseRepository.existsById(idBytes)) { - throw new NotFoundException("Gasto no encontrado"); - } - expenseRepository.deleteById(idBytes); - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/service/IncomeService.java b/huertos/src/main/java/net/miarma/backend/huertos/service/IncomeService.java deleted file mode 100644 index 91edbf5..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/service/IncomeService.java +++ /dev/null @@ -1,128 +0,0 @@ -package net.miarma.backend.huertos.service; - -import java.time.Instant; -import java.time.temporal.TemporalAmount; -import java.util.Comparator; -import java.util.List; -import java.util.UUID; - -import net.miarma.backend.huertos.model.view.VIncomesWithInfo; -import net.miarma.backend.huertos.service.view.VIncomesWithInfoService; -import net.miarma.backlib.exception.BadRequestException; -import net.miarma.backlib.exception.NotFoundException; -import net.miarma.backlib.exception.ValidationException; -import org.springframework.stereotype.Service; - -import jakarta.transaction.Transactional; -import net.miarma.backend.huertos.model.Income; -import net.miarma.backend.huertos.repository.IncomeRepository; -import net.miarma.backlib.util.UuidUtil; - -@Service -@Transactional -public class IncomeService { - - private final IncomeRepository incomeRepository; - private final VIncomesWithInfoService incomesWithInfoService; - private final UserMetadataService metadataService; - - public IncomeService(IncomeRepository incomeRepository, - VIncomesWithInfoService incomesWithInfoService, - UserMetadataService metadataService) { - this.incomeRepository = incomeRepository; - this.incomesWithInfoService = incomesWithInfoService; - this.metadataService = metadataService; - } - - public List getAll() { - return incomeRepository.findAll().stream() - .sorted(Comparator.comparing(Income::getCreatedAt).reversed()) - .toList(); - } - - public Income getById(UUID incomeId) { - byte[] idBytes = UuidUtil.uuidToBin(incomeId); - return incomeRepository.findById(idBytes) - .orElseThrow(() -> new NotFoundException("Ingreso no encontrado")); - } - - public List getByUserId(UUID userId) { - return incomeRepository.findAll().stream() - .filter(i -> i.getUserId().equals(userId)) - .toList(); - } - - public Income create(Income income) { - if (income.getUserId() == null) { - throw new BadRequestException("El identificador de usuario es obligatorio"); - } - if (income.getConcept() == null) { - throw new BadRequestException("El concepto es obligatorio"); - } - if (income.getConcept().isBlank() || income.getConcept().isEmpty()) { - throw new ValidationException("concept", "El concepto no puede ir vacío"); - } - if (income.getAmount() == null || income.getAmount().signum() <= 0) { - throw new ValidationException("amount", "La cantidad debe ser positiva"); - } - if (income.getCreatedAt() == null) { - income.setCreatedAt(Instant.now()); - } - - income.setIncomeId(UUID.randomUUID()); - - return incomeRepository.save(income); - } - - public Income update(UUID incomeId, Income changes) { - byte[] idBytes = UuidUtil.uuidToBin(incomeId); - - Income income = incomeRepository.findById(idBytes) - .orElseThrow(() -> new NotFoundException("Ingreso no encontrado")); - - if (changes.getConcept() != null) income.setConcept(changes.getConcept()); - if (changes.getAmount() != null) { - if (changes.getAmount().signum() <= 0) { - throw new ValidationException("amount", "La cantidad debe ser positiva"); - } - income.setAmount(changes.getAmount()); - } - if (changes.getType() != null) income.setType(changes.getType()); - if (changes.getFrequency() != null) income.setFrequency(changes.getFrequency()); - if (changes.getCreatedAt() != null && !changes.getCreatedAt().equals(income.getCreatedAt())) { - income.setCreatedAt(changes.getCreatedAt()); - } - - return incomeRepository.save(income); - } - - public void delete(UUID incomeId) { - byte[] idBytes = UuidUtil.uuidToBin(incomeId); - - if (!incomeRepository.existsById(idBytes)) { - throw new NotFoundException("Ingreso no encontrado"); - } - - incomeRepository.deleteById(idBytes); - } - - public Boolean existsByMemberNumber(Integer memberNumber) { - try { - UUID userId = metadataService.getByMemberNumber(memberNumber).getUserId(); - return !getByUserId(userId).isEmpty(); - } catch (Exception e) { - return false; - } - } - - public Boolean hasPaid(Integer memberNumber) { - UUID userId = metadataService.getByMemberNumber(memberNumber).getUserId(); - List incomes = getByUserId(userId); - return !incomes.isEmpty() && incomes.stream().allMatch(Income::isPaid); - } - - public List getByMemberNumber(Integer memberNumber) { - UUID userId = metadataService.getByMemberNumber(memberNumber).getUserId(); - return incomesWithInfoService.getByUserId(userId); - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/service/MemberService.java b/huertos/src/main/java/net/miarma/backend/huertos/service/MemberService.java deleted file mode 100644 index ad2dbe1..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/service/MemberService.java +++ /dev/null @@ -1,217 +0,0 @@ - package net.miarma.backend.huertos.service; - - import net.miarma.backend.huertos.client.HuertosWebClient; - import net.miarma.backend.huertos.dto.*; - import net.miarma.backend.huertos.dto.view.VIncomesWithInfoDto; - import net.miarma.backend.huertos.mapper.DropdownDtoMapper; - import net.miarma.backend.huertos.mapper.RequestMapper; - 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.CacheEvict; - import org.springframework.cache.annotation.Cacheable; - import org.springframework.stereotype.Service; - - import java.util.Comparator; - import java.util.List; - import java.util.UUID; - - @Service - public class MemberService { - private final HuertosWebClient huertosWebClient; - private final IncomeService incomeService; - private final RequestService requestService; - private final UserMetadataService metadataService; - - public MemberService(HuertosWebClient huertosWebClient, - IncomeService incomeService, - RequestService requestService, - UserMetadataService metadataService) { - this.huertosWebClient = huertosWebClient; - this.incomeService = incomeService; - this.requestService = requestService; - this.metadataService = metadataService; - } - - @Cacheable(value = "memberById") - public MemberDto getById(UUID userId) { - var uwc = huertosWebClient.getUserWithCredential(userId, (byte)1); - if (uwc == null) { - throw new NotFoundException("Socio no encontrado"); - } - - var meta = metadataService.getById(userId); - if (meta == null) { - throw new NotFoundException("User metadata not found"); - } - - return new MemberDto( - uwc.user(), - uwc.account(), - UserMetadataMapper.toDto(meta) - ); - } - - @Cacheable("members") - public List getAll() { - List all = huertosWebClient.getAllUsersWithCredentials((byte)1); - - return all.stream() - .filter(uwc -> metadataService.existsById(uwc.user().getUserId())) - .map(uwc -> { - var meta = metadataService.getById(uwc.user().getUserId()); - return new MemberDto( - uwc.user(), - uwc.account(), - UserMetadataMapper.toDto(meta) - ); - }) - .sorted(Comparator.comparing(dto -> dto.metadata().getMemberNumber())) - .toList(); - } - - public MemberProfileDto getMyProfile(UUID userId) { - MemberDto member = getById(userId); - Integer memberNumber = member.metadata().getMemberNumber(); - - List requests = requestService.getByUserId(userId).stream() - .map(RequestMapper::toResponse) - .toList(); - - List payments = incomeService.getByMemberNumber(memberNumber).stream() - .map(VIncomesWithInfoMapper::toResponse) - .toList(); - - return new MemberProfileDto( - member.user(), - member.account(), - member.metadata(), - requests, - payments, - hasCollaborator(memberNumber), - hasGreenhouse(memberNumber), - hasCollaboratorRequest(memberNumber), - hasGreenhouseRequest(memberNumber) - ); - } - - public Integer getLatestMemberNumber() { - return metadataService.getLatestMemberNumber(); - } - - @Cacheable("waitlist") - public List getWaitlist() { - List all = huertosWebClient.getAllUsersWithCredentials((byte)1); - - return all.stream() - .filter(uwc -> metadataService.existsById(uwc.user().getUserId())) - .filter(uwc -> uwc.account().getStatus() != 0) - .map(uwc -> { - var meta = metadataService.getById(uwc.user().getUserId()); - return new MemberDto(uwc.user(), uwc.account(), - UserMetadataMapper.toDto(meta)); - }) - .filter(dto -> dto.metadata().getType().equals((byte) 0)) - .sorted(Comparator.comparing(dto -> dto.metadata().getCreatedAt())) - .toList(); - } - - public List getWaitlistLimited() { - return getWaitlist().stream() - .map(dto -> { - WaitlistCensoredDto censored = new WaitlistCensoredDto(); - censored.setName(NameCensorer.censor(dto.user().getDisplayName())); - return censored; - }) - .toList(); - } - - public MemberDto getByMemberNumber(Integer memberNumber) { - return getAll().stream() - .filter(dto -> dto.metadata().getMemberNumber().equals(memberNumber)) - .findFirst() - .orElseThrow(() -> new NotFoundException("No hay socio con ese número")); - } - - public MemberDto getByPlotNumber(Integer plotNumber) { - return getAll().stream() - .filter(dto -> dto.metadata().getPlotNumber().equals(plotNumber)) - .findFirst() - .orElseThrow(() -> new NotFoundException("No hay socio con ese huerto")); - } - - public MemberDto getByDni(String dni) { - return getAll().stream() - .filter(dto -> dni.equals(dto.metadata().getDni())) - .findFirst() - .orElseThrow(() -> new NotFoundException("No hay socio con ese DNI")); - } - - public List getIncomes(Integer memberNumber) { - return incomeService.getByMemberNumber(memberNumber).stream() - .map(VIncomesWithInfoMapper::toResponse) - .toList(); - } - - public Boolean hasPaid(Integer memberNumber) { - return incomeService.hasPaid(memberNumber); - } - - public Boolean hasCollaborator(Integer memberNumber) { - List all = getAll(); - - var member = all.stream() - .filter(dto -> dto.metadata().getMemberNumber().equals(memberNumber)) - .findFirst() - .orElse(null); - - if (member == null) return false; - - Integer plotNumber = member.metadata().getPlotNumber(); - if (plotNumber == null) return false; - - List plotMembers = all.stream() - .filter(dto -> plotNumber.equals(dto.metadata().getPlotNumber())) - .toList(); - - return plotMembers.stream() - .anyMatch(dto -> dto.metadata().getType().equals((byte)3)); - } - - public Boolean hasGreenhouse(Integer memberNumber) { - return metadataService.getByMemberNumber(memberNumber).getType().equals((byte)2); - } - - public Boolean hasCollaboratorRequest(Integer memberNumber) { - UUID userId = metadataService.getByMemberNumber(memberNumber).getUserId(); - return requestService.hasCollaboratorRequest(userId); - } - - public Boolean hasGreenhouseRequest(Integer memberNumber) { - UUID userId = metadataService.getByMemberNumber(memberNumber).getUserId(); - return requestService.hasGreenhouseRequest(userId); - } - - public List getDropdown() { - return getAll().stream() - .map(DropdownDtoMapper::toDto) - .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; - } - } diff --git a/huertos/src/main/java/net/miarma/backend/huertos/service/RequestAcceptanceService.java b/huertos/src/main/java/net/miarma/backend/huertos/service/RequestAcceptanceService.java deleted file mode 100644 index 50bc655..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/service/RequestAcceptanceService.java +++ /dev/null @@ -1,140 +0,0 @@ -package net.miarma.backend.huertos.service; - -import jakarta.transaction.Transactional; -import net.miarma.backend.huertos.client.HuertosWebClient; -import net.miarma.backend.huertos.mapper.RequestMetadataMapper; -import net.miarma.backend.huertos.model.Request; -import net.miarma.backend.huertos.model.RequestMetadata; -import net.miarma.backend.huertos.model.UserMetadata; -import net.miarma.backlib.dto.UserWithCredentialDto; -import net.miarma.backlib.exception.BadRequestException; -import org.springframework.stereotype.Service; - -import java.util.UUID; - -@Service -public class RequestAcceptanceService { - - private final RequestService requestService; - private final UserMetadataService metadataService; - private final HuertosWebClient huertosWebClient; - private final MemberService memberService; - - public RequestAcceptanceService( - RequestService requestService, - UserMetadataService metadataService, - HuertosWebClient huertosWebClient, - MemberService memberService - ) { - this.requestService = requestService; - this.metadataService = metadataService; - this.huertosWebClient = huertosWebClient; - this.memberService = memberService; - } - - public Request acceptRequest(UUID requestId) { - Request request = requestService.accept(requestId); - - if (request.getMetadata() == null) { - throw new BadRequestException("No hay metadata asociada"); - } - - return request; - } - - public void handleSideEffects(Request request) { - RequestMetadata metadata = request.getMetadata(); - - switch (request.getType()) { - - case 0: // REGISTER - handleRegister(metadata); - break; - - case 1: // UNREGISTER - handleUnregister(metadata); - break; - - case 2: // ADD_COLLABORATOR - handleAddCollaborator(metadata); - break; - - case 3: // REMOVE_COLLABORATOR - handleRemoveCollaborator(metadata); - break; - - case 4: // ADD_GREENHOUSE - handleAddGreenhouse(metadata); - break; - - case 5: // REMOVE_GREENHOUSE - handleRemoveGreenhouse(metadata); - break; - - default: - throw new BadRequestException("Tipo de solicitud no soportado"); - } - } - - private void handleRegister(RequestMetadata metadata) { - UserWithCredentialDto createdUser = - huertosWebClient.createUser(RequestMetadataMapper.toDto(metadata)); - - UserMetadata userMetadata = buildBaseUserMetadata(metadata, createdUser.user().getUserId()); - userMetadata.setType((byte) 0); // socio - userMetadata.setRole((byte) 0); - - metadataService.create(userMetadata); - } - - private void handleUnregister(RequestMetadata metadata) { - UserMetadata toRemove = metadataService.getByMemberNumber(metadata.getMemberNumber()); - huertosWebClient.updateCredentialStatus(toRemove.getUserId(), (byte)1, (byte)0); - } - - private void handleAddCollaborator(RequestMetadata metadata) { - UserWithCredentialDto newCollab = - huertosWebClient.createUser(RequestMetadataMapper.toDto(metadata)); - - UserMetadata collabMeta = buildBaseUserMetadata( - metadata, - newCollab.user().getUserId() - ); - - collabMeta.setType((byte) 3); // colaborador - collabMeta.setRole((byte) 0); - - metadataService.create(collabMeta); - } - - private void handleRemoveCollaborator(RequestMetadata metadata) { - UserMetadata collab = metadataService.getByMemberNumber(metadata.getMemberNumber()); - huertosWebClient.updateCredentialStatus(collab.getUserId(), (byte)1, (byte)0); - } - - private void handleAddGreenhouse(RequestMetadata metadata) { - UserMetadata user = - metadataService.getByMemberNumber(metadata.getMemberNumber()); - - user.setType((byte) 2); // invernadero - metadataService.update(user.getUserId(), user); - } - - private void handleRemoveGreenhouse(RequestMetadata metadata) { - UserMetadata user = - metadataService.getByMemberNumber(metadata.getMemberNumber()); - - user.setType((byte) 1); // socio normal - metadataService.update(user.getUserId(), user); - } - - private UserMetadata buildBaseUserMetadata(RequestMetadata metadata, UUID userId) { - UserMetadata um = new UserMetadata(); - um.setUserId(userId); - um.setMemberNumber(metadata.getMemberNumber()); - um.setPlotNumber(metadata.getPlotNumber()); - um.setDni(metadata.getDni()); - um.setPhone(metadata.getPhone()); - return um; - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/service/RequestService.java b/huertos/src/main/java/net/miarma/backend/huertos/service/RequestService.java deleted file mode 100644 index ae24e52..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/service/RequestService.java +++ /dev/null @@ -1,140 +0,0 @@ -package net.miarma.backend.huertos.service; - -import java.time.Instant; -import java.util.List; -import java.util.UUID; - -import net.miarma.backend.huertos.dto.RequestDto; -import net.miarma.backend.huertos.dto.RequestMetadataDto; -import net.miarma.backend.huertos.mapper.RequestMapper; -import net.miarma.backend.huertos.mapper.RequestMetadataMapper; -import net.miarma.backend.huertos.validation.RequestValidator; -import net.miarma.backlib.exception.ConflictException; -import org.springframework.stereotype.Service; -import jakarta.transaction.Transactional; - -import net.miarma.backend.huertos.model.Request; -import net.miarma.backend.huertos.model.RequestMetadata; -import net.miarma.backend.huertos.repository.RequestRepository; -import net.miarma.backend.huertos.repository.RequestMetadataRepository; -import net.miarma.backlib.exception.BadRequestException; -import net.miarma.backlib.exception.NotFoundException; -import net.miarma.backlib.util.UuidUtil; - -@Service -@Transactional -public class RequestService { - - private final RequestRepository requestRepository; - private final RequestMetadataRepository metadataRepository; - - public RequestService(RequestRepository requestRepository, - RequestMetadataRepository metadataRepository) { - this.requestRepository = requestRepository; - this.metadataRepository = metadataRepository; - } - - public List getAll() { - return requestRepository.findAll(); - } - - public Request getById(UUID requestId) { - return requestRepository.findById(UuidUtil.uuidToBin(requestId)) - .orElseThrow(() -> new NotFoundException("Solicitud no encontrada")); - } - - public List getByUserId(UUID userId) { - return requestRepository.findAll().stream() - .filter(r -> r.getUserId() != null && r.getUserId().equals(userId)) - .toList(); - } - - @Transactional - public Request create(Request request) { - - if (request == null) { - throw new BadRequestException("La solicitud es obligatoria"); - } - - if (request.getType() == null) { - throw new BadRequestException("El tipo de solicitud es obligatorio"); - } - - if (request.getType() == 1 && hasUnregisterRequest(request.getUserId())) { - throw new ConflictException("Ya tienes una solicitud, espera que se acepte o se elimine al ser rechazada"); - } - - if ((request.getType() == 2 || request.getType() == 3) && - hasCollaboratorRequest(request.getUserId())) { // tiene soli de collab - throw new ConflictException("Ya tienes una solicitud, espera que se acepte o se elimine al ser rechazada"); - } - - if ((request.getType() == 4 || request.getType() == 5) && - hasGreenhouseRequest(request.getUserId())) { // tiene soli de invernadero - throw new ConflictException("Ya tienes una solicitud, espera que se acepte o se elimine al ser rechazada"); - } - - request.setRequestId(UUID.randomUUID()); - request.setCreatedAt(Instant.now()); - request.getMetadata().setRequestId(request.getRequestId()); - - if (request.getMetadata() != null) { - RequestValidator.validate(request.getMetadata(), request.getType()); - } - - return requestRepository.save(request); - } - - public Request update(UUID requestId, Request changes) { - Request request = getById(requestId); - - if (changes.getType() != null) request.setType(changes.getType()); - if (changes.getStatus() != null) request.setStatus(changes.getStatus()); - if (changes.getUserId() != null) request.setUserId(changes.getUserId()); - - return requestRepository.save(request); - } - - public Request accept(UUID requestId) { - byte[] bin = UuidUtil.uuidToBin(requestId); - Request request = requestRepository.findByIdWithMetadata(bin) - .orElseThrow(() -> new NotFoundException("Request no encontrada")); - if (request.getStatus() != 0) { - throw new BadRequestException("La solicitud ya ha sido procesada"); - } - request.setStatus((byte)1); - return requestRepository.save(request); - } - - public Request reject(UUID requestId) { - Request request = getById(requestId); - if (request.getStatus() != 0) { - throw new BadRequestException("La solicitud ya ha sido procesada"); - } - request.setStatus((byte)2); - return requestRepository.save(request); - } - - public void delete(UUID requestId) { - UUID id = requestId; - if (!requestRepository.existsById(UuidUtil.uuidToBin(id))) { - throw new NotFoundException("Solicitud no encontrada"); - } - requestRepository.deleteById(UuidUtil.uuidToBin(id)); - } - - public boolean hasGreenhouseRequest(UUID userId) { - return getByUserId(userId).stream() - .anyMatch(r -> r.getType() == 4 || r.getType() == 5); - } - - public boolean hasCollaboratorRequest(UUID userId) { - return getByUserId(userId).stream() - .anyMatch(r -> r.getType() == 2 || r.getType() == 3); - } - - public boolean hasUnregisterRequest(UUID userId) { - return getByUserId(userId).stream() - .anyMatch(r -> r.getType() == 1); - } -} \ No newline at end of file diff --git a/huertos/src/main/java/net/miarma/backend/huertos/service/UserMetadataService.java b/huertos/src/main/java/net/miarma/backend/huertos/service/UserMetadataService.java deleted file mode 100644 index eb96546..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/service/UserMetadataService.java +++ /dev/null @@ -1,120 +0,0 @@ -package net.miarma.backend.huertos.service; - -import java.time.Instant; -import java.util.List; -import java.util.UUID; - -import net.miarma.backlib.exception.BadRequestException; -import net.miarma.backlib.exception.ConflictException; -import net.miarma.backlib.exception.NotFoundException; -import org.springframework.cache.annotation.CacheEvict; -import org.springframework.cache.annotation.Cacheable; -import org.springframework.stereotype.Service; - -import jakarta.transaction.Transactional; -import net.miarma.backend.huertos.model.UserMetadata; -import net.miarma.backend.huertos.repository.UserMetadataRepository; -import net.miarma.backlib.util.UuidUtil; - -@Service -@Transactional -public class UserMetadataService { - - private final UserMetadataRepository repository; - - public UserMetadataService(UserMetadataRepository repository) { - this.repository = repository; - } - - public List getAll() { - return repository.findAll(); - } - - @Cacheable("metadataByUserId") - public UserMetadata getById(UUID userId) { - byte[] idBytes = UuidUtil.uuidToBin(userId); - return repository.findById(idBytes) - .orElseThrow(() -> new NotFoundException("Metadatos de usuario no encontrados")); - } - - @Cacheable("metadataByMemberNumber") - public UserMetadata getByMemberNumber(Integer memberNumber) { - return repository.findByMemberNumber(memberNumber) - .orElseThrow(() -> new NotFoundException("Metadatos de usuario no encontrados")); - } - - @Cacheable("metadataExists") - public boolean existsById(UUID userId) { - byte[] idBytes = UuidUtil.uuidToBin(userId); - return repository.existsById(idBytes); - } - - public UserMetadata create(UserMetadata meta) { - if (meta.getUserId() == null) { - throw new BadRequestException("El identificador de usuario es obligatorio"); - } - if (repository.existsById(UuidUtil.uuidToBin(meta.getUserId()))) { - throw new ConflictException("Este usuario ya tiene metadatos asociados"); - } - - if (meta.getMemberNumber() == null) throw new BadRequestException("El número de socio es obligatorio"); - if (meta.getPlotNumber() == null) throw new BadRequestException("El número de huerto es obligatorio"); - if (meta.getDni() == null || meta.getDni().isBlank()) throw new BadRequestException("El DNI es obligatorio"); - if (meta.getPhone() == null || meta.getPhone().isBlank()) throw new BadRequestException("El teléfono es obligatorio"); - if (meta.getType() == null) meta.setType((byte) 0); - if (meta.getRole() == null) meta.setRole((byte) 0); - - meta.setCreatedAt(Instant.now()); - meta.setAssignedAt(null); - meta.setDeactivatedAt(null); - - return repository.save(meta); - } - - @CacheEvict( - value = { - "metadataByUserId", - "metadataByMemberNumber", - "metadataExists" - }, - key = "#p0" - ) - public UserMetadata update(UUID userId, UserMetadata changes) { - byte[] idBytes = UuidUtil.uuidToBin(userId); - - UserMetadata metadata = repository.findById(idBytes) - .orElseThrow(() -> new NotFoundException("Metadatos de usuario no encontrados")); - - if (changes.getMemberNumber() != null) metadata.setMemberNumber(changes.getMemberNumber()); - if (changes.getPlotNumber() != null) metadata.setPlotNumber(changes.getPlotNumber()); - if (changes.getDni() != null) metadata.setDni(changes.getDni()); - if (changes.getPhone() != null) metadata.setPhone(changes.getPhone()); - if (changes.getType() != null) metadata.setType(changes.getType()); - if (changes.getRole() != null) metadata.setRole(changes.getRole()); - if (changes.getNotes() != null) metadata.setNotes(changes.getNotes()); - metadata.setAssignedAt(changes.getAssignedAt()); - if (changes.getDeactivatedAt() != null) metadata.setDeactivatedAt(changes.getDeactivatedAt()); - - return repository.save(metadata); - } - - public void delete(UUID userId) { - byte[] idBytes = UuidUtil.uuidToBin(userId); - if (!repository.existsById(idBytes)) { - throw new NotFoundException("Metadatos de usuario no encontrados"); - } - repository.deleteById(idBytes); - } - - public Integer getLatestMemberNumber() { - return repository.findAll() - .stream() - .map(UserMetadata::getMemberNumber) - .max(Integer::compareTo) - .get(); - } - - public Boolean existsByMemberNumber(Integer memberNumber) { - return getByMemberNumber(memberNumber).getUserId() != null; - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/service/view/VBalanceWithTotalsService.java b/huertos/src/main/java/net/miarma/backend/huertos/service/view/VBalanceWithTotalsService.java deleted file mode 100644 index 68aabd3..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/service/view/VBalanceWithTotalsService.java +++ /dev/null @@ -1,24 +0,0 @@ -package net.miarma.backend.huertos.service.view; - -import java.util.List; - -import org.springframework.stereotype.Service; - -import jakarta.transaction.Transactional; -import net.miarma.backend.huertos.model.view.VBalanceWithTotals; -import net.miarma.backend.huertos.repository.view.VBalanceWithTotalsRepository; - -@Service -@Transactional -public class VBalanceWithTotalsService { - - private final VBalanceWithTotalsRepository repository; - - public VBalanceWithTotalsService(VBalanceWithTotalsRepository repository) { - this.repository = repository; - } - - public List getAll() { - return repository.findAll(); - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/service/view/VIncomesWithInfoService.java b/huertos/src/main/java/net/miarma/backend/huertos/service/view/VIncomesWithInfoService.java deleted file mode 100644 index 2bd7349..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/service/view/VIncomesWithInfoService.java +++ /dev/null @@ -1,44 +0,0 @@ -package net.miarma.backend.huertos.service.view; - -import java.util.Comparator; -import java.util.List; -import java.util.UUID; - -import net.miarma.backend.huertos.model.Income; -import net.miarma.backlib.exception.NotFoundException; -import org.springframework.stereotype.Service; - -import jakarta.transaction.Transactional; -import net.miarma.backend.huertos.model.view.VIncomesWithInfo; -import net.miarma.backend.huertos.repository.view.VIncomesWithInfoRepository; -import net.miarma.backlib.util.UuidUtil; - -@Service -@Transactional -public class VIncomesWithInfoService { - - private final VIncomesWithInfoRepository repository; - - public VIncomesWithInfoService(VIncomesWithInfoRepository repository) { - this.repository = repository; - } - - public List getAll() { - return repository.findAll().stream() - .sorted(Comparator.comparing(VIncomesWithInfo::getCreatedAt).reversed()) - .toList(); - } - - public VIncomesWithInfo getById(UUID incomeId) { - byte[] idBytes = UuidUtil.uuidToBin(incomeId); - return repository.findById(idBytes) - .orElseThrow(() -> new NotFoundException("Ingreso no encontrado")); - } - - public List getByUserId(UUID userId) { - byte[] idBytes = UuidUtil.uuidToBin(userId); - return repository.findAll().stream() - .filter(i -> i.getUserId().equals(userId)) - .toList(); - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/util/UsernameGenerator.java b/huertos/src/main/java/net/miarma/backend/huertos/util/UsernameGenerator.java deleted file mode 100644 index 1f7018b..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/util/UsernameGenerator.java +++ /dev/null @@ -1,9 +0,0 @@ -package net.miarma.backend.huertos.util; - -import java.util.Locale; - -public class UsernameGenerator { - public static String generate(String name, Integer number) { - return name.split(" ")[0].toLowerCase() + number; - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/validation/DniValidator.java b/huertos/src/main/java/net/miarma/backend/huertos/validation/DniValidator.java deleted file mode 100644 index 10af1f6..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/validation/DniValidator.java +++ /dev/null @@ -1,66 +0,0 @@ -package net.miarma.backend.huertos.validation; - -/** - * Validador de DNI/NIE español. - *

- * Este validador comprueba si un DNI o NIE es válido según las reglas establecidas por la legislación española. - * Un DNI debe tener 8 dígitos seguidos de una letra, y un NIE debe comenzar con X, Y o Z seguido de 7 dígitos y una letra. - * - * @author José Manuel Amador Gallardo - */ -public class DniValidator { - - /** - * Valida un DNI o NIE español. - * - * @param id El DNI o NIE a validar. - * @return true si el DNI/NIE es válido, false en caso contrario. - */ - public static boolean isValid(String id) { - if (id == null || id.length() != 9) { - return false; - } - - id = id.toUpperCase(); // Pa evitar problemas con minúsculas - String numberPart; - char letterPart = id.charAt(8); - - if (id.startsWith("X") || id.startsWith("Y") || id.startsWith("Z")) { - // NIE - char prefix = id.charAt(0); - String numericPrefix = switch (prefix) { - case 'X' -> "0"; - case 'Y' -> "1"; - case 'Z' -> "2"; - default -> null; - }; - - if (numericPrefix == null) return false; - - numberPart = numericPrefix + id.substring(1, 8); - } else { - // DNI - numberPart = id.substring(0, 8); - } - - if (!numberPart.matches("\\d{8}")) { - return false; - } - - int number = Integer.parseInt(numberPart); - char expectedLetter = calculateLetter(number); - - return letterPart == expectedLetter; - } - - /** - * Calcula la letra correspondiente a un número de DNI. - * - * @param number El número del DNI (8 dígitos). - * @return La letra correspondiente. - */ - private static char calculateLetter(int number) { - String letters = "TRWAGMYFPDXBNJZSQVHLCKE"; - return letters.charAt(number % 23); - } -} diff --git a/huertos/src/main/java/net/miarma/backend/huertos/validation/RequestValidator.java b/huertos/src/main/java/net/miarma/backend/huertos/validation/RequestValidator.java deleted file mode 100644 index 66b4e1d..0000000 --- a/huertos/src/main/java/net/miarma/backend/huertos/validation/RequestValidator.java +++ /dev/null @@ -1,90 +0,0 @@ -package net.miarma.backend.huertos.validation; - -import net.miarma.backend.huertos.model.RequestMetadata; -import net.miarma.backlib.exception.BadRequestException; -import net.miarma.backlib.exception.ValidationException; - -import java.util.regex.Pattern; - -public class RequestValidator { - - private static final Pattern DNI_PATTERN = Pattern.compile("\\d{8}[A-Za-z]"); - private static final Pattern EMAIL_PATTERN = Pattern.compile("^[\\w.%+-]+@[\\w.-]+\\.[a-zA-Z]{2,6}$"); - private static final Pattern PHONE_PATTERN = Pattern.compile("^\\+?\\d{9,15}$"); - - public static void validate(RequestMetadata metadata, Byte requestType) { - if (metadata.getRequestId() == null) { - throw new BadRequestException("Estos metadatos deben pertenecer a una solicitud (falta ID)"); - } - - if (isBlank(metadata.getDisplayName())) { - throw new BadRequestException("El nombre a mostrar es obligatorio"); - } else if (metadata.getDisplayName().length() < 3) { - throw new ValidationException("displayName", "El nombre a mostrar debe tener al menos 3 caracteres"); - } - - if (isBlank(metadata.getDni())) { - throw new BadRequestException("El DNI es obligatorio"); - } else if (!DNI_PATTERN.matcher(metadata.getDni()).matches()) { - throw new ValidationException("dni", "Formato de DNI inválido (ej: 12345678A)"); - } else if (!DniValidator.isValid(metadata.getDni())) { - throw new ValidationException("dni", "Este DNI no es un DNI real"); - } - - if (isBlank(metadata.getEmail())) { - throw new BadRequestException("El email es obligatorio"); - } else if (!EMAIL_PATTERN.matcher(metadata.getEmail()).matches()) { - throw new ValidationException("email", "Email inválido"); - } - - if (isBlank(metadata.getUsername())) { - throw new BadRequestException("El usuario es obligatorio"); - } else if (metadata.getUsername().length() < 3) { - throw new ValidationException("username", "El usuario debe tener al menos 3 caracteres"); - } - - if (metadata.getType() == null) { - throw new BadRequestException("El tipo de usuario es obligatorio"); - } - - if (requestType == 2) { - if (metadata.getPlotNumber() == null) { - throw new BadRequestException("El colaborador debe tener huerto"); - } - } - - if (requestType == 0 || requestType == 1) { - if (metadata.getMemberNumber() == null) { - throw new BadRequestException("El número de socio es obligatorio"); - } - } - - if (requestType == 0) { - if (metadata.getAddress() == null || metadata.getZipCode() == null || metadata.getCity() == null) { - throw new BadRequestException("La dirección, código postal y ciudad son obligatorios"); - } - } - - if (requestType == 0) { - if (isBlank(metadata.getAddress())) { - throw new ValidationException("address", "La dirección es obligatoria"); - } - if (isBlank(metadata.getZipCode())) { - throw new ValidationException("zipCode", "El código postal es obligatorio"); - } else if(metadata.getZipCode().length() < 5) { - throw new ValidationException("zipCode", "El código postal debe tener 5 dígitos"); - } - if (isBlank(metadata.getCity())) { - throw new ValidationException("city", "La ciudad es obligatoria"); - } - } - - if (metadata.getPhone() != null && !PHONE_PATTERN.matcher(metadata.getPhone()).matches()) { - throw new ValidationException("phone", "Teléfono inválido (debe tener 9 dígitos)"); - } - } - - private static boolean isBlank(String s) { - return s == null || s.trim().isEmpty(); - } -} diff --git a/huertos/src/main/resources/application-dev.yml b/huertos/src/main/resources/application-dev.yml deleted file mode 100644 index c0e66ab..0000000 --- a/huertos/src/main/resources/application-dev.yml +++ /dev/null @@ -1,28 +0,0 @@ -server: - port: 8081 - servlet: - context-path: /v2/huertos - -spring: - datasource: - url: jdbc:mariadb://localhost:3306/miarma_v2 - username: admin - password: ${DB_PASS} - driver-class-name: org.mariadb.jdbc.Driver - -logging: - level: - org.hibernate.SQL: DEBUG - org.hibernate.orm.jdbc.bind: TRACE - -core: - url: http://localhost:8080/v2/core - -huertos: - user: SYSTEM - password: ${HUERTOS_PASS} - -mail: - smtp: - server: smtp.dondominio.com - port: 587 \ No newline at end of file diff --git a/huertos/src/main/resources/application-prod.yml b/huertos/src/main/resources/application-prod.yml deleted file mode 100644 index 56dca05..0000000 --- a/huertos/src/main/resources/application-prod.yml +++ /dev/null @@ -1,27 +0,0 @@ -server: - port: 8081 - servlet: - context-path: /v2/huertos - -spring: - datasource: - url: jdbc:mariadb://mariadb:3306/miarma_v2 - username: ${DB_USER} - password: ${DB_PASS} - driver-class-name: org.mariadb.jdbc.Driver - -logging: - level: - org.hibernate.SQL: WARN - -core: - url: http://core:8080/v2/core - -huertos: - user: SYSTEM - password: ${HUERTOS_PASS} - -mail: - smtp: - server: smtp.dondominio.com - port: 587 \ No newline at end of file diff --git a/huertos/src/main/resources/application.yml b/huertos/src/main/resources/application.yml deleted file mode 100644 index 87de0a8..0000000 --- a/huertos/src/main/resources/application.yml +++ /dev/null @@ -1,25 +0,0 @@ -spring: - application: - name: huertos-service - - jpa: - open-in-view: false - hibernate: - ddl-auto: validate - properties: - hibernate: - jdbc: - time_zone: UTC - - jackson: - default-property-inclusion: non_null - time-zone: Europe/Madrid - -jwt: - expiration-ms: 3600000 - -management: - endpoints: - web: - exposure: - include: health,info diff --git a/pom.xml b/pom.xml index 5acf6c0..0222e15 100644 --- a/pom.xml +++ b/pom.xml @@ -11,9 +11,7 @@ core - huertos minecraft - cine mpaste backlib