add possibility to get expenses by date and month

This commit is contained in:
mirrerror
2023-11-13 09:08:16 +02:00
parent 04aa41e354
commit acbb6285d9
7 changed files with 84 additions and 2 deletions

View File

@@ -8,6 +8,8 @@ import com.faf223.expensetrackerfaf.repository.ExpenseRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.time.Month;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@@ -33,6 +35,20 @@ public class ExpenseService implements ITransactionService {
return new ArrayList<>();
}
@Override
public List<Expense> getTransactionsByDate(LocalDate date) {
return expenseRepository.findByDate(date);
}
// TODO: store transaction month in a separate field in the DB and change this logic
@Override
public List<Expense> getTransactionsByMonth(Month month) {
LocalDate startOfMonth = LocalDate.of(LocalDate.now().getYear(), month, 1);
LocalDate endOfMonth = startOfMonth.plusMonths(1).minusDays(1);
return expenseRepository.findByDateBetween(startOfMonth, endOfMonth);
}
public List<Expense> getTransactions() {
return expenseRepository.findAll();
}