Search in sources :

Example 1 with Spending

use of model.db.Spending in project amos-ss17-alexa by c-i-ber.

the class AmosAlexaSimpleTestImpl method resetTestCategory.

private void resetTestCategory() {
    // Delete old test category
    List<Category> categories = DynamoDbMapper.getInstance().loadAll(Category.class);
    Category category = null;
    List<String> testCategoryIds = new ArrayList<>();
    for (Category cat : categories) {
        if (cat.getName().equals(TEST_CATEGORY_NAME)) {
            testCategoryIds.add(cat.getId());
            category = cat;
            DynamoDbMapper.getInstance().delete(cat);
        // DynamoDbClient.instance.deleteItem(Category.TABLE_NAME, cat);
        }
    }
    List<Spending> dbSpendings = dynamoDbMapper.loadAll(Spending.class);
    for (Spending spending : dbSpendings) {
        String catId;
        try {
            catId = spending.getCategoryId();
        } catch (Exception e) {
            continue;
        }
        if (testCategoryIds.contains(catId)) {
            dynamoDbMapper.delete(spending);
        }
    }
}
Also used : Category(model.db.Category) Spending(model.db.Spending) IOException(java.io.IOException)

Example 2 with Spending

use of model.db.Spending in project amos-ss17-alexa by c-i-ber.

the class BudgetManager method getSpendingAmount.

private double getSpendingAmount(String categoryId, DateTime start, DateTime end) {
    double sum = 0;
    List<Spending> dbSpendings = dynamoDbMapper.loadAll(Spending.class);
    for (Spending spending : dbSpendings) {
        if (spending.getCategoryId().equals(categoryId)) {
            if (spending.getCreationDateTimeAsDateTime().isAfter(start) && spending.getCreationDateTimeAsDateTime().isBefore(end)) {
                sum += spending.getAmount();
            }
        }
    }
    return sum;
}
Also used : Spending(model.db.Spending)

Aggregations

Spending (model.db.Spending)2 IOException (java.io.IOException)1 Category (model.db.Category)1