This repository contains the backend code for the Capstone 2310 project Streaming On The Go, implemented in Python with Flask. It includes RESTful APIs, database models, and migrations necessary for the project's functionality. We used Pytest to test the routes and models.
Before you begin, ensure you have the following installed:
- Python 3.12 or higher
- PostgreSQL 14 or higher
- Git
Follow these steps to get your development environment set up:
-
Clone the Repository
git clone git@github.com:2310-combined/python-backend.git -
Setup Python Virtual Environment
python3 -m venv venv source venv/bin/activate python3 -m pip install --upgrade pip -
Install Dependencies
pip install -r requirements.txt -
Database Setup
After installing PostgreSQL, create a database for the project and update the
SQLALCHEMY_DATABASE_URIin your configuration to point to your database. (You may want to create a .env in the root directory to hide credentials) -
Run Migrations
flask db upgrade -
Run the Application
flask run
To run tests, ensure you have pytest installed:
pip install pytest
Then execute the tests using:
pytest
Here are some additional commands that may be useful during development:
-
Start Virtual Environment
python3 -m venv venv source venv/bin/activate python3 -m pip install --upgrade pip -
Install Flask-CORS
pip install flask-cors -
Initialize Database
flask db init -
Create a Migration
flask db migrate -m "custom message" -
Apply Migrations
flask db upgrade
Note: Endpoints examples use flask local host. Here are the endpoints you can use to access the database:
- Post User
POST http://127.0.0.1:5000/users
{
"email": "example@mails.com",
"first_name": "Joe",
"last_name": "Dude"
}
- Show User
GET http://127.0.0.1:5000/users/:id
- Index Users
GET http://127.0.0.1:5000/users
- Update User
PUT http://127.0.0.1:5000/users/:id
{
"email": "lambertones@gmail.com",
"first_name": "Nathan",
"last_name": "Laaaambert"
}
- Create Trip
POST http://127.0.0.1:5000/users/:id/trips
{
"start_location_latitude": "40.7128",
"start_location_longitude": "-74.006",
"end_location_latitude": "34.0522",
"end_location_longitude": "-118.2437",
"trip_duration": "2345234",
"time_of_trip": "2024-05-13T15:26:03Z",
"user_id": 1
}
- Index User's Trips
GET http://127.0.0.1:5000/users/:id/trips
- Delete Trip
DELETE http://127.0.0.1:5000/trips/:id
- Full Heroku Deployment
- Successful connection and database storage for FE application
If you have a recommendation for improvements, please feel free to make a pull request!
- Project concept by Jamie Francisco
- Technical direction, consultation, and moral support by Jeremiah Black, Khoa Nguyen and Megan McMahon
- This project completed by Mod 4 students at Turing School of Software and Design