Skip to content

A java spring-boot based REST application to handle stocks based CRUD operations with some locking techniques to prevent short time stock data manipulation.

License

Notifications You must be signed in to change notification settings

rajagopal28/stocks-splurge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stocks Splurge - Stock data REST API

A java spring-boot based REST application to handle stocks based CRUD operations with some locking techniques to prevent short time stock data manipulation. It is a minimal Proof of concept that adheres to the requirements mentioned in Here

Key aspects related to implementation:

  • Employing test driven development practice while building application - Each module goes through the red -> fix -> green -> refactor cycle
  • Intensive unit tests - Mocktio based unit tests to observe interactions of various actors
  • Separation of concerns - Modular approach on top of MVC paradigm in giving specific responsibility to each module in the application
    • Persistence layer powered by jpa/hibernate libraies taking care of the data persistence with simplified ORM capabilities mapping to relational entities.
    • Service layer to handle data persistence and business logics required to invoke the what3words api with the location data supplied
    • Controller to handle all the endpoint calls to process the data from users.
    • Models to keep track of data that is processed by the system.
    • ControllerAdvice to handle all the user defined exceptions handled at the runtime to send proper response code to users to better understand the flow.
  • Dependency resolution with Spring-Boot's Auto-configuration and dependency resolution.
  • MVC test to support integration testing of the entire Spring Application.
  • Lombok - used annotation based pre-processing to reduce a lot of boilerplate code that can be deferred to compile time.
  • H2 in memory data base along with the persistence capabilities in java/spring-boot to enable in-memory data management.
  • Minimal UI : Single page UI with the stock CRUD operations created using jQuery UI with essential aspects with javascript and css. With my very minimal knowledge on styling and css I used jQuery UI to create a simpler app in a really limited amount of time.

TDD - Red->Green->Refactor cycle

TDD Diagram

REST APIs

Post new Stock to system

Request
POST /api/stocks HTTP/1.1
Host: localhost:8080
Content-Type: application/json

{
     "name":"PCNQ",
     "currentPrice": 12.45
}

Request format:

name – the name of the company stock in the system. currentPrice - the price of that particular stock.

Response

Returns: The created stock object with reference details.

200 – in case of success 400 – if the request is missing the name or invalid price. 208 – if the name given to update is found in system for other stock. 422 – if one of the fields sent is empty or wrong. 403 - if the request is to update/delte the stock within the lock window.

HTTP/1.1 201 Created
Content-Type: application/json

{
    "id": 1,
    "name": "PCNQ",
    "currentPrice": 12.45,
    "timeCreated": 1636817934,
    "lastUpdated": 1636817934
}

OR

HTTP/1.1 208 Already reported
Content-Type: application/json

OR

HTTP/1.1 422 Unprocessable Entity
Content-Type: application/json

{
    "message": "Invalid request data passed!"
}

Get Particular stock in the system with ID

Response

Returns: The created stock object with reference details.

200 – in case of success 204 – if the given id is not in the system.

GET /api/stocks/1 HTTP/1.1
Host: localhost:8080

{
    "id": 1,
    "name": "PCNQ",
    "currentPrice": 12.45,
    "timeCreated": 1636817934,
    "lastUpdated": 1636817934
}

OR

HTTP/1.1 204 No content
Content-Type: application/json

Get List of all stocks in the system.

Response

Returns: The list of created stock objects with reference details. 200 – in case of success

GET /api/stocks/ HTTP/1.1
Host: localhost:8080

[{
    "id": 1,
    "name": "PCNQ",
    "currentPrice": 12.45,
    "timeCreated": 1636817934,
    "lastUpdated": 1636817934
},{
    "id": 2,
    "name": "ADYN",
    "currentPrice": 45.87,
    "timeCreated": 1636817934,
    "lastUpdated": 1636817934
}]

Delete Particular stock in the system with ID

Response

Returns: The created stock object with reference details.

200 – in case of success 204 – if the given id is not in the system. 403 - if the request is to update/delete the stock within the lock window.

DELTE /api/stocks/1 HTTP/1.1
Host: localhost:8080

{
    "id": 1,
    "name": "PCNQ",
    "currentPrice": 12.45,
    "timeCreated": 1636817934,
    "lastUpdated": 1636817934
}

OR

HTTP/1.1 204 No content
Content-Type: application/json

OR

HTTP/1.1 402 Forbidden
Content-Type: application/json

{
    "message": "Cannot manipulate stock within Lock window!"
}

Update Stock name or price in the system with ID

Request
PUT /api/stocks/1 HTTP/1.1
Host: localhost:8080
Content-Type: application/json

{
     "name":"PCNQ2",
     "currentPrice": 23.32
}

Request format:

name – the name of the company stock in the system. currentPrice - the price of that particular stock.

Response

Returns: The created stock object with reference details.

200 – in case of success 400 – if the request is missing the name or invalid price. 208 – if the name given to update is found in system for other stock. 422 – if one of the fields sent is empty or wrong. 403 - if the request is to update/delete the stock within the lock window.

HTTP/1.1 200 OK
Content-Type: application/json

{
    "id": 1,
    "name": "PCNQ2",
    "currentPrice": 23.32,
    "timeCreated": 1636817934,
    "lastUpdated": 1636817934
}

OR

HTTP/1.1 208 Already reported
Content-Type: application/json

OR

HTTP/1.1 400 Bad Request
Content-Type: application/json

{
    "message": "Blank request cannot be updated!"
}

OR

HTTP/1.1 402 Forbidden
Content-Type: application/json

{
    "message": "Cannot manipulate stock within Lock window!"
}

Single page UI

Home

Home

Add Stock

Add-Stock

Add-Stock

Update Stock

Update-Stock

Update-Stock

Update-Stock

Delete Stock

Delete-Stock

Delete-Stock

Test Coverage

TestCoverage

TestCoverage

TestCoverage

Dependencies

Dependencies

Dependencies

Dependencies

Testing

This application is build following TDD principles and are rich with various integration/unit tests based on test pyramids To run all the tests:

mvn clean test

Build

In order to build this application, run the following maven command.

mvn clean package

installing the packages

With Tests:

$ mvn clean install -U

running tests

Unit tests:

$ mvn  test

running the app locally in localhost:8080

Application Server:

$ java  target/stocks-splurge-1.0.0.jar
    Developed in Jetbrain's IntelliJ IDE

References

License

MIT

About

A java spring-boot based REST application to handle stocks based CRUD operations with some locking techniques to prevent short time stock data manipulation.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published