add possibility to get expenses by date and month
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.faf223.expensetrackerfaf.service;
|
||||
|
||||
import com.faf223.expensetrackerfaf.model.Credential;
|
||||
import com.faf223.expensetrackerfaf.model.Expense;
|
||||
import com.faf223.expensetrackerfaf.model.IMoneyTransaction;
|
||||
import com.faf223.expensetrackerfaf.model.Income;
|
||||
import com.faf223.expensetrackerfaf.repository.CredentialRepository;
|
||||
@@ -8,6 +9,8 @@ import com.faf223.expensetrackerfaf.repository.IncomeRepository;
|
||||
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;
|
||||
@@ -37,6 +40,20 @@ public class IncomeService implements ITransactionService {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Income> getTransactionsByDate(LocalDate date) {
|
||||
return incomeRepository.findByDate(date);
|
||||
}
|
||||
|
||||
// TODO: store transaction month in a separate field in the DB and change this logic
|
||||
@Override
|
||||
public List<Income> getTransactionsByMonth(Month month) {
|
||||
LocalDate startOfMonth = LocalDate.of(LocalDate.now().getYear(), month, 1);
|
||||
LocalDate endOfMonth = startOfMonth.plusMonths(1).minusDays(1);
|
||||
|
||||
return incomeRepository.findByDateBetween(startOfMonth, endOfMonth);
|
||||
}
|
||||
|
||||
public Income getTransactionById(long id) {
|
||||
return incomeRepository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user