This repository contains a Flask application for managing superheroes and their powers. The application includes three main files: app.py
, models.py
, and seed.py
, all located inside the server
folder. The application uses an SQLite database named superheroes.db
.
Click the link below to visit the site.
Ensure you have Python installed on your system. You can download and install Python from python.org.
Verify the installation by running:
python --version
- Visual Studio Code, official website: VisualStudio.com
Copy and paste the below to the Terminal
git clone https://github.com/Moringa-SDF-PTO5/superheroes-nabil-nagib.git
After Cloning open VSCode, click Terminal and select New terminal and type:
cd server
Create and activate a virtual environment to manage dependencies:
Mac/Linux users;
python -m venv venv
source venv/bin/activate
Windows users:
python -m venv venv
venv\Scripts\activate
Install the required dependencies using pip:
pip install -r requirements.txt
Initialize the database and run migrations:
flask db init
flask db migrate -m "migration"
flask db upgrade
Seed the database with initial data:
python server/seed.py
Start the Flask application:
export FLASK_APP=server/app.py
python app.py
This file sets up the Flask application, configures the database, and defines the API routes. The routes include:
- GET /heroes: Returns a list of all heroes.
- GET /heroes/int:id: Returns details of a specific hero by ID.
- GET /powers: Returns a list of all powers.
- GET /powers/int:id: Returns details of a specific power by ID.
- PATCH /powers/int:id: Updates the description of a specific power.
- POST /hero_powers: Creates a new HeroPower.
This file defines the database models and their relationships:
- Hero: Represents a superhero with id, name, and super_name.
- Power: Represents a power with id, name, and description.
- HeroPower: Represents a relationship between Hero and Power with id, strength, hero_id, and power_id.
This file seeds the database with initial data for heroes, powers, and hero_powers. The file does the following:
- Clears the existing data.
- Adds predefined powers to the database.
- Adds predefined heroes to the database.
- Associates heroes with powers and strengths.
Copyright © 2024 Nabil Nagib
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.