Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 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
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
b326cdb
Add initial client setup with routing, authentication context, and ba…
LadyKerr Feb 19, 2025
ff584d6
Remove padding from #root in App.css
LadyKerr Feb 26, 2025
33fd9d7
Remove padding from root container in App.css for improved layout
LadyKerr Feb 26, 2025
a47fd4e
Add @mui/icons-material dependency
LadyKerr Feb 26, 2025
336bbd4
Add login functionality with LoginPage, LoginForm, and AuthLayout; up…
LadyKerr Feb 27, 2025
2cf908c
Add signup functionality with SignupForm and SignupPage; update Navba…
LadyKerr Feb 27, 2025
0ea3468
Refactor authentication flow to use API service for login and signup;…
LadyKerr Feb 27, 2025
ab33767
Implement dashboard layout and routing; enhance login handling and er…
LadyKerr Feb 28, 2025
ba905d6
Replace ListItem with ListItemButton in DashboardLayout for improved …
LadyKerr Feb 28, 2025
e52b1d4
Add TripCard and TripList components for trip management; implement l…
LadyKerr Feb 28, 2025
9c77e3c
Add NewTripForm and NewTripPage components; implement trip creation f…
LadyKerr Feb 28, 2025
891493a
Add TripDetailsPage component; implement trip details fetching and ro…
LadyKerr Feb 28, 2025
cb3ecad
Remove Expenses and Notes tabs from TripDetailsPage for simplified na…
LadyKerr Feb 28, 2025
a68d7cf
Add EditTripPage and itinerary components; implement trip editing and…
LadyKerr Feb 28, 2025
019288f
Add EmptyOverviewSection, AccommodationCard, and TransportationCard c…
LadyKerr Feb 28, 2025
43ef22b
Enhance authentication flow: add success message to LoginForm, pre-fi…
LadyKerr Feb 28, 2025
453d3e1
Update DashboardLayout styles: adjust drawer height and margin to acc…
LadyKerr Mar 1, 2025
b58f3f1
Update database file: apply schema changes and data updates
LadyKerr Mar 25, 2025
1d0f72c
Added pytest
GeekTrainer Mar 27, 2025
609b671
Add username validation function and corresponding tests
GeekTrainer Mar 27, 2025
b9c49cf
Merge pull request #10 from github-samples/geektrainer/testing
LadyKerr Apr 21, 2025
214a03c
Add Docker configuration and update README for local development setup
LadyKerr Apr 24, 2025
94e4d80
Merge branch 'client-complete' into client-start
LadyKerr Apr 24, 2025
a20a199
Merge pull request #7 from github-samples/client-start
LadyKerr Apr 24, 2025
6ce2a9f
Merge branch 'main' into client-complete
LadyKerr Apr 24, 2025
e7c600d
Merge branch 'client-complete' of github.com:github-samples/planventu…
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
126 changes: 111 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,124 @@
# Build with Me + GitHub Copilot 🚀
# Planventure API Server 🚀

You can build along with me in this [Youtube video]() or read this [blog post]().
A Flask backend API that powers the Planventure travel planning application. This guide will help you quickly get the server running so you can focus on building the client application.

![Build with Me + GitHub Copilot on Youtube](link-to-image)
![Build with Me + GitHub Copilot on the Blog](link-to-image)
## Quick Start

# Planventure API 🚁
A Flask-based REST API backend for the Planventure application.
1. Fork and clone the repository:
```sh
git clone https://github.com/yourusername/planventure.git
cd planventure/planventure-api
```

2. Set up Python environment and install dependencies:
```sh
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
```

3. Start the development server:
```sh
flask run
```

The API server will be running at `http://localhost:5000`

That's it! You can now proceed to set up and work on the client application.

## API Health Check

Verify the server is running:
```sh
curl http://localhost:5000/health
```

Expected response: `{"status": "healthy"}`

# Planventure Client ✈️

[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/github-samples/planventure)

A React-based travel planning application that helps you organize your trips, manage itineraries, and keep track of travel details.

## Features

- 🗺️ Trip Planning & Management
- 📅 Interactive Itinerary Builder
- 🏨 Accommodation Tracking
- 🚗 Transportation Management
- 📱 Responsive Design
- 🔐 Secure Authentication

## Prerequisites
Before you begin, ensure you have the following:

- A GitHub account - [sign up for FREE](https://github.com)
Before you begin, ensure you have the following:
- Node.js (v16 or higher)
- npm or yarn
- A GitHub account
- Access to GitHub Copilot - [sign up for FREE](https://gh.io/gfb-copilot)!
- A Code Editor - [VS Code](https://code.visualstudio.com/download) is recommended
- API Client (like [Bruno](https://github.com/usebruno/bruno))
- Git - [Download & Install Git](https://git-scm.com/downloads)

## 🚀 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.
### Quick Start with Codespaces

1. Click the "Open in GitHub Codespaces" button above
2. Wait for the environment to build
3. Run `npm install` and `npm run dev`

### Local Development Setup

1. Open a new terminal window and cd into the `planventure-client` directory:
```sh
cd planventure/planventure-client
```

2. Install dependencies:
```sh
npm install
```

3. Create a `.env` file:
```sh
VITE_API_URL=http://localhost:5000
```

4. Start the development server:
```sh
npm run dev
```

Visit `http://localhost:5173` to see the application.

## 🏗️ Tech Stack

- React
- Material-UI
- React Router
- Day.js
- Vite

## 📱 Features Overview

### Trip Management
- Create and manage trips
- Set destinations and dates
- Track accommodations and transportation

### Itinerary Planning
- Day-by-day planning
- Activity scheduling
- Time management

## 🤝 Contributing

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request

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/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
venv/
.env
__pycache__/
*.pyc
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




80 changes: 80 additions & 0 deletions planventure-api/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
from flask import Flask, jsonify
from flask_cors import CORS
from flask_sqlalchemy import SQLAlchemy
from flask_jwt_extended import JWTManager
from os import environ
from dotenv import load_dotenv
from datetime import timedelta
from config import Config

# Load environment variables
load_dotenv()

# Initialize SQLAlchemy
db = SQLAlchemy()

def create_app():
app = Flask(__name__)

# Configure CORS
CORS(app,
resources={r"/*": {
"origins": Config.CORS_ORIGINS,
"methods": Config.CORS_METHODS,
"allow_headers": Config.CORS_HEADERS,
"supports_credentials": Config.CORS_SUPPORTS_CREDENTIALS
}})

# JWT Configuration
app.config['JWT_SECRET_KEY'] = environ.get('JWT_SECRET_KEY', 'your-secret-key')
app.config['JWT_ACCESS_TOKEN_EXPIRES'] = timedelta(hours=1)
jwt = JWTManager(app)

@jwt.expired_token_loader
def expired_token_callback(jwt_header, jwt_data):
return jsonify({
'error': 'Token has expired',
'code': 'token_expired'
}), 401

@jwt.invalid_token_loader
def invalid_token_callback(error):
return jsonify({
'error': 'Invalid token',
'code': 'invalid_token'
}), 401

@jwt.unauthorized_loader
def missing_token_callback(error):
return jsonify({
'error': 'Authorization token is missing',
'code': 'authorization_required'
}), 401

# Database configuration
app.config['SQLALCHEMY_DATABASE_URI'] = environ.get('DATABASE_URL', 'sqlite:///planventure.db')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

# Initialize extensions
db.init_app(app)

# Register blueprints
from routes.auth import auth_bp
from routes.trips import trips_bp
app.register_blueprint(auth_bp, url_prefix='/auth')
app.register_blueprint(trips_bp, url_prefix='/api')

# Register routes
@app.route('/')
def home():
return jsonify({"message": "Welcome to PlanVenture API"})

@app.route('/health')
def health_check():
return jsonify({"status": "healthy"})

return app

if __name__ == '__main__':
app = create_app()
app.run(debug=True)
28 changes: 28 additions & 0 deletions planventure-api/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from os import environ
from dotenv import load_dotenv

load_dotenv()

class Config:
# CORS Settings
CORS_ORIGINS = environ.get(
'CORS_ORIGINS',
'http://localhost:3000,http://localhost:5173'
).split(',')

CORS_HEADERS = [
'Content-Type',
'Authorization',
'Access-Control-Allow-Credentials'
]

CORS_METHODS = [
'GET',
'POST',
'PUT',
'DELETE',
'OPTIONS'
]

# Cookie Settings
CORS_SUPPORTS_CREDENTIALS = True
12 changes: 12 additions & 0 deletions planventure-api/init_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from app import create_app, db
from models import User

def init_db():
app = create_app()
with app.app_context():
# Create all database tables
db.create_all()
print("Database tables created successfully!")

if __name__ == '__main__':
init_db()
Binary file added planventure-api/instance/planventure.db
Binary file not shown.
21 changes: 21 additions & 0 deletions planventure-api/middleware/auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from functools import wraps
from flask import jsonify
from flask_jwt_extended import verify_jwt_in_request, get_jwt_identity
from models import User

def auth_middleware(f):
@wraps(f)
def decorated(*args, **kwargs):
try:
verify_jwt_in_request()
current_user_id = get_jwt_identity()

# Check if user still exists in database
user = User.query.get(current_user_id)
if not user:
return jsonify({"error": "User not found"}), 401

return f(*args, **kwargs)
except Exception as e:
return jsonify({"error": "Invalid or expired token"}), 401
return decorated
4 changes: 4 additions & 0 deletions planventure-api/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .user import User
from .trip import Trip

__all__ = ['User', 'Trip']
22 changes: 22 additions & 0 deletions planventure-api/models/trip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from datetime import datetime, timezone
from app import db

class Trip(db.Model):
__tablename__ = 'trips'

id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
destination = db.Column(db.String(200), nullable=False)
start_date = db.Column(db.DateTime, nullable=False)
end_date = db.Column(db.DateTime, nullable=False)
latitude = db.Column(db.Float)
longitude = db.Column(db.Float)
itinerary = db.Column(db.JSON)
created_at = db.Column(db.DateTime, default=lambda: datetime.now(timezone.utc))
updated_at = db.Column(db.DateTime, default=lambda: datetime.now(timezone.utc), onupdate=lambda: datetime.now(timezone.utc))

# Relationship
user = db.relationship('User', back_populates='trips')

def __repr__(self):
return f'<Trip {self.destination} ({self.start_date} - {self.end_date})>'
Loading