Skip to content

methods/S_BookAPIV.2

 
 

Repository files navigation

S_BookAPIV.2

Project Overview

This project provides a books API that will allow users to add, retrieve, reserve and edit books on a database.

Prerequisites

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)

Getting Started: A Step-by-Step Guide

Step 1: Clone the Repository

This project uses a Makefile to automate setup and common tasks.

  1. Clone the repository:

    git clone git@github.com:methods/S_BookAPIV.2.git
    cd S_BookAPIV.2
  2. View available commands: To see a list of all available commands, run:

    make help

Step 2: Set Up and Run MongoDB

This project requires MongoDB to be running locally. We recommend using Docker and Colima for a lightweight, consistent environment.

1: Start Colima

colima start

2: Run the MongoDB Container: (This will pull the image if it's not already local)

docker run --name mongodb -p 27017:27017 -d mongodb/mongodb-community-server:latest

3: Verify MongoDB is Running

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.

Step 3: Install Project Dependencies

The Makefile will create a local virtual environment (venv) and install all required Python packages. You only need to run this once.

make install

Step 4: Set Up the Database

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.

Step 5: Run the API

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.


Development Tasks

Here are other common commands for development, testing, and maintenance.

Testing and Coverage

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.

Code Quality (Linting)

This project uses Pylint to check code quality and style.

To run the linter

make lint

Clean the Project

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.

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 97.6%
  • Makefile 1.9%
  • Shell 0.5%