This project provides a books API that will allow users to add, retrieve, reserve and edit books on a database.
Before you begin, ensure you have the following installed:
- Python 3: Version 3.7 or newer is recommended. You can download it from python.org.
- pip: Python's package installer. It usually comes with Python installations.
- make: A build automation tool. Pre-installed on macOS/Linux. Windows users may need to install it (e.g., via Chocolatey or WSL).
- Docker
- Colima (for Mac/Linux users)
- mongosh (MongoDB shell client)
- (Optional) MongoDB Compass (GUI client)
This project uses a Makefile
to automate setup and common tasks.
-
Clone the repository:
git clone git@github.com:methods/S_BookAPIV.2.git cd S_BookAPIV.2
-
View available commands: To see a list of all available commands, run:
make help
This project requires MongoDB to be running locally. We recommend using Docker and Colima for a lightweight, consistent environment.
colima start
docker run --name mongodb -p 27017:27017 -d mongodb/mongodb-community-server:latest
docker ps
docker ps -a
Look for a container named mongodb with port 27017 exposed. You can also connect via mongosh or MongoDB Compass to confirm.
The Makefile
will create a local virtual environment (venv) and install all required Python packages. You only need to run this once.
make install
To perform a full database reset and populate it with initial data for development, run the main setup command:
make setup
This single command will clean the database and then populate it with books, users, and reservations, ensuring a consistent state for all developers.
For more granular control, you can use the individual commands below. For more details on what each script does, see Scripts Documentation
To use the API, you first need to populate the database with some initial data.
Command | Description |
---|---|
make setup | (Recommended) Resets the entire database and seeds all data. |
make clean-db | Deletes ALL books and reservations. Useful for starting fresh. |
make books | Populates the database with books from scripts/test_data/books.json. |
make reservations | Populates the database with reservations from scripts/test_data/reservations.json. |
make seed-users | Populates the database with users from scripts/test_data/sample_user_data.json. |
With the database seeded, you can now run the Flask application.
make run
The API will be available at http://127.0.0.1:5000.
Here are other common commands for development, testing, and maintenance.
This project uses pytest to run tests and coverage.py to measure code coverage. To run the test suite and see the coverage report:
make test
If old data is persisting, you can use an explicit
coverage erase
command to clean out the old data.
This project uses Pylint to check code quality and style.
To run the linter
make lint
To remove the virtual environment and all Python cache files (pycache, .coverage, etc.):
make clean
This is useful if you want to start with a fresh environment.
This project is licensed under the MIT License - see the LICENSE.md file for details.