This repository contains the backend API for a Donation Management System, providing endpoints to manage staff, donations, types of donations, and generate reports based on donation subtypes and donor activity.
- Staff registration/authentication and session management
- Create custom donation types and subtypes
- Registration and management of donors
- Recording and tracking of donations and distributions
- Report generation by type, donor, and subtype
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
To get a local copy up and running follow these steps:
- Clone the repository:
git clone https://github.com/colinpeng-datascience/donation-management.git
- Navigate to the project directory:
cd donation-management
- Install the project (editable mode recommended for development):
pip install -e .
- Set the Flask app environment variable:
export FLASK_APP=donman
- Create the
var
directory and touch the SQLite3 file:
mkdir var
touch var/donman.sqlite3
- Initialize the database:
flask db init
- Run the initial migration:
flask db migrate -m "Initial migration"
- Perform the migration and upgrade the database:
flask db upgrade
- Initialize the database with any necessary seed data:
flask init-db
- Run the Flask app with:
flask --app donman --debug run --host 0.0.0.0 --port 8000
A separate test script is provided to test the API endpoints. In a new terminal window, proceed to make the rest_test.sh
script executable and run the tests using the following commands:
chmod +x rest_test.sh
./rest_test.sh
(Make sure httpie is installed)
This will test all of the available API endpoints, including success and error cases.
POST /api/staff/login
: Authenticate a staff member and establish a session. Requires staff email and password.DELETE /api/staff/logout
: Terminate the current staff session.
POST /api/staff
: Registers a new staff member. Requires staff name, email, and password.GET /api/staff
: Retrieves a list of all staff members.DELETE /api/staff/<staff_id>
: Deletes a staff by ID, removing them from the system.
POST /api/type
: Registers a new donation type, specified by the type name.GET /api/type
: Retrieves a list of all donation types.
GET /api/type/sub
: Retrieves all donation subtypes associated with a specific type ID, passed as a query parameter.POST /api/type/sub
: Registers a new donation subtype associated with an existing donation type. Requires type ID and subtype name.
GET /api/donor
: Retrieves a list of all registered donors.POST /api/donor
: Registers a new donor. Requires donor name and email.
POST /api/donation
: Registers a new donation entry linked to a donor and subtype. Requires donor ID, donation quantity, and subtype ID.
POST /api/distribution
: Registers a new distribution entry. Requires subtype ID and the amount distributed.
GET /api/report/type/<type_id>
: Generates a report by type ID, showing totals of donated and distributed amounts, as well as the remaining amount.GET /api/report/subtype/<subtype_id>
: Generates a report for a specific subtype ID, including the total amounts donated and distributed.GET /api/report/donor/<donor_id>
: Generates a report summarizing donations made by a specific donor ID, broken down by type and subtype.
- Flask - The web framework used
- Flask-RESTful - Extension for Flask that adds support for quickly building REST APIs.
- Flask-SQLAlchemy - ORM and database management
- Flask-Migrate - Database schema migrations
- HTTPie - Command-line HTTP client
Colin Peng colinpeng-datascience
This project is licensed under the MIT License
Special thanks to:
- REST api tutorial by EECS 485 team at UMich
- Full Stack Flask + React tutorial by Sandyjtech