tufangorel / accounts

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

User Savings Account REST API

REST endpoint that allows an existing user to open a savings account.

Run with

Run: accounts > mvn spring-boot:run

Tech Stack

Java 8
Spring Boot
Spring Data JPA
Hibernate
H2 in memory db
Maven

Database Tables

create table account (account_id integer generated by default as identity, balance decimal(19,2), primary key (account_id))
create table user (user_id integer generated by default as identity, name varchar(255), primary key (user_id))
create table user_account (account_id integer not null, user_id integer not null, primary key (account_id, user_id))

Database Tables Definitions

user = Stores user detail information (such as user name)
account = Stores account detail information (such as account balance)
user_account = Join table for user-savingAccount pairs

Requirements

  • Create a new user
  • Add a savings account to an existing user

Create a new user

Method : HTTP.POST
URL : http://localhost:8080/user/save

Request Input Test Data :

{
	"name" : "Kiril"
}

Response :

HTTP response code 200

{
    "userId": 2,
    "name": "Kiril"
}

Add a savings account to an existing user

Method : HTTP.POST
URL : http://localhost:8080/userSavingsAccount/save

Case 1 : Existing user id is provided in input JSON message 

Request Input Test Data :
{
    "userId": 1
}

Response : 

HTTP response code 200 
{ "userId": 1, "accountId": 1 } Case 2 : Non-Existing user id is provided in input JSON message Request Input Test Data : { "userId": 3 } Response : HTTP response code 451
{ "msgList": [ "User does not exist in the system. Save user before savings account creation." ] } Case 3 : User having savings account is provided in input JSON message again. Request Input Test Data : { "userId": 1 } Response : HTTP response code 451
{ "msgList": [ "User can have only one savings account. Duplicate savings account creation is not allowed." ] } Case 4 : Savings account opening time is violated. Request Input Test Data : { "userId": 1 } Response : HTTP response code 451
{ "msgList": [ "The account can only be opened between 8 AM and 5 PM." ] }

About


Languages

Language:Java 100.0%