Giter VIP home page Giter VIP logo

rajagopal28 / stocks-splurge Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 3.3 MB

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: MIT License

Java 83.64% HTML 6.03% JavaScript 10.33%
stocks spring-boot spring-mvc tdd-java rest-api mvc-pattern single-page-app test-pyramid single-responsibility-principle jpa-hibernate dependency-injection inversion-of-control

stocks-splurge's Introduction

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

stocks-splurge's People

Contributors

rajagopal28 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.