The Finance Manager API is a backend service designed to empower individuals and small businesses to effectively manage their financial data. It provides a comprehensive suite of features for tracking transactions, managing accounts, and categorizing expenses and income. By offering endpoints for creating, reading, updating, and deleting financial records, it adheres to the RESTful principles, ensuring a scalable, flexible, and intuitive interface for developers and applications.
- No specific hardware requirements.
- Operating System: Compatible with any OS that can run Python 3 (e.g., Windows, macOS, Linux).
All endpoints are documented in this README document, and can be imported from the endpoints.json file to either Insomnia, or Postman.
To run from local machine using postgreSQL:
- Create a new postgreSQL User and give Permissions
- Create a postgreSQL Database
- Edit ".env" file so "SQL_DATABASE_URI" matches user and database details
- Start python virtual invironment (python3 -m venv venv)
- Activate virtual environment (source venv/bin/activate)
- Install requirements (pip3 install -r requirements.txt)
- Create and seed tables (flask db drop && flask db create && flask db seed)
- Run flask app (flask run)
For ease of assessment, I have created a postgreSQL Databased hosted via Neon.tech - as such no configuration is required on your end to test functionality of this application.
The details for this are saved in the .env file included in submission, however for obvious reasons this is not shared directly to GitHub. As such, the only steps needed to be taken is to create and seed the tables, and run the flask server:
-
flask db drop && flask db create && flask db seed
-
flask run
Distributed under the terms of the MIT License
Click here for response
Click here for Account Controller Endpoints
This endpoint is protected and requires a valid JWT token.
Used to create a new Account in relation to a User
account_type
: (str
) type or description of accountbalance
: (int
) initial value of account
eg
{
"account_type": "savings",
"balance": 15000
}
JSON response of Account, 201
Example response:
{
"id": 4,
"account_type": "test",
"balance": "15000.00",
"transactions": [],
"date_created": "2024-03-22T09:55:02.430673",
"user": {
"username": "User",
"email": "[email protected]"
}
}
This endpoint is protected and requires a valid JWT token.
Retrieves a list of all accounts. Auditors can see all accounts, while other users see only their own.
JSON array of Account objects.
Example response:
[
{
"id": 1,
"account_type": "savings",
"balance": "1234.56",
"date_created": "2024-03-20T12:34:56.789Z",
"user": {
"username": "Admin",
"email": "[email protected]"
}
}
]
This endpoint is protected and requires a valid JWT token.
Retrieves information about a specific account. Auditors can view any account, while other users can only view their own accounts.
account_id
: URL parameter specifying the account's ID.
JSON representation of the specified Account
Example response:
{
"id": 2,
"account_type": "checking",
"balance": "5000.00",
"date_created": "2024-03-21T11:22:33.444Z",
"user": {
"username": "User",
"email": "[email protected]"
}
}
This endpoint is protected and requires a valid JWT token. Only Admins can update accounts not owned by themselves.
Updates information about a specific account.
account_type
: (Optional,str
) New type or description of the account.balance
: (Optional,int
) New balance value for the account.
{
"account_type": "emergency fund",
"balance": 20000
}
JSON representation of the updated Account, 201.
{
"id": 2,
"account_type": "emergency fund",
"balance": "20000.00",
"transactions": [],
"date_created": "2024-03-21T11:22:33.444Z",
"user": {
"username": "User",
"email": "[email protected]"
}
}
This endpoint is protected and requires a valid JWT token. Only Admins can delete accounts not owned by themselves.
Deletes a specific account.
account_id
: URL parameter specifying the account's ID.
Confirmation message of the deleted account, 201
Example response:
{
"message": "Account 'emergency fund' deleted successfully"
}
This endpoint is protected and requires a valid JWT token. Only accessible by users with the "Auditor" role.
Calculates the total balance across all accounts in the system.
JSON object with the total balance.
Example response:
{
"total_balance": "27345.01"
}
This endpoint is protected and requires a valid JWT token. Only accessible by users with the "Auditor" role.
Ranks transactions within a specific account based on the amount, showing the relative size of each transaction.
account_id
: URL parameter specifying the account's ID to rank transactions within.
JSON array of transactions with their ranks.
Example response:
[
{
"transaction_id": 3,
"amount": "-500.00",
"rank": 1
},
{
"transaction_id": 1,
"amount": "-300.00",
"rank": 2
}
]
This endpoint is protected and requires a valid JWT token. Only accessible by users with the "Auditor" role.
Provides a summary of each account including the account ID, type, and total spent in transactions.
JSON array with a summary for each account.
Example response:
[
{
"account_id": 1,
"account_type": "savings",
"total_spent": "-560.00"
},
{
"account_id": 2,
"account_type": "checking",
"total_spent": "-1230.00"
}
]
This endpoint is protected and requires a valid JWT token. It enables searching for transactions based on a description, with results filtered by the user's role.
Allows users to search for transactions across all accounts if they have the "Auditor" role. Regular users can only search within their own accounts.
query
: (str
) The search term to filter transactions by their description.
Example request:
{
"query": "groceries"
}
JSON array of transactions matching the search term, filtered according to the user's role.
Example response (for an "Auditor"):
[
{
"id": 2,
"amount": "-123.45",
"description": "groceries at mart",
"transaction_date": "2024-03-22T09:55:02.430673",
"account": {
"id": 1,
"account_type": "checking"
}
}
]
Click here for Auth Controller Endpoints
This endpoint is protected and requires a valid JWT token. Only accessible by users with the "Auditor" role.
Retrieves a list of all registered users in the system.
JSON array of User objects, 201
Example response:
[
{
"id": 1,
"username": "Admin",
"email": "[email protected]",
"role": "Admin",
"date_created": "2024-03-20T12:00:00Z"
}
]
This endpoint is open and does not require a JWT token.
Allows new users to register by providing a username, email, and password.
username
: (str
) The user's chosen username.email
: (str
) The user's email address.password
: (str
) The user's chosen password.
Example request:
{
"username": "newuser",
"email": "[email protected]",
"password": "password123"
}
JSON response of the created User object, 201.
Example response:
{
"id": 3,
"username": "newuser",
"email": "[email protected]",
"role": "User",
"date_created": "2024-03-22T10:00:00Z"
}
This endpoint is open and does not require a JWT token.
Authenticates a user by their email and password, returning a JWT token if successful.
email
: (str
) The user's email address.password
: (str
) The user's password.
Example request:
{
"email": "[email protected]",
"password": "password123"
}
JSON object containing the user's email, JWT token, and role, 201
Example Response:
{
"email": "[email protected]",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"role": "User"
}
This endpoint is protected and requires a valid JWT token. Only accessible by users with the "Admin" role.
Deletes a specific user from the system.
user_id
: URL parameter specifying the user's ID to be deleted.
Confirmation message of the deleted user, 201
Example response:
{
"message": "User 'newuser', 'User' deleted successfully"
}
Click here for Category Controller Endpoints
This endpoint is protected and requires a valid JWT token. Only users except those with the "Auditor" role can add categories.
Allows creating a new category that can be assigned to future transactions.
name
: (str
) The name of the category.description
: (str
, optional) A description of the category.
Example request:
{
"name": "Utilities",
"description": "Monthly bills for utilities"
}
JSON response of the created Category object, 201.
Example response:
{
"id": 1,
"name": "Utilities",
"description": "Monthly bills for utilities"
}
This endpoint is protected and requires a valid JWT token.
Retrieves a list of all categories available in the system.
JSON array of Category objects, 201
Example response:
[
{
"id": 1,
"name": "Utilities",
"description": "Monthly bills for utilities"
}
]
This endpoint is protected and requires a valid JWT token.
Retrieves information about a specific category by its ID.
category_id
: URL parameter specifying the category's ID.
JSON representation of the specified Category, 201
Example response:
{
"id": 1,
"name": "Utilities",
"description": "Monthly bills for utilities"
}
This endpoint is protected and requires a valid JWT token. Only an Admin can update a category once created.
Updates information about a specific category.
name
: (str
, optional) New name of the category.description
: (str
, optional) New description of the category.
{
"name": "Monthly Utilities",
"description": "Updated description for utilities"
}
JSON representation of the updated Category, 200.
Example response:
{
"id": 1,
"name": "Monthly Utilities",
"description": "Updated description for utilities"
}
This endpoint is protected and requires a valid JWT token. Only an Admin can delete a category.
Deletes a specific category from the system.
category_id
: URL parameter specifying the category's ID to be deleted.
Confirmation message of the deleted category.
Example response:
{
"message": "Category with id 1, Name: Utilities, and Description: Monthly bills for utilities deleted successfully"
}
Click here for Transaction Controller Endpoints
This endpoint is protected and requires a valid JWT token.
Allows adding a new transaction to a specific account. Users can add transactions only to their own accounts, except for admins who can add transactions to any account.
amount
: (int
) The transaction amount. A positive value for deposits, negative for withdrawals.description
: (str
, optional) A description of the transaction.
Example request:
{
"amount": -50.75,
"description": "Grocery shopping"
}
JSON response of the created Transaction object, 201.
Example response:
{
"id": 1,
"amount": "-50.75",
"description": "Grocery shopping",
"transaction_date": "2024-03-23T12:00:00Z",
"account_id": 1
}
This endpoint is protected and requires a valid JWT token. Only accessible by users with the "Admin" role.
Updates information about a specific transaction within a specific account.
amount
: (int
, optional) New amount of the transaction.description
: (str
, optional) New description of the transaction.
Example request:
{
"amount": -45.0,
"description": "Supermarket shopping"
}
JSON representation of the updated Transaction, 200.
Example response:
{
"id": 1,
"amount": "-45.00",
"description": "Supermarket shopping",
"transaction_date": "2024-03-23T12:00:00Z",
"account_id": 1
}
This endpoint is protected and requires a valid JWT token. Only accessible by users with the "Admin" role.
Deletes a specific transaction from a specific account.
Confirmation message of the deleted transaction.
Example response:
{
"message": "Transaction with id 1, Description: 'Supermarket shopping', Amount: -45.00 deleted successfully"
}
This endpoint is protected and requires a valid JWT token.
Searches transactions based on a description query. Auditors can see all transactions across all accounts, while other users can only see transactions within their own accounts.
query
: (str
) The search term to match against transaction descriptions. Example request:
{
"query": "shopping"
}
JSON array of Transaction objects that match the search term.
Example response:
[
{
"id": 1,
"account_id": 1,
"amount": "-45.00",
"description": "Supermarket shopping",
"transaction_date": "2024-03-23T12:00:00Z"
}
]