Add: custom Exception for fine-grain error handling. Add: env variables for deploying in prod.
This commit is contained in:
@@ -14,6 +14,13 @@
|
||||
<maven.compiler.target>25</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>gitea</id>
|
||||
<url>https://git.miarma.net/api/packages/Gallardo7761/maven</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<!-- Spring Boot -->
|
||||
<dependency>
|
||||
@@ -65,4 +72,22 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>${spring.boot.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -1,6 +1,8 @@
|
||||
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.annotation.method.configuration.EnableMethodSecurity;
|
||||
@@ -16,28 +18,43 @@ import org.springframework.security.web.authentication.UsernamePasswordAuthentic
|
||||
public class SecurityConfig {
|
||||
|
||||
private final HuertosJwtFilter jwtFilter;
|
||||
private final RestAuthEntryPoint authEntryPoint;
|
||||
private final RestAccessDeniedHandler accessDeniedHandler;
|
||||
|
||||
public SecurityConfig(HuertosJwtFilter jwtFilter) {
|
||||
public SecurityConfig(
|
||||
HuertosJwtFilter jwtFilter,
|
||||
RestAuthEntryPoint authEntryPoint,
|
||||
RestAccessDeniedHandler accessDeniedHandler
|
||||
) {
|
||||
this.jwtFilter = jwtFilter;
|
||||
this.authEntryPoint = authEntryPoint;
|
||||
this.accessDeniedHandler = accessDeniedHandler;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
|
||||
http
|
||||
.csrf(csrf -> csrf.disable())
|
||||
.sessionManagement(sm -> sm.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
||||
.authorizeHttpRequests(auth -> auth
|
||||
// PUBLICAS
|
||||
.requestMatchers("/login").permitAll()
|
||||
.requestMatchers("/announces/**").permitAll()
|
||||
.requestMatchers("/huertos/members/waitlist").permitAll()
|
||||
.csrf(csrf -> csrf.disable())
|
||||
.sessionManagement(sm -> sm.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
||||
.exceptionHandling(ex -> ex
|
||||
.authenticationEntryPoint(authEntryPoint)
|
||||
.accessDeniedHandler(accessDeniedHandler)
|
||||
)
|
||||
.authorizeHttpRequests(auth -> auth
|
||||
// PUBLICAS
|
||||
.requestMatchers("/login").permitAll()
|
||||
.requestMatchers("/announces/**").permitAll()
|
||||
.requestMatchers("/huertos/members/waitlist").permitAll()
|
||||
.requestMatchers("/huertos/members/waitlist/limited").permitAll()
|
||||
.requestMatchers("/huertos/members/latest-number").permitAll()
|
||||
// PRIVADAS
|
||||
.requestMatchers("/**").authenticated()
|
||||
);
|
||||
.requestMatchers("/huertos/members/latest-number").permitAll()
|
||||
// PRIVADAS
|
||||
.anyRequest().authenticated()
|
||||
);
|
||||
|
||||
http.addFilterBefore(jwtFilter, UsernamePasswordAuthenticationFilter.class);
|
||||
|
||||
return http.build();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import jakarta.transaction.Transactional;
|
||||
import net.miarma.backend.huertos.dto.AnnouncementDto;
|
||||
import net.miarma.backend.huertos.model.Announcement;
|
||||
import net.miarma.backend.huertos.repository.AnnouncementRepository;
|
||||
import net.miarma.backlib.exception.NotFoundException;
|
||||
import net.miarma.backlib.util.UuidUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -28,7 +29,7 @@ public class AnnouncementService {
|
||||
public Announcement getById(UUID announceId) {
|
||||
byte[] idBytes = UuidUtil.uuidToBin(announceId);
|
||||
return announcementRepository.findById(idBytes)
|
||||
.orElseThrow(() -> new RuntimeException("Announcement not found"));
|
||||
.orElseThrow(() -> new NotFoundException("Announcement not found"));
|
||||
}
|
||||
|
||||
public Announcement create(Announcement announcement) {
|
||||
@@ -42,7 +43,7 @@ public class AnnouncementService {
|
||||
public Announcement update(UUID announceId, AnnouncementDto.Request dto) {
|
||||
byte[] idBytes = UuidUtil.uuidToBin(announceId);
|
||||
Announcement announcement = announcementRepository.findById(idBytes)
|
||||
.orElseThrow(() -> new RuntimeException("Announcement not found"));
|
||||
.orElseThrow(() -> new NotFoundException("Announcement not found"));
|
||||
|
||||
if (dto.getBody() != null) announcement.setBody(dto.getBody());
|
||||
if (dto.getPriority() != null) announcement.setPriority(dto.getPriority());
|
||||
@@ -54,7 +55,7 @@ public class AnnouncementService {
|
||||
public void delete(UUID announceId) {
|
||||
byte[] idBytes = UuidUtil.uuidToBin(announceId);
|
||||
if (!announcementRepository.existsById(idBytes))
|
||||
throw new RuntimeException("Announcement not found");
|
||||
throw new NotFoundException("Announcement not found");
|
||||
announcementRepository.deleteById(idBytes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package net.miarma.backend.huertos.service;
|
||||
import java.time.Instant;
|
||||
import java.util.Optional;
|
||||
|
||||
import net.miarma.backlib.exception.ConflictException;
|
||||
import net.miarma.backlib.exception.NotFoundException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import jakarta.transaction.Transactional;
|
||||
@@ -21,12 +23,12 @@ public class BalanceService {
|
||||
|
||||
public Balance get() {
|
||||
return repo.findById((byte) 1)
|
||||
.orElseThrow(() -> new RuntimeException("Balance not found"));
|
||||
.orElseThrow(() -> new NotFoundException("Balance not found"));
|
||||
}
|
||||
|
||||
public Balance create(Balance balance) {
|
||||
if (repo.existsById((byte) 1)) {
|
||||
throw new RuntimeException("Balance already exists");
|
||||
throw new ConflictException("Balance already exists");
|
||||
}
|
||||
balance.setId((byte) 1);
|
||||
balance.setCreatedAt(Instant.now());
|
||||
@@ -35,7 +37,7 @@ public class BalanceService {
|
||||
|
||||
public Balance update(Balance dto) {
|
||||
Balance balance = repo.findById((byte) 1)
|
||||
.orElseThrow(() -> new RuntimeException("Balance not found"));
|
||||
.orElseThrow(() -> new NotFoundException("Balance not found"));
|
||||
|
||||
if (dto.getInitialBank() != null) balance.setInitialBank(dto.getInitialBank());
|
||||
if (dto.getInitialCash() != null) balance.setInitialCash(dto.getInitialCash());
|
||||
@@ -45,7 +47,7 @@ public class BalanceService {
|
||||
|
||||
public void delete() {
|
||||
if (!repo.existsById((byte) 1)) {
|
||||
throw new RuntimeException("Balance not found");
|
||||
throw new NotFoundException("Balance not found");
|
||||
}
|
||||
repo.deleteById((byte) 1);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import jakarta.transaction.Transactional;
|
||||
import net.miarma.backend.huertos.dto.ExpenseDto;
|
||||
import net.miarma.backend.huertos.model.Expense;
|
||||
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;
|
||||
|
||||
@@ -28,21 +30,21 @@ public class ExpenseService {
|
||||
public Expense getById(UUID expenseId) {
|
||||
byte[] idBytes = UuidUtil.uuidToBin(expenseId);
|
||||
return expenseRepository.findById(idBytes)
|
||||
.orElseThrow(() -> new RuntimeException("Expense not found"));
|
||||
.orElseThrow(() -> new NotFoundException("Expense not found"));
|
||||
}
|
||||
|
||||
public Expense create(Expense expense) {
|
||||
if (expense.getConcept() == null || expense.getConcept().isBlank()) {
|
||||
throw new RuntimeException("Concept is required");
|
||||
throw new ValidationException("Concept is required");
|
||||
}
|
||||
if (expense.getAmount() == null) {
|
||||
throw new RuntimeException("Amount is required");
|
||||
throw new ValidationException("Amount is required");
|
||||
}
|
||||
if (expense.getSupplier() == null || expense.getSupplier().isBlank()) {
|
||||
throw new RuntimeException("Supplier is required");
|
||||
throw new ValidationException("Supplier is required");
|
||||
}
|
||||
if (expense.getInvoice() == null || expense.getInvoice().isBlank()) {
|
||||
throw new RuntimeException("Invoice is required");
|
||||
throw new ValidationException("Invoice is required");
|
||||
}
|
||||
|
||||
expense.setExpenseId(UUID.randomUUID());
|
||||
@@ -54,7 +56,7 @@ public class ExpenseService {
|
||||
public Expense update(UUID expenseId, ExpenseDto.Request dto) {
|
||||
byte[] idBytes = UuidUtil.uuidToBin(expenseId);
|
||||
Expense expense = expenseRepository.findById(idBytes)
|
||||
.orElseThrow(() -> new RuntimeException("Expense not found"));
|
||||
.orElseThrow(() -> new NotFoundException("Expense not found"));
|
||||
|
||||
if (dto.getConcept() != null) expense.setConcept(dto.getConcept());
|
||||
if (dto.getAmount() != null) expense.setAmount(dto.getAmount());
|
||||
@@ -68,7 +70,7 @@ public class ExpenseService {
|
||||
public void delete(UUID expenseId) {
|
||||
byte[] idBytes = UuidUtil.uuidToBin(expenseId);
|
||||
if (!expenseRepository.existsById(idBytes)) {
|
||||
throw new RuntimeException("Expense not found");
|
||||
throw new NotFoundException("Expense not found");
|
||||
}
|
||||
expenseRepository.deleteById(idBytes);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.miarma.backlib.exception.BadRequestException;
|
||||
import net.miarma.backlib.exception.ConflictException;
|
||||
import net.miarma.backlib.exception.NotFoundException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import jakarta.transaction.Transactional;
|
||||
@@ -31,12 +34,12 @@ public class HuertosUserMetadataService {
|
||||
public HuertosUserMetadata getById(UUID userId) {
|
||||
byte[] idBytes = UuidUtil.uuidToBin(userId);
|
||||
return repository.findById(idBytes)
|
||||
.orElseThrow(() -> new RuntimeException("User metadata not found"));
|
||||
.orElseThrow(() -> new NotFoundException("User metadata not found"));
|
||||
}
|
||||
|
||||
public HuertosUserMetadata getByMemberNumber(Integer memberNumber) {
|
||||
return repository.findByMemberNumber(memberNumber)
|
||||
.orElseThrow(() -> new RuntimeException("User metadata not found"));
|
||||
.orElseThrow(() -> new NotFoundException("User metadata not found"));
|
||||
}
|
||||
|
||||
public boolean existsById(UUID userId) {
|
||||
@@ -46,16 +49,16 @@ public class HuertosUserMetadataService {
|
||||
|
||||
public HuertosUserMetadata create(HuertosUserMetadata meta) {
|
||||
if (meta.getUserId() == null) {
|
||||
throw new RuntimeException("userId is required");
|
||||
throw new BadRequestException("userId is required");
|
||||
}
|
||||
if (repository.existsById(UuidUtil.uuidToBin(meta.getUserId()))) {
|
||||
throw new RuntimeException("Metadata already exists for this user");
|
||||
throw new ConflictException("Metadata already exists for this user");
|
||||
}
|
||||
|
||||
if (meta.getMemberNumber() == null) throw new RuntimeException("memberNumber required");
|
||||
if (meta.getPlotNumber() == null) throw new RuntimeException("plotNumber required");
|
||||
if (meta.getDni() == null || meta.getDni().isBlank()) throw new RuntimeException("dni required");
|
||||
if (meta.getPhone() == null || meta.getPhone().isBlank()) throw new RuntimeException("phone required");
|
||||
if (meta.getMemberNumber() == null) throw new BadRequestException("memberNumber required");
|
||||
if (meta.getPlotNumber() == null) throw new BadRequestException("plotNumber required");
|
||||
if (meta.getDni() == null || meta.getDni().isBlank()) throw new BadRequestException("dni required");
|
||||
if (meta.getPhone() == null || meta.getPhone().isBlank()) throw new BadRequestException("phone required");
|
||||
if (meta.getType() == null) meta.setType((byte) 0);
|
||||
if (meta.getRole() == null) meta.setRole((byte) 0);
|
||||
|
||||
@@ -70,7 +73,7 @@ public class HuertosUserMetadataService {
|
||||
byte[] idBytes = UuidUtil.uuidToBin(userId);
|
||||
|
||||
HuertosUserMetadata meta = repository.findById(idBytes)
|
||||
.orElseThrow(() -> new RuntimeException("User metadata not found"));
|
||||
.orElseThrow(() -> new NotFoundException("User metadata not found"));
|
||||
|
||||
if (dto.getMemberNumber() != null) meta.setMemberNumber(dto.getMemberNumber());
|
||||
if (dto.getPlotNumber() != null) meta.setPlotNumber(dto.getPlotNumber());
|
||||
@@ -88,7 +91,7 @@ public class HuertosUserMetadataService {
|
||||
public void delete(UUID userId) {
|
||||
byte[] idBytes = UuidUtil.uuidToBin(userId);
|
||||
if (!repository.existsById(idBytes)) {
|
||||
throw new RuntimeException("User metadata not found");
|
||||
throw new NotFoundException("User metadata not found");
|
||||
}
|
||||
repository.deleteById(idBytes);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,9 @@ import java.util.UUID;
|
||||
import net.miarma.backend.huertos.dto.IncomeDto;
|
||||
import net.miarma.backend.huertos.model.HuertosUserMetadata;
|
||||
import net.miarma.backend.huertos.repository.HuertosUserMetadataRepository;
|
||||
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;
|
||||
@@ -34,7 +37,7 @@ public class IncomeService {
|
||||
public Income getById(UUID incomeId) {
|
||||
byte[] idBytes = UuidUtil.uuidToBin(incomeId);
|
||||
return incomeRepository.findById(idBytes)
|
||||
.orElseThrow(() -> new RuntimeException("Income not found"));
|
||||
.orElseThrow(() -> new NotFoundException("Income not found"));
|
||||
}
|
||||
|
||||
public List<Income> getByUserId(UUID userId) {
|
||||
@@ -45,13 +48,13 @@ public class IncomeService {
|
||||
|
||||
public Income create(Income income) {
|
||||
if (income.getUserId() == null) {
|
||||
throw new RuntimeException("userId is required");
|
||||
throw new BadRequestException("userId is required");
|
||||
}
|
||||
if (income.getConcept() == null || income.getConcept().isBlank()) {
|
||||
throw new RuntimeException("concept is required");
|
||||
throw new BadRequestException("concept is required");
|
||||
}
|
||||
if (income.getAmount() == null || income.getAmount().signum() <= 0) {
|
||||
throw new RuntimeException("amount must be positive");
|
||||
throw new ValidationException("amount must be positive");
|
||||
}
|
||||
|
||||
income.setIncomeId(UUID.randomUUID());
|
||||
@@ -64,12 +67,12 @@ public class IncomeService {
|
||||
byte[] idBytes = UuidUtil.uuidToBin(incomeId);
|
||||
|
||||
Income income = incomeRepository.findById(idBytes)
|
||||
.orElseThrow(() -> new RuntimeException("Income not found"));
|
||||
.orElseThrow(() -> new NotFoundException("Income not found"));
|
||||
|
||||
if (dto.getConcept() != null) income.setConcept(dto.getConcept());
|
||||
if (dto.getAmount() != null) {
|
||||
if (dto.getAmount().signum() <= 0) {
|
||||
throw new RuntimeException("amount must be positive");
|
||||
throw new ValidationException("amount must be positive");
|
||||
}
|
||||
income.setAmount(dto.getAmount());
|
||||
}
|
||||
@@ -83,7 +86,7 @@ public class IncomeService {
|
||||
byte[] idBytes = UuidUtil.uuidToBin(incomeId);
|
||||
|
||||
if (!incomeRepository.existsById(idBytes)) {
|
||||
throw new RuntimeException("Income not found");
|
||||
throw new NotFoundException("Income not found");
|
||||
}
|
||||
|
||||
incomeRepository.deleteById(idBytes);
|
||||
@@ -93,7 +96,7 @@ public class IncomeService {
|
||||
try {
|
||||
UUID userId = metadataService.getByMemberNumber(memberNumber).getUserId();
|
||||
return !getByUserId(userId).isEmpty();
|
||||
} catch (RuntimeException e) {
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import net.miarma.backend.huertos.dto.WaitlistCensoredDto;
|
||||
import net.miarma.backend.huertos.mapper.HuertosUserMetadataMapper;
|
||||
import net.miarma.backend.huertos.security.NameCensorer;
|
||||
import net.miarma.backlib.dto.UserWithCredentialDto;
|
||||
import net.miarma.backlib.exception.NotFoundException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Comparator;
|
||||
@@ -88,21 +89,21 @@ public class MemberService {
|
||||
return getAll((byte)1).stream()
|
||||
.filter(dto -> dto.metadata().getMemberNumber().equals(memberNumber))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new RuntimeException("Member not found"));
|
||||
.orElseThrow(() -> new NotFoundException("Member not found"));
|
||||
}
|
||||
|
||||
public MemberDto getByPlotNumber(Integer plotNumber) {
|
||||
return getAll((byte)1).stream()
|
||||
.filter(dto -> dto.metadata().getPlotNumber().equals(plotNumber))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new RuntimeException("Member not found"));
|
||||
.orElseThrow(() -> new NotFoundException("Member not found"));
|
||||
}
|
||||
|
||||
public MemberDto getByDni(String dni) {
|
||||
return getAll((byte)1).stream()
|
||||
.filter(dto -> dni.equals(dto.metadata().getDni()))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new RuntimeException("Member not found"));
|
||||
.orElseThrow(() -> new NotFoundException("Member not found"));
|
||||
}
|
||||
|
||||
public Boolean hasIncomes(Integer memberNumber) {
|
||||
|
||||
@@ -5,6 +5,8 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.miarma.backend.huertos.dto.PreUserDto;
|
||||
import net.miarma.backlib.exception.BadRequestException;
|
||||
import net.miarma.backlib.exception.NotFoundException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import jakarta.transaction.Transactional;
|
||||
@@ -29,7 +31,7 @@ public class PreUserService {
|
||||
public PreUser getById(UUID preUserId) {
|
||||
byte[] idBytes = UuidUtil.uuidToBin(preUserId);
|
||||
return repository.findById(idBytes)
|
||||
.orElseThrow(() -> new RuntimeException("PreUser not found"));
|
||||
.orElseThrow(() -> new NotFoundException("PreUser not found"));
|
||||
}
|
||||
|
||||
public List<PreUser> getByRequestId(UUID requestId) {
|
||||
@@ -42,22 +44,22 @@ public class PreUserService {
|
||||
|
||||
public PreUser create(PreUser preUser) {
|
||||
if (preUser.getRequestId() == null) {
|
||||
throw new RuntimeException("requestId is required");
|
||||
throw new BadRequestException("requestId is required");
|
||||
}
|
||||
if (preUser.getUserName() == null || preUser.getUserName().isBlank()) {
|
||||
throw new RuntimeException("userName is required");
|
||||
throw new BadRequestException("userName is required");
|
||||
}
|
||||
if (preUser.getDisplayName() == null || preUser.getDisplayName().isBlank()) {
|
||||
throw new RuntimeException("displayName is required");
|
||||
throw new BadRequestException("displayName is required");
|
||||
}
|
||||
if (preUser.getDni() == null || preUser.getDni().isBlank()) {
|
||||
throw new RuntimeException("dni is required");
|
||||
throw new BadRequestException("dni is required");
|
||||
}
|
||||
if (preUser.getPhone() == null || preUser.getPhone().isBlank()) {
|
||||
throw new RuntimeException("phone is required");
|
||||
throw new BadRequestException("phone is required");
|
||||
}
|
||||
if (preUser.getEmail() == null || preUser.getEmail().isBlank()) {
|
||||
throw new RuntimeException("email is required");
|
||||
throw new BadRequestException("email is required");
|
||||
}
|
||||
|
||||
preUser.setPreUserId(UUID.randomUUID());
|
||||
@@ -70,7 +72,7 @@ public class PreUserService {
|
||||
byte[] idBytes = UuidUtil.uuidToBin(preUserId);
|
||||
|
||||
PreUser preUser = repository.findById(idBytes)
|
||||
.orElseThrow(() -> new RuntimeException("PreUser not found"));
|
||||
.orElseThrow(() -> new NotFoundException("PreUser not found"));
|
||||
|
||||
if (dto.getUserName() != null) preUser.setUserName(dto.getUserName());
|
||||
if (dto.getDisplayName() != null) preUser.setDisplayName(dto.getDisplayName());
|
||||
@@ -93,7 +95,7 @@ public class PreUserService {
|
||||
byte[] idBytes = UuidUtil.uuidToBin(preUserId);
|
||||
|
||||
if (!repository.existsById(idBytes)) {
|
||||
throw new RuntimeException("PreUser not found");
|
||||
throw new NotFoundException("PreUser not found");
|
||||
}
|
||||
|
||||
repository.deleteById(idBytes);
|
||||
|
||||
@@ -6,6 +6,8 @@ import java.util.UUID;
|
||||
|
||||
import net.miarma.backend.huertos.dto.RequestDto;
|
||||
import net.miarma.backend.huertos.model.HuertosUserMetadata;
|
||||
import net.miarma.backlib.exception.BadRequestException;
|
||||
import net.miarma.backlib.exception.NotFoundException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import jakarta.transaction.Transactional;
|
||||
@@ -33,7 +35,7 @@ public class RequestService {
|
||||
public Request getById(UUID requestId) {
|
||||
byte[] idBytes = UuidUtil.uuidToBin(requestId);
|
||||
return requestRepository.findById(idBytes)
|
||||
.orElseThrow(() -> new RuntimeException("Request not found"));
|
||||
.orElseThrow(() -> new NotFoundException("Request not found"));
|
||||
}
|
||||
|
||||
public List<Request> getByUserId(UUID userId) {
|
||||
@@ -56,13 +58,13 @@ public class RequestService {
|
||||
|
||||
public Request create(Request request) {
|
||||
if (request.getType() == null) {
|
||||
throw new RuntimeException("type is required");
|
||||
throw new BadRequestException("type is required");
|
||||
}
|
||||
if (request.getStatus() == null) {
|
||||
throw new RuntimeException("status is required");
|
||||
throw new BadRequestException("status is required");
|
||||
}
|
||||
if (request.getRequestedBy() == null) {
|
||||
throw new RuntimeException("requestedBy is required");
|
||||
throw new BadRequestException("requestedBy is required");
|
||||
}
|
||||
|
||||
request.setRequestId(UUID.randomUUID());
|
||||
@@ -75,7 +77,7 @@ public class RequestService {
|
||||
byte[] idBytes = UuidUtil.uuidToBin(requestId);
|
||||
|
||||
Request request = requestRepository.findById(idBytes)
|
||||
.orElseThrow(() -> new RuntimeException("Request not found"));
|
||||
.orElseThrow(() -> new NotFoundException("Request not found"));
|
||||
|
||||
if (dto.getType() != null) request.setType(dto.getType());
|
||||
if (dto.getStatus() != null) request.setStatus(dto.getStatus());
|
||||
@@ -88,7 +90,7 @@ public class RequestService {
|
||||
public Request acceptRequest(UUID requestId) {
|
||||
byte[] idBytes = UuidUtil.uuidToBin(requestId);
|
||||
Request request = requestRepository.findById(idBytes)
|
||||
.orElseThrow(() -> new RuntimeException("Request not found"));
|
||||
.orElseThrow(() -> new NotFoundException("Request not found"));
|
||||
request.setStatus((byte)1);
|
||||
return requestRepository.save(request);
|
||||
}
|
||||
@@ -96,7 +98,7 @@ public class RequestService {
|
||||
public Request rejectRequest(UUID requestId) {
|
||||
byte[] idBytes = UuidUtil.uuidToBin(requestId);
|
||||
Request request = requestRepository.findById(idBytes)
|
||||
.orElseThrow(() -> new RuntimeException("Request not found"));
|
||||
.orElseThrow(() -> new NotFoundException("Request not found"));
|
||||
request.setStatus((byte)2);
|
||||
return requestRepository.save(request);
|
||||
}
|
||||
@@ -105,7 +107,7 @@ public class RequestService {
|
||||
byte[] idBytes = UuidUtil.uuidToBin(requestId);
|
||||
|
||||
if (!requestRepository.existsById(idBytes)) {
|
||||
throw new RuntimeException("Request not found");
|
||||
throw new NotFoundException("Request not found");
|
||||
}
|
||||
|
||||
requestRepository.deleteById(idBytes);
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.miarma.backend.huertos.service.view;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.miarma.backlib.exception.NotFoundException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import jakarta.transaction.Transactional;
|
||||
@@ -27,6 +28,6 @@ public class VHuertosMembersService {
|
||||
public VHuertosMembers getById(UUID userId) {
|
||||
byte[] idBytes = UuidUtil.uuidToBin(userId);
|
||||
return repository.findById(idBytes)
|
||||
.orElseThrow(() -> new RuntimeException("Member not found"));
|
||||
.orElseThrow(() -> new NotFoundException("Member not found"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.miarma.backend.huertos.service.view;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.miarma.backlib.exception.NotFoundException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import jakarta.transaction.Transactional;
|
||||
@@ -27,7 +28,7 @@ public class VIncomesWithFullNamesService {
|
||||
public VIncomesWithFullNames getById(UUID incomeId) {
|
||||
byte[] idBytes = UuidUtil.uuidToBin(incomeId);
|
||||
return repository.findById(idBytes)
|
||||
.orElseThrow(() -> new RuntimeException("Income not found"));
|
||||
.orElseThrow(() -> new NotFoundException("Income not found"));
|
||||
}
|
||||
|
||||
public List<VIncomesWithFullNames> getByUserId(UUID userId) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.miarma.backend.huertos.service.view;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.miarma.backlib.exception.NotFoundException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import jakarta.transaction.Transactional;
|
||||
@@ -27,7 +28,7 @@ public class VRequestsWithPreUsersService {
|
||||
public VRequestsWithPreUsers getById(UUID requestId) {
|
||||
byte[] idBytes = UuidUtil.uuidToBin(requestId);
|
||||
return repository.findById(idBytes)
|
||||
.orElseThrow(() -> new RuntimeException("Request not found"));
|
||||
.orElseThrow(() -> new NotFoundException("Request not found"));
|
||||
}
|
||||
|
||||
public List<VRequestsWithPreUsers> getByRequestType(Byte type) {
|
||||
|
||||
28
huertos/src/main/resources/application-dev.yml
Normal file
28
huertos/src/main/resources/application-dev.yml
Normal file
@@ -0,0 +1,28 @@
|
||||
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_SYSTEM_PASSWORD}
|
||||
|
||||
mail:
|
||||
smtp:
|
||||
server: smtp.dondominio.com
|
||||
port: 587
|
||||
27
huertos/src/main/resources/application-prod.yml
Normal file
27
huertos/src/main/resources/application-prod.yml
Normal file
@@ -0,0 +1,27 @@
|
||||
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_SYSTEM_PASSWORD}
|
||||
|
||||
mail:
|
||||
smtp:
|
||||
server: smtp.dondominio.com
|
||||
port: 587
|
||||
@@ -1,66 +1,23 @@
|
||||
server:
|
||||
port: 8081
|
||||
servlet:
|
||||
context-path: /v2/huertos
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: huertos-service
|
||||
|
||||
datasource:
|
||||
url: jdbc:mariadb://localhost:3306/miarma_v2
|
||||
username: admin
|
||||
password: ositovito
|
||||
driver-class-name: org.mariadb.jdbc.Driver
|
||||
|
||||
jpa:
|
||||
open-in-view: false
|
||||
hibernate:
|
||||
ddl-auto: validate
|
||||
properties:
|
||||
hibernate:
|
||||
format_sql: true
|
||||
jdbc:
|
||||
time_zone: UTC
|
||||
|
||||
jackson:
|
||||
serialization:
|
||||
indent-output: true
|
||||
default-property-inclusion: non_null
|
||||
time-zone: Europe/Madrid
|
||||
|
||||
logging:
|
||||
level:
|
||||
org.hibernate.SQL: DEBUG
|
||||
org.hibernate.orm.jdbc.bind: TRACE
|
||||
org.springframework.security: INFO
|
||||
|
||||
jwt:
|
||||
private-key-path: /home/jomaa/.config/miarma-backend/private.pem
|
||||
public-key-path: /home/jomaa/.config/miarma-backend/public.pem
|
||||
expiration-ms: 3600000
|
||||
|
||||
core:
|
||||
url: "http://localhost:8080/v2/core"
|
||||
|
||||
huertos:
|
||||
user: "SYSTEM"
|
||||
password: "mR193*8ztxgskTrt"
|
||||
|
||||
mail:
|
||||
smtp:
|
||||
server: smtp.dondominio.com
|
||||
port: 587
|
||||
password:
|
||||
presidente: Huertos$Presidenzia2025
|
||||
secretaria: Huertos$Secretarya2025
|
||||
tesoreria: Huertos$Tesorerya2025
|
||||
admin: Mi.Primer.Aire.Mundo.Clima;99
|
||||
noreply: hpeeuRqn2-2MN_
|
||||
imap:
|
||||
server: imap.dondominio.com
|
||||
port: 993
|
||||
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
|
||||
Reference in New Issue
Block a user