RESTful web service built with Spring Boot, using MySQL for the database and provides endpoints for creating, updating, and retrieving expense records.
The primary structure involves two main tables:
- users
- expense_base
The users table serves as the repository for user information. Whenever a new user is created, their details, are stored in this table.
`users` (
`user_id` varchar(255) NOT NULL,
`email_id` varchar(255) DEFAULT NULL,
`password` varchar(255) DEFAULT NULL,
`username` varchar(255) DEFAULT NULL,
PRIMARY KEY (`user_id`)
)
The expense_base table acts as a foundational template for individual user expense tables. When a new user is added to the system, a corresponding table is dynamically created with the user's username as the table name.
`expense_base` (
`transaction_id` int NOT NULL AUTO_INCREMENT,
`amount` decimal(10,2) NOT NULL,
`isCredited` tinyint(1) NOT NULL,
`category` varchar(255) NOT NULL,
`description` varchar(255) NOT NULL,
`transaction_date` datetime NOT NULL,
PRIMARY KEY (`transaction_id`)
)
-
Creating a new user
POST /user/new
{
"password": "[password]",
"username": "[username]",
"emailId": "[email id]"
}
{
"status": "success",
"message": "User created successfully",
"data": {
"userId": "[userid]", //generated
"username": "[username]",
"password": "[password]",
"emailId": "[email id]"
}
}
{
"status": "failure",
"message": "User already exists",
"data": {
"userId": null,
"username": "[username]",
"password": "[password]",
"emailId": "[email id]"
}
}
-
Authentication of a user
POST /user/auth
{
"username":"[username]" ,
"password": "[password]"
}
{
"status": "successful",
"message": "Authenticated Successfully",
"token": "[JWT TOKEN]"
}
{
"status": "failure",
"message": "Unauthorized: Authentication unsuccessful.",
"data": null
}
-
Add a expense
POST /expense/add/{username}
Authorization: Bearer [JWT Token]
{
"amount": "[amount]",
"isCredit": [true/false],
"category": "[category]",
"description": "[description]",
"dateTime": "[dateTime]"
}
{
"status": "success",
"message": "Expense Added Successfully",
"data": {
"id": null,
"dateTime": "[dateTime]",
"amount": "[amount]",
"description": "[description]",
"category": "[category]",
"credit": [true/false]
}
}
-
Get all expenses
GET /expense/get/all/{username}
Authorization: Bearer [JWT Token]
[
{
"id": 1,
"dateTime": "[DateTime 1]",
"amount": "[Amount 1]",
"description": "[Description 1]",
"category": "[Category 1]",
"credit": false
},
{
"id": 2,
"dateTime": "[DateTime 2]",
"amount": "[Amount 2]",
"description": "[Description 2]",
"category": "[Category 2]",
"credit": false
},
{
"id": 3,
"dateTime": "[DateTime 3]",
"amount": "[Amount 3]",
"description": "[Description 3]",
"category": "[Category 3]",
"credit": false
}
]
-
Update a expense
PUT /expense/update/{username}/{id}
Authorization: Bearer [JWT Token]
{
"dateTime": "[updated date time]",
"amount": [updated amount],
"description": "[updated description]",
"category": "[updated category]",
"isCredit": [updated boolean]
}
{
"status": "success",
"message": "Expense Updated Successfully",
"data": {
"id": 3,
"dateTime": "[updated date time]",
"amount": [updated amount],
"description": "[updated description]",
"category": "[updated category]",
"credit": [updated boolean]
}
}
-
Delete a expense
/expense/delete/{username}/{id}
Authorization: Bearer [JWT Token]
{
"status": "success",
"message": "Expense Deleted Successfully",
"data": null
}