Class MongoExpenseRepository

java.lang.Object
com.truebubo.maniflow.expense.MongoExpenseRepository
All Implemented Interfaces:
ExpenseRepository

@Repository public class MongoExpenseRepository extends Object implements ExpenseRepository
Repository used for dealing with storage and retrieval of expense using MongoDB
  • Constructor Details

    • MongoExpenseRepository

      public MongoExpenseRepository(@NonNull com.mongodb.client.MongoClient mongoClient)
      Creates mongo repository
      Parameters:
      mongoClient - Mongo client to be used
  • Method Details

    • saveExpense

      @Nullable public Expense saveExpense(@NonNull Expense expense)
      Description copied from interface: ExpenseRepository
      Saves the expense to storage
      Specified by:
      saveExpense in interface ExpenseRepository
      Parameters:
      expense - Expense saved
      Returns:
      expense saved
    • getExpense

      @NonNull public Optional<Expense> getExpense(int id)
      Description copied from interface: ExpenseRepository
      Finds the expense with given id
      Specified by:
      getExpense in interface ExpenseRepository
      Parameters:
      id - ID as shown by showExpenses
      Returns:
      Expense if found else empty
    • getExpenses

      @NonNull public List<Expense> getExpenses()
      Description copied from interface: ExpenseRepository
      Finds all the expenses saved
      Specified by:
      getExpenses in interface ExpenseRepository
      Returns:
      List of all the expenses saved
    • changeExpense

      @Nullable public Optional<Expense> changeExpense(int id, @NonNull BigDecimal newAmount)
      Description copied from interface: ExpenseRepository
      Changes the expense with given ID
      Specified by:
      changeExpense in interface ExpenseRepository
      Parameters:
      id - ID identifying the expense. It is the left value displayed when calling showExpenses
      newAmount - Will update the value to this value. If set to zero. The expanse will be removed
      Returns:
      Changed expense or empty if did not change