Skip to content

mariocalin/challenge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Code challenge

This challenge has been developed entirely by Mario Calín Sánchez.

1 Requirements

1.1 Developed in this system

The code challenge has been developed using the technologies:

  • Ubuntu 22.04
  • Java JDK 21
  • Apache Maven 3.9.6

2 Business assumptions

I have set some assumptions about the business rules that I consider relevant:

  • The transaction reference is a string in form of UUID. This has made really simple the generation of unique identifiers. I am aware that they may not be efficient in production ready databases.
  • The feature definition of the check transaction status endpoint features have slightly changed. I find setting the transaction date before calling the system more understandable, therefore the And step concerning the transaction date has been moved from When to Given.
  • In the check transaction status endpoint it is not mandatory to set the channel parameter. In that case, the default value is been given to INTERNAL in the query.

3 Build, testing and execution

For developing the application, the following technologies have been used:

  • Springboot 3.2 as web framework.
  • H2 In memory database as persistence

Every maven command in this section must be used in the project's root folder.

3.1 Building the app

For building the app the following maven command can be used:

mvn install -DskipTests

3.2 Testing the app

Unit testing

Unit tests for CreateTransactionCommand and SearchTransactionsQuery have been created as an example.

To run only unit tests use the following maven command:

mvn test

Integration testing and acceptance tests

An integration test for SQLTransactionRepository with H2 database has been created.

Two ways of creating acceptance test have been followed:

  • Acceptance test with only JUnit (create transaction and search transaction endpoints)
  • Cucumber with gherkin language (check endpoint status)

To run both integration and acceptance tests the following maven command can be used:

mvn verify

3.3 Running the app

To run the application just run the following maven command inside the project's root folder. It will run the app in the url http://localhost:8080.

mvn spring-boot:run

3.4 GitHub actions as CI

A simple GitHub action has been added to verify that the build is passing. It is located in the .github/workflows/build.yml and it consist of steps for building and testing the application. GitHub also provides a cool green "tick" in the repo page if the build is passing.

See an example of an action passing (the full description migght not be available)

4 Application

In this section I explain some features that the application provides.

4.1 Database migrations

Flyway has been used in order to illustrate database migrations. Currently, there is only a table creation script, and it is executed if the database is not in the last version automatically.

4.2 API contract

Thanks to the open api plugin a file called openapi.yml is created for defining the api contract. Currently, the file is placed in the target folder after running the integration testing phase.

4.3 Architecture

I have followed architectural and testing concepts: Test driven design, Acceptance test driven design, Domain driven design, hexagonal architecture and a form of CQRS with a simple command-query bus implementation.

4.4 Misc

Conventional commits have been as can be checked in the commits history.

5 API usage

Some api usage examples are provided in this section. They are based on curl tool and they are ready to be used in an unix shell. Moreover, with the application running you are able to see the api specification accessing the link http://localhost:8080/swagger-ui/index.html#/.

5.1 Create transaction endpoint

Create a transaction with all parameters

curl -i -X POST http://localhost:8080/v1/transaction/create \
     -H 'Content-Type: application/json'  \
     -d '{ "reference":"a005c77c-88e0-4436-bd6e-1867047739c1", "account_iban":"ES9820385778983000760236", "date":"2019-07-16T16:55:42.000Z", "amount":193.38, "fee":3.18, "description":"Restaurant payment"}' 

Create a transaction with no reference

curl -i -X POST http://localhost:8080/v1/transaction/create \
     -H 'Content-Type: application/json'  \
     -d '{ "account_iban":"ES9820385778983000760236", "date":"2019-07-16T16:55:42.000Z", "amount":193.38, "fee":3.18, "description":"Restaurant payment"}' 

Create a transaction with no iban results in bad request

curl -i -X POST http://localhost:8080/v1/transaction/create \
     -H 'Content-Type: application/json'  \
     -d '{ "reference":"a005c77c-88e0-4436-bd6e-1867047739c1", "date":"2019-07-16T16:55:42.000Z", "amount":193.38, "fee":3.18, "description":"Restaurant payment"}' 

5.2 Search transactions

Some transaction have been loaded for testing purposes. Those transaction are created for ES0204877966878429941794 IBAN. Use the examples below.

Search transactions for iban.

curl -i -X GET http://localhost:8080/v1/transaction/search?account_iban=ES0204877966878429941794

Search transactions for iban ordered by amount.

curl -i -X GET http://localhost:8080/v1/transaction/search?account_iban=ES0204877966878429941794&orderByAmount=asc

5.3 Check transactions status

Some transaction have been loaded for testing purposes. Use the examples below.

Check transaction status

curl -i -X POST http://localhost:8080/v1/transaction/status \
-H 'Content-Type: application/json'  \
-d '{ "reference":"462789e2-d01f-4bcd-96bc-d391050648e9", "channel":"INTERNAL"}'
curl -i -X POST http://localhost:8080/v1/transaction/status \
-H 'Content-Type: application/json'  \
-d '{ "reference":"462789e2-d01f-4bcd-96bc-d391050648e9"}'
curl -i -X POST http://localhost:8080/v1/transaction/status \
-H 'Content-Type: application/json'  \
-d '{ "reference":"6b732680-330e-4e35-a9f6-14699784adcd", "channel":"ATM"}'
curl -i -X POST http://localhost:8080/v1/transaction/status \
-H 'Content-Type: application/json'  \
-d '{ "reference":"89cb0aa2-1569-4aea-ae0a-6e2560a17bdd", "channel":"CLIENT"}'

6 Future work

  • Asynchronous communication and event driven architectures are really common in microservices. It might be advisable to add domain events such as TransactionCreated.
  • In order to make this services a containerized application, a Dockerfile might be added in order to provide a cloud-ready docker image.
  • Enrich openapi specification with endpoint information, documentation, requests and responses.

About

Code challenge transactions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors