Skip to content

SpringBoot Java 8 Rest API that handles Transfers with care

Notifications You must be signed in to change notification settings

felipeaffonso/payment-challenge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Payment Challenge

Table of Contents

Introduction

This is a Spring Boot 2.1.0 REST API with Swagger Documentation that uses Transactions and H2 as Database.

The main focus of this application is:

  • Maintain Accounts and Transfer money between then.

The relationship between Account and Transfer was mapped with 2 @ManyToOne annotations at the source and target accounts inside the Transfer.

There is a requirement, that the system need to be able to handle simultaneous transfer requests.

In order to process the simultaneous transfers, the system make use of transactions.

I just used the Optimistic Lock JPA feature, that controls the object version to avoid invalid states in a distributed system.

As we are dealing with financial information, I used another JPA Feature called Auditing, that maintain createadAt and updatedAt fields at the entities.

The application make use of RuntimeExceptions for business flux control, that affects also the API responses.

There is a difference between the Requests and the Responses that is handled by the Controllers and the Service layer. There are some data that sometimes we don't want or we can't expose for external world. Because of this, the application have different objects that comes in and out.

To convert the Objects, I have created a Functional Interface that can be implemented with the necessary objects.

There is data.sql file that inserts 2 example accounts and 1 example transfer between them.

Technical Info

The software was built using the following tools/platforms:

Requirements

In order to run the application, you need to have installed at your environment:

  1. Java 8
  2. Maven

Usage

First, you have to generate the jar with mvn:

$ mvn clean install

You are ready to run with the command:

$ mvn springboot:run

The program will start embedded tomcat at port 8080, so you can now navigate to Swagger UI

Swagger Documentation could be reached HERE and can be imported to Postman, for example.

Test Coverage

I tried to focus on the application CORE BUSINESS, so not all the classes were not tested on purpose.

  1. Test Coverage is 100% of Tested Classes
  2. The Coverage is measured by Jacoco library that gives a HTML report that can be reached at target/site/jacoco/index.html

Non-Tested Classes

  1. Exceptions were not tested.
  2. PaymentChallengeApplication was nos tested
  3. JpaConfiguration and SwaggerConfig were not tested
  4. model package was not tested, but the Account class was, because of the business logic methods
  5. DTOs inside of request and response packages were not tested
  6. @NotSameAccount annotation was not tested

About

SpringBoot Java 8 Rest API that handles Transfers with care

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published