add possibility to get expenses by date and month
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.faf223.expensetrackerfaf.service;
|
||||
|
||||
import com.faf223.expensetrackerfaf.model.IMoneyTransaction;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.Month;
|
||||
import java.util.List;
|
||||
|
||||
public interface ITransactionService {
|
||||
@@ -9,6 +11,8 @@ public interface ITransactionService {
|
||||
void createOrUpdate(IMoneyTransaction transaction);
|
||||
List<? extends IMoneyTransaction> getTransactions();
|
||||
List<? extends IMoneyTransaction> getTransactionsByEmail(String email);
|
||||
List<? extends IMoneyTransaction> getTransactionsByDate(LocalDate date);
|
||||
List<? extends IMoneyTransaction> getTransactionsByMonth(Month month);
|
||||
IMoneyTransaction getTransactionById(long id);
|
||||
void deleteTransactionById(long it);
|
||||
|
||||
|
||||
@@ -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