Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
2c5a9c2
Set up Planventure API with Docker and Flask
LadyKerr Feb 6, 2025
ad04f34
Add Docker setup and API documentation for Planventure project
LadyKerr Feb 6, 2025
e220d13
Update README.md ✈️
LadyKerr Feb 6, 2025
df0c7d1
Enhance development environment with updated devcontainer configurati…
LadyKerr Feb 6, 2025
6c87b95
setting up
LadyKerr Feb 10, 2025
f1f68ad
Remove sample environment configuration file from planventure-api
LadyKerr Feb 12, 2025
ad90069
starter reqs txt
LadyKerr Feb 12, 2025
24c09b5
Refactor Planventure API to integrate SQLAlchemy for database managem…
LadyKerr Feb 12, 2025
e23b917
Implement JWT authentication and user registration/login endpoints in…
LadyKerr Feb 13, 2025
43eb5d3
Add CORS and JWT configuration, implement trip management routes, and…
LadyKerr Feb 13, 2025
a3e4ca1
Add README.md for Planventure API with features, tech stack, and API …
LadyKerr Feb 13, 2025
6089195
Add initial Planventure API setup with Flask and update README
LadyKerr Feb 14, 2025
4c062b7
Update README to include branch switch instructions for local develop…
LadyKerr Feb 14, 2025
ceec435
Add CORS support for trip management routes and handle preflight OPTI…
LadyKerr Feb 19, 2025
8ddbce3
Fix import statement for configuration in trip management routes
LadyKerr Feb 19, 2025
0e51264
Update database schemA
LadyKerr Feb 19, 2025
e9e1fa2
Update container files
GeekTrainer Feb 21, 2025
b896415
Merge pull request #8 from github-samples/update-container
LadyKerr Apr 21, 2025
f7c30a0
Update .gitignore, README, SECURITY, and SUPPORT files; remove obsole…
LadyKerr Apr 21, 2025
46a72ee
Set up development environment with Docker, Docker Compose, and Postg…
LadyKerr Apr 21, 2025
f24d4b7
Update dependabot configuration to monitor pip dependencies in the pl…
LadyKerr Apr 21, 2025
15e517d
Merge branch 'api-start' into api-complete
LadyKerr Apr 24, 2025
108e896
Merge branch 'main' into api-complete
LadyKerr Apr 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 41 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# Build with Me + GitHub Copilot 🚀

You can build along with me in this [Youtube video]() or read this [blog post]().
# Planventure API 🚁

![Build with Me + GitHub Copilot on Youtube](link-to-image)
![Build with Me + GitHub Copilot on the Blog](link-to-image)
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/github-samples/planventure)

# Planventure API 🚁
A Flask-based REST API backend for the Planventure application.

## Prerequisites
Expand All @@ -19,10 +15,44 @@ Before you begin, ensure you have the following:

## 🚀 Getting Started

1. Fork this repository to your GitHub account.
2. Switch to the `api-start` branch.
3. Clone the repository to your local machine.
## Build along in a Codespace

1. Click the "Open in GitHub Codespaces" button above to start developing in a GitHub Codespace.

### Local Development Setup

If you prefer to develop locally, follow the steps below:

1.Fork and clone the repository and navigate to the [planventue-api](/planventure-api/) directory:
```sh
cd planventure-api
```

2. Create a virtual environment and activate it:
```sh
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
```

3. Install the required dependencies:
```sh
pip install -r requirements.txt
```

4. Create an `.env` file based on [.sample.env](/planventure-api/.sample.env):
```sh
cp .sample.env .env
```

5. Start the Flask development server:
```sh
flask run
```

## 📚 API Endpoints
- GET / - Welcome message
- GET /health - Health check endpoint

You can find next steps in the README on the `api-start` branch.
## 📝 License

Happy Coding! 🎉
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
Empty file removed index.html
Empty file.
8 changes: 8 additions & 0 deletions planventure-api/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# CORS Settings
CORS_ORIGINS=http://localhost:3000,http://localhost:5173

# JWT Settings
JWT_SECRET_KEY=your-secret-key-here

# Database Settings
DATABASE_URL=sqlite:///planventure.db
4 changes: 4 additions & 0 deletions planventure-api/.sample.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SECRET_KEY=your-secret-key-here
JWT_SECRET_KEY=your-jwt-secret-key-here
DATABASE_URL=your-sqldatabase-url-here
CORS_ORIGINS=your-cors-origins-here-host-hopefully-localhost:3000
252 changes: 252 additions & 0 deletions planventure-api/PROMPTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
# Building the Planventure API with GitHub Copilot

This guide will walk you through creating a Flask-based REST API with SQLAlchemy and JWT authentication using GitHub Copilot to accelerate development.

## Prerequisites

- Python 3.8 or higher
- VS Code with GitHub Copilot extension
- Bruno API Client (for testing API endpoints)
- Git installed

## Project Structure

We'll be working in the `api-start` branch and creating a structured API with:
- Authentication system
- Database models
- CRUD operations for trips
- JWT token protection

## Step 1: Project Setup
### Prompts to Configure Flask with SQLAlchemy

Open Copilot Chat and type:
```
@workspace Update the Flask app with SQLAlchemy and basic configurations
```

When the code is generated, click "Apply in editor" to update your `app.py` file.

### Update Dependencies

In Copilot Chat, type:
```
update requirements.txt with necessary packages for Flask API with SQLAlchemy and JWT
```

Install the updated dependencies:
```bash
pip install -r requirements.txt
```

### Create .env File

Create a `.env` file for environment variables and add it to `.gitignore`.

## Step 2: Database Models

### User Model

In Copilot Edits, type:
```
Create SQLAlchemy User model with email, password_hash, and timestamps. add code in new files
```

Review and accept the generated code.

### Initialize Database Tables

Ask Copilot to create a database initialization script:
```
update code to be able to create the db tables with a python shell script
```

Run the initialization script:
```bash
python init_db.py
```

### Install SQLite Viewer Extension

1. Go to VS Code extensions
2. Search for "SQLite viewer"
3. Install the extension
4. Click on `init_db.py` to view the created tables

### Trip Model

In Copilot Edits, type:
```
Create SQLAlchemy Trip model with user relationship, destination, start date, end date, coordinates and itinerary
```

Accept changes and run the initialization script again:
```bash
python3 init_db.py
```

### Commit Your Changes

Use Source Control in VS Code:
1. Stage all changes
2. Click the sparkle icon to generate a commit message with Copilot
3. Click commit

## Step 3: Authentication System

### Password Hashing Utilities

In Copilot Edits, type:
```
Create password hashing and salt utility functions for the User model
```

Review, accept changes, and install required packages:
```bash
pip install bcrypt
```

### JWT Token Functions

In Copilot Edits, type:
```
Setup JWT token generation and validation functions
```

Review, accept changes, and install the JWT package:
```bash
pip install flask-jwt-extended
```

### Registration Route

In Copilot Edits, type:
```
Create auth routes for user registration with email validation
```

Review and accept the changes.

### Test Registration Route

Use Bruno API Client:
1. Create a new POST request
2. Set URL to `http://localhost:5000/auth/register`
3. Add header: `Content-Type: application/json`
4. Add JSON body:
```json
{
"email": "[email protected]",
"password": "test1234"
}
```
5. Send the request and verify the response

### Login Route

In Copilot Edits, type:
```
Create login route with JWT token generation
```

Review, accept changes, and restart the Flask server.

### Enable Development Mode

To have Flask automatically reload on code changes:

```bash
export FLASK_DEBUG=1
flask run
```

### Authentication Middleware

In Copilot Edits, type:
```
Create auth middleware to protect routes
```

Review and accept the changes.

### Commit Your Changes

Use Source Control and Copilot to create a commit message.

## Step 4: Trip Routes

### Create Trip Routes Blueprint

In Copilot Edits, type:
```
Create Trip routes blueprint with CRUD operations
```

Review and accept the changes.

> **Note**: Ensure that `verify_jwt_in_request` is set to `verify_jwt_in_request(optional=True)` if needed

### Test Trip Routes

Use Bruno API Client to test:
1. CREATE a new trip
2. GET a trip by ID

### Add Itinerary Template Generator

In Copilot Edits, type:
```
Create function to generate default itinerary template
```

Review, accept changes, and test the updated route.

## Step 5: Finalize API

### Configure CORS for Frontend Access

In Copilot Edits, type:
```
Setup CORS configuration for React frontend
```

Review and accept the changes.

### Add Health Check Endpoint

In Copilot Edits, type:
```
Create basic health check endpoint
```

Review and accept the changes.

### Commit Final Changes

Use Source Control with Copilot to create your final commit.

### Create README

Ask Copilot to write a comprehensive README for your API project.

## Common Issues and Solutions

### GOTCHAS:

- Ensure there are no trailing slashes in any of the routes - especially the base `/trip` route
- Make sure all required packages are installed
- Check that JWT token validation is configured correctly
- Verify database tables are created properly using the SQLite viewer

## Next Steps

Consider these enhancements for your API:
- Add more comprehensive input validation
- Create custom error handlers for HTTP exceptions
- Setup logging configuration
- Add validation error handlers for form data
- Configure database migrations

## Conclusion

You now have a fully functional API with authentication, database models, and protected routes. This can serve as the backend for your Planventure application!
62 changes: 62 additions & 0 deletions planventure-api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Planventure API 🌍✈️

A Flask-based REST API for managing travel itineraries and trip planning.

## Features

- 🔐 User Authentication (JWT-based)
- 🗺️ Trip Management
- 📅 Itinerary Planning
- 🔒 Secure Password Hashing
- ⚡ CORS Support

## Tech Stack

- Python 3.x
- Flask
- SQLAlchemy
- Flask-JWT-Extended
- SQLite Database
- BCrypt for password hashing

## API Endpoints

### Authentication

- `POST /auth/register` - Register a new user
```json
{
"email": "[email protected]",
"password": "secure_password"
}
```

- `POST /auth/login` - Login and get JWT token
```json
\{
"email": "[email protected]",
"password": "secure_password"
}
```

### Trips

- `GET /trips` - Get all trips
- `POST /trips` - Create a new trip
```json
{
"destination": "Paris, France",
"start_date": "2024-06-15T00:00:00Z",
"end_date": "2024-06-22T00:00:00Z",
"latitude": 48.8566,
"longitude": 2.3522,
"itinerary": {}
}
```
- `GET /trips/<trip_id>` - Get a single trip
- `PUT /trips/<trip_id>` - Update a trip
- `DELETE /trips/<trip_id>` - Delete a trip




Loading