The task is to build a simple REST API using Spring Boot Framework and PostgreSQL.
Implement a transaction API for enabling fund transfer between users.
- 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!
GET: /api/transactions/<transactionId>
- Returns transaction information for a given transaction Id. Check
spec/transaction.json
for the transaction format.
GET: /api/transactions/
- Returns all transactions [list of spec/transaction.json]
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.
DELETE: /api/transactions/<transactionId>
- Reverses a transaction and restores the senders and receivers balance accordingly.
- Install
psycopg2
using:pip install psycopg2
- Run the python script to load the users.json to PostgreSQL database server
Here
python script.py <your username> <your password> <hostname> <portname>
hostname
andportname
are optional and can be omitted:python script.py <your username> <your password>
- Navigate to
application.properties
in theresources
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