Skip to content

Latest commit

 

History

History
83 lines (57 loc) · 2.52 KB

README.md

File metadata and controls

83 lines (57 loc) · 2.52 KB

The task is to build a simple REST API using Spring Boot Framework and PostgreSQL.

API TASK

Implement a transaction API for enabling fund transfer between users.

SUBTASK 1: Database Design

  • You will use PostgreSQL as your choice of database for this assignment.
  • Create sql scripts for database creation. It should be possible to setup the db with a single terminal command.
  • Load a users table from spec/users.json with a load script. You can use any language for this (python, js, raw sql, shell, etc) but it must be automated.
  • The transactions table should have valid {senderId, receiverId}. Both these values should belong to a valid users. Bonus points if you use foreign keys!

SUBTASK 2: Retrieve a transaction

GET: /api/transactions/<transactionId>

  • Returns transaction information for a given transaction Id. Check spec/transaction.json for the transaction format.

SUBTASK 3: Retrieve all transactions

GET: /api/transactions/

  • Returns all transactions [list of spec/transaction.json]

SUBTASK 4: Create a new transaction

POST: /api/transactions/

  • Creates a new transaction.
  • Payload will contain {senderId, receiverId, amount, details}.
  • Transaction Id will be autogenerated on backend - should be uuid!.
  • Validate the transaction to check if balance is sufficient in sender's account.
  • Store the transaction in the database.

SUBTASK 5: Reverse a transaction

DELETE: /api/transactions/<transactionId>

  • Reverses a transaction and restores the senders and receivers balance accordingly.

Steps to Install

Load Script

  • Install psycopg2 using:
    pip install psycopg2
    
  • Run the python script to load the users.json to PostgreSQL database server
    python script.py <your username> <your password> <hostname> <portname>
    
    Here hostname and portname are optional and can be omitted:
    python script.py <your username> <your password>
    

Application Properties

  • Navigate to application.properties in the resources folder
  • Change the default username and password to your own PostgreSQL server's username and password:
    spring.datasource.username=yourusername
    spring.datasource.password=yourpassword
    
  • If your host and port are different from defaults, change the JDBC url.\

From:

  spring.datasource.url=jdbc:postgresql://localhost:5432/neowise

To:

  spring.datasource.url=jdbc:postgresql://<your host>:<your port>/neowise

All set! Now run the Spring Boot Application!