use of com.example.expenses.model.Person in project aws-java-serverless by hermanlintvelt.
the class ExpenseAggregate method createMockedData.
public void createMockedData() {
Person me = new Person("me@me.com");
createExpense(new Expense(BigDecimal.valueOf(150.0), me));
createExpense(new Expense(BigDecimal.valueOf(234.0), me));
createExpense(new Expense(BigDecimal.valueOf(234.0), new Person("you@me.com")));
}
use of com.example.expenses.model.Person in project aws-java-serverless by hermanlintvelt.
the class CreateExpenseHandlerJsonNode method handleRequest.
@Override
public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent request, Context context) {
LOG.info("Creating an expense from request: " + request.toString());
try {
JsonNode jsonNode = OBJECT_MAPPER.readTree(request.getBody());
String email = jsonNode.get("email").asText();
BigDecimal amount = BigDecimal.valueOf(jsonNode.get("amount").asDouble());
Expense newExpense = EXPENSE_AGGREGATE.createExpense(new Expense(amount, new Person(email)));
LOG.info("Created expense: " + newExpense);
return new APIGatewayProxyResponseEvent().withStatusCode(200).withBody(OBJECT_MAPPER.writeValueAsString(newExpense));
} catch (JsonProcessingException e) {
LOG.error("Error parsing request body to create new expense", e);
return new APIGatewayProxyResponseEvent().withStatusCode(400).withBody("Invalid Expense object in request body.");
}
}
use of com.example.expenses.model.Person in project aws-java-serverless by hermanlintvelt.
the class CreateExpenseHandlerRequestObject method handleRequest.
@Override
public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent request, Context context) {
LOG.info("Creating an expense from request: " + request.toString());
try {
CreateExpenseRequest createExpenseRequest = OBJECT_MAPPER.readValue(request.getBody(), CreateExpenseRequest.class);
Expense newExpense = EXPENSE_AGGREGATE.createExpense(new Expense(BigDecimal.valueOf(createExpenseRequest.getAmount()), new Person(createExpenseRequest.getEmail())));
LOG.info("Created expense: " + newExpense);
return new APIGatewayProxyResponseEvent().withStatusCode(200).withBody(OBJECT_MAPPER.writeValueAsString(newExpense));
} catch (JsonProcessingException e) {
LOG.error("Error parsing request body to create new expense", e);
return new APIGatewayProxyResponseEvent().withStatusCode(400).withBody("Invalid Expense object in request body.");
}
}
use of com.example.expenses.model.Person in project aws-java-serverless by hermanlintvelt.
the class ExpenseAggregateTest method createExpense.
@Test
@DisplayName("Creating test should result in expense existing in service")
void createExpense() {
Person me = new Person("me@me.com");
Expense expense = new Expense(BigDecimal.valueOf(150.0), me);
expenseAggregate.createExpense(expense);
assertThat(expenseAggregate.getAllExpenses()).asList().contains(expense);
}
use of com.example.expenses.model.Person in project aws-java-serverless by hermanlintvelt.
the class ExpenseAggregateTest method findExpensesPaidBy.
@Test
@DisplayName("If two expenses are created via service, the service must found them for person")
void findExpensesPaidBy() {
Person me = new Person("me@me.com");
Expense expense1 = new Expense(BigDecimal.valueOf(150.0), me);
expenseAggregate.createExpense(expense1);
Expense expense2 = new Expense(BigDecimal.valueOf(80.0), me);
expenseAggregate.createExpense(expense2);
List<Expense> foundExpenses = expenseAggregate.findExpensesPaidBy(me.getEmail());
assertThat(foundExpenses).isNotNull();
assertThat(foundExpenses).asList().isNotEmpty();
assertThat(foundExpenses).asList().contains(expense1, expense2);
}
Aggregations