Fix: lists orders and edit createdAt attr on some entities
This commit is contained in:
1
TODO
1
TODO
@@ -15,3 +15,4 @@ RESUELTO ---------------------------------
|
|||||||
- todos los socios en dropdown ingresos
|
- todos los socios en dropdown ingresos
|
||||||
- validacion LE/COlab
|
- validacion LE/COlab
|
||||||
- createdAt custom en ing,gastos
|
- createdAt custom en ing,gastos
|
||||||
|
- editar createdAt
|
||||||
@@ -98,6 +98,7 @@ public class IncomeController {
|
|||||||
@PathVariable("income_id") UUID incomeId,
|
@PathVariable("income_id") UUID incomeId,
|
||||||
@RequestBody IncomeDto.Request dto
|
@RequestBody IncomeDto.Request dto
|
||||||
) {
|
) {
|
||||||
|
IO.println(dto.getCreatedAt());
|
||||||
return ResponseEntity.ok(
|
return ResponseEntity.ok(
|
||||||
IncomeMapper.toResponse(
|
IncomeMapper.toResponse(
|
||||||
incomeService.update(
|
incomeService.update(
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.miarma.backend.huertos.controller;
|
package net.miarma.backend.huertos.controller;
|
||||||
|
|
||||||
import net.miarma.backend.huertos.dto.*;
|
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.IncomeMapper;
|
||||||
import net.miarma.backend.huertos.mapper.RequestMapper;
|
import net.miarma.backend.huertos.mapper.RequestMapper;
|
||||||
import net.miarma.backend.huertos.security.HuertosPrincipal;
|
import net.miarma.backend.huertos.security.HuertosPrincipal;
|
||||||
@@ -81,7 +82,7 @@ public class MemberController {
|
|||||||
|
|
||||||
@GetMapping("/number/{member_number}/incomes")
|
@GetMapping("/number/{member_number}/incomes")
|
||||||
@PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')")
|
@PreAuthorize("hasAnyRole('HUERTOS_ROLE_ADMIN', 'HUERTOS_ROLE_DEV')")
|
||||||
public ResponseEntity<List<IncomeDto.Response>> getMemberIncomes(@PathVariable("member_number") Integer memberNumber) {
|
public ResponseEntity<List<VIncomesWithInfoDto>> getMemberIncomes(@PathVariable("member_number") Integer memberNumber) {
|
||||||
return ResponseEntity.ok(memberService.getIncomes(memberNumber));
|
return ResponseEntity.ok(memberService.getIncomes(memberNumber));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package net.miarma.backend.huertos.dto;
|
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.CredentialDto;
|
||||||
import net.miarma.backlib.dto.UserDto;
|
import net.miarma.backlib.dto.UserDto;
|
||||||
|
|
||||||
@@ -10,7 +11,7 @@ public record MemberProfileDto(
|
|||||||
CredentialDto account,
|
CredentialDto account,
|
||||||
UserMetadataDto metadata,
|
UserMetadataDto metadata,
|
||||||
List<RequestDto.Response> requests,
|
List<RequestDto.Response> requests,
|
||||||
List<IncomeDto.Response> payments,
|
List<VIncomesWithInfoDto> payments,
|
||||||
boolean hasCollaborator,
|
boolean hasCollaborator,
|
||||||
boolean hasGreenhouse,
|
boolean hasGreenhouse,
|
||||||
boolean hasCollaboratorRequest,
|
boolean hasCollaboratorRequest,
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public class Income {
|
|||||||
@Column(name = "frequency")
|
@Column(name = "frequency")
|
||||||
private Byte frequency;
|
private Byte frequency;
|
||||||
|
|
||||||
@Column(name = "created_at", nullable = false)
|
@Column(name = "created_at", nullable = false, updatable = true)
|
||||||
private Instant createdAt;
|
private Instant createdAt;
|
||||||
|
|
||||||
@PrePersist
|
@PrePersist
|
||||||
|
|||||||
@@ -3,12 +3,14 @@ package net.miarma.backend.huertos.service;
|
|||||||
import jakarta.transaction.Transactional;
|
import jakarta.transaction.Transactional;
|
||||||
import net.miarma.backend.huertos.dto.AnnouncementDto;
|
import net.miarma.backend.huertos.dto.AnnouncementDto;
|
||||||
import net.miarma.backend.huertos.model.Announcement;
|
import net.miarma.backend.huertos.model.Announcement;
|
||||||
|
import net.miarma.backend.huertos.model.Income;
|
||||||
import net.miarma.backend.huertos.repository.AnnouncementRepository;
|
import net.miarma.backend.huertos.repository.AnnouncementRepository;
|
||||||
import net.miarma.backlib.exception.NotFoundException;
|
import net.miarma.backlib.exception.NotFoundException;
|
||||||
import net.miarma.backlib.util.UuidUtil;
|
import net.miarma.backlib.util.UuidUtil;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@@ -25,7 +27,9 @@ public class AnnouncementService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<Announcement> getAll() {
|
public List<Announcement> getAll() {
|
||||||
return announcementRepository.findAll();
|
return announcementRepository.findAll().stream()
|
||||||
|
.sorted(Comparator.comparing(Announcement::getCreatedAt).reversed())
|
||||||
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Announcement getById(UUID announceId) {
|
public Announcement getById(UUID announceId) {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package net.miarma.backend.huertos.service;
|
|||||||
import jakarta.transaction.Transactional;
|
import jakarta.transaction.Transactional;
|
||||||
import net.miarma.backend.huertos.dto.ExpenseDto;
|
import net.miarma.backend.huertos.dto.ExpenseDto;
|
||||||
import net.miarma.backend.huertos.model.Expense;
|
import net.miarma.backend.huertos.model.Expense;
|
||||||
|
import net.miarma.backend.huertos.model.Income;
|
||||||
import net.miarma.backend.huertos.repository.ExpenseRepository;
|
import net.miarma.backend.huertos.repository.ExpenseRepository;
|
||||||
import net.miarma.backlib.exception.NotFoundException;
|
import net.miarma.backlib.exception.NotFoundException;
|
||||||
import net.miarma.backlib.exception.ValidationException;
|
import net.miarma.backlib.exception.ValidationException;
|
||||||
@@ -10,6 +11,7 @@ import net.miarma.backlib.util.UuidUtil;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@@ -24,7 +26,9 @@ public class ExpenseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<Expense> getAll() {
|
public List<Expense> getAll() {
|
||||||
return expenseRepository.findAll();
|
return expenseRepository.findAll().stream()
|
||||||
|
.sorted(Comparator.comparing(Expense::getCreatedAt).reversed())
|
||||||
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Expense getById(UUID expenseId) {
|
public Expense getById(UUID expenseId) {
|
||||||
@@ -76,6 +80,9 @@ public class ExpenseService {
|
|||||||
if (changes.getType() != null)
|
if (changes.getType() != null)
|
||||||
expense.setType(changes.getType());
|
expense.setType(changes.getType());
|
||||||
|
|
||||||
|
if (changes.getCreatedAt() != null)
|
||||||
|
expense.setCreatedAt(changes.getCreatedAt());
|
||||||
|
|
||||||
return expenseRepository.save(expense);
|
return expenseRepository.save(expense);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,12 @@ package net.miarma.backend.huertos.service;
|
|||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.temporal.TemporalAmount;
|
import java.time.temporal.TemporalAmount;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
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.BadRequestException;
|
||||||
import net.miarma.backlib.exception.NotFoundException;
|
import net.miarma.backlib.exception.NotFoundException;
|
||||||
import net.miarma.backlib.exception.ValidationException;
|
import net.miarma.backlib.exception.ValidationException;
|
||||||
@@ -20,16 +23,21 @@ import net.miarma.backlib.util.UuidUtil;
|
|||||||
public class IncomeService {
|
public class IncomeService {
|
||||||
|
|
||||||
private final IncomeRepository incomeRepository;
|
private final IncomeRepository incomeRepository;
|
||||||
|
private final VIncomesWithInfoService incomesWithInfoService;
|
||||||
private final UserMetadataService metadataService;
|
private final UserMetadataService metadataService;
|
||||||
|
|
||||||
public IncomeService(IncomeRepository incomeRepository,
|
public IncomeService(IncomeRepository incomeRepository,
|
||||||
|
VIncomesWithInfoService incomesWithInfoService,
|
||||||
UserMetadataService metadataService) {
|
UserMetadataService metadataService) {
|
||||||
this.incomeRepository = incomeRepository;
|
this.incomeRepository = incomeRepository;
|
||||||
|
this.incomesWithInfoService = incomesWithInfoService;
|
||||||
this.metadataService = metadataService;
|
this.metadataService = metadataService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Income> getAll() {
|
public List<Income> getAll() {
|
||||||
return incomeRepository.findAll();
|
return incomeRepository.findAll().stream()
|
||||||
|
.sorted(Comparator.comparing(Income::getCreatedAt).reversed())
|
||||||
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Income getById(UUID incomeId) {
|
public Income getById(UUID incomeId) {
|
||||||
@@ -81,6 +89,9 @@ public class IncomeService {
|
|||||||
}
|
}
|
||||||
if (changes.getType() != null) income.setType(changes.getType());
|
if (changes.getType() != null) income.setType(changes.getType());
|
||||||
if (changes.getFrequency() != null) income.setFrequency(changes.getFrequency());
|
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);
|
return incomeRepository.save(income);
|
||||||
}
|
}
|
||||||
@@ -110,8 +121,8 @@ public class IncomeService {
|
|||||||
return !incomes.isEmpty() && incomes.stream().allMatch(Income::isPaid);
|
return !incomes.isEmpty() && incomes.stream().allMatch(Income::isPaid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Income> getByMemberNumber(Integer memberNumber) {
|
public List<VIncomesWithInfo> getByMemberNumber(Integer memberNumber) {
|
||||||
UUID userId = metadataService.getByMemberNumber(memberNumber).getUserId();
|
UUID userId = metadataService.getByMemberNumber(memberNumber).getUserId();
|
||||||
return getByUserId(userId);
|
return incomesWithInfoService.getByUserId(userId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,12 @@
|
|||||||
|
|
||||||
import net.miarma.backend.huertos.client.HuertosWebClient;
|
import net.miarma.backend.huertos.client.HuertosWebClient;
|
||||||
import net.miarma.backend.huertos.dto.*;
|
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.DropdownDtoMapper;
|
||||||
import net.miarma.backend.huertos.mapper.RequestMapper;
|
import net.miarma.backend.huertos.mapper.RequestMapper;
|
||||||
import net.miarma.backend.huertos.mapper.UserMetadataMapper;
|
import net.miarma.backend.huertos.mapper.UserMetadataMapper;
|
||||||
import net.miarma.backend.huertos.mapper.IncomeMapper;
|
import net.miarma.backend.huertos.mapper.IncomeMapper;
|
||||||
|
import net.miarma.backend.huertos.mapper.view.VIncomesWithInfoMapper;
|
||||||
import net.miarma.backend.huertos.security.NameCensorer;
|
import net.miarma.backend.huertos.security.NameCensorer;
|
||||||
import net.miarma.backlib.dto.UserWithCredentialDto;
|
import net.miarma.backlib.dto.UserWithCredentialDto;
|
||||||
import net.miarma.backlib.exception.NotFoundException;
|
import net.miarma.backlib.exception.NotFoundException;
|
||||||
@@ -66,6 +68,7 @@
|
|||||||
UserMetadataMapper.toDto(meta)
|
UserMetadataMapper.toDto(meta)
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
|
.sorted(Comparator.comparing(dto -> dto.metadata().getMemberNumber()))
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,8 +80,8 @@
|
|||||||
.map(RequestMapper::toResponse)
|
.map(RequestMapper::toResponse)
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
List<IncomeDto.Response> payments = incomeService.getByMemberNumber(memberNumber).stream()
|
List<VIncomesWithInfoDto> payments = incomeService.getByMemberNumber(memberNumber).stream()
|
||||||
.map(IncomeMapper::toResponse)
|
.map(VIncomesWithInfoMapper::toResponse)
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
return new MemberProfileDto(
|
return new MemberProfileDto(
|
||||||
@@ -146,9 +149,9 @@
|
|||||||
.orElseThrow(() -> new NotFoundException("No hay socio con ese DNI"));
|
.orElseThrow(() -> new NotFoundException("No hay socio con ese DNI"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<IncomeDto.Response> getIncomes(Integer memberNumber) {
|
public List<VIncomesWithInfoDto> getIncomes(Integer memberNumber) {
|
||||||
return incomeService.getByMemberNumber(memberNumber).stream()
|
return incomeService.getByMemberNumber(memberNumber).stream()
|
||||||
.map(IncomeMapper::toResponse)
|
.map(VIncomesWithInfoMapper::toResponse)
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package net.miarma.backend.huertos.service.view;
|
package net.miarma.backend.huertos.service.view;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import net.miarma.backend.huertos.model.Income;
|
||||||
import net.miarma.backlib.exception.NotFoundException;
|
import net.miarma.backlib.exception.NotFoundException;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -22,7 +24,9 @@ public class VIncomesWithInfoService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<VIncomesWithInfo> getAll() {
|
public List<VIncomesWithInfo> getAll() {
|
||||||
return repository.findAll();
|
return repository.findAll().stream()
|
||||||
|
.sorted(Comparator.comparing(VIncomesWithInfo::getCreatedAt).reversed())
|
||||||
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public VIncomesWithInfo getById(UUID incomeId) {
|
public VIncomesWithInfo getById(UUID incomeId) {
|
||||||
|
|||||||
Reference in New Issue
Block a user