This application is an Expense Tracker API built with Flask. It allows users to create, retrieve, and filter expenses. The API supports both JSON and CSV formats for data retrieval, making it versatile for various client needs.
To run the tests, you can use the following commands:
-
To run tests with MockDatabase (default):
poetry run pytest
-
To run tests with SQLite in-memory database:
poetry run pytest --database-type=sqlite
To run the application, use the following command:
poetry run python -m app.rest.api
- URL:
/expenses
- Method:
POST
- Data Params:
{ "amount": "50.00", "date": "2023-05-20", "category": "Food", "description": "Grocery shopping" }
- Success Response:
- Code: 201
- Content:
{ "id": 1, "amount": "50.00", "date": "2023-05-20", "category": "Food", "description": "Grocery shopping" }
- Error Response:
- Code: 400
- Content:
{"error": "Invalid data provided"}
- URL:
/expenses
- Method:
GET
- URL Params:
from_date
(optional): Start date for filtering (format: YYYY-MM-DD)to_date
(optional): End date for filtering (format: YYYY-MM-DD)category
(optional): Category to filter by
- Headers:
Content-Type
:application/json
(default) ortext/csv
- Success Response:
- Code: 200
- Content:
- JSON format (default):
[ { "amount": "50.00", "date": "2023-05-20", "category": "Food", "description": "Grocery shopping" }, { "amount": "30.00", "date": "2023-05-19", "category": "Transport", "description": "Bus ticket" } ]
- CSV format (when
Content-Type: text/csv
is specified):Amount,Date,Category,Description 50.00,2023-05-20,Food,Grocery shopping 30.00,2023-05-19,Transport,Bus ticket
- JSON format (default):
- Error Response:
- Code: 400
- Content:
{"error": "Invalid filter parameters"}
-
Create an expense:
curl -X POST http://localhost:5000/expenses -H "Content-Type: application/json" -d '{"amount": "50.00", "date": "2023-05-20", "category": "Food", "description": "Grocery shopping"}'
-
Retrieve expenses with JSON format:
curl http://localhost:5000/expenses
-
Retrieve expenses with CSV format:
curl http://localhost:5000/expenses -H "Accept: text/csv"