Skip to content
Open
Show file tree
Hide file tree
Changes from 29 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
40 changes: 0 additions & 40 deletions .devcontainer/devcontainer.json

This file was deleted.

5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
# Replace the .gitignore with the appropriate one from https://github.com/github/gitignore
.vscode
# Bruno adds a dir to your vscode workspace
Planventure
venv/
69 changes: 59 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,62 @@
# Walkthrough Template
# Planventure API 🚁

This repository serves as a template for creating a walkthrough. Follow the steps below to get started.
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/github-samples/planventure)

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

1. Clone this repository.
2. Update the documentation in the `docs` folder (including the `README.md` folder).
3. Customize the code and other content as needed.
4. Update the `SUPPORT.md` file with the appropriate information.
5. Review the default LICENSE (MIT), CODE_OF_CONDUCT, and CONTRIBUTING files to ensure they meet your needs. These use the samples provided as part of the OSPO release process.
6. Update the `README.md` file in the repository root with the appropriate information. You can find an example at [github-samples/game-of-life-walkthrough](https://github.com/github-samples/game-of-life-walkthrough).
7. When you are ready to publish the repository, please make sure that the Git history is clean. Then, raise an issue for a 'sample release' at [https://github.com/github/open-source-releases](https://github.com/github/open-source-releases).
## Prerequisites
Before you begin, ensure you have the following:

- A GitHub account
- Access to GitHub Copilot - [sign up for FREE](https://gh.io/gfb-copilot)!
- A Code Editor
- API Client (like [Bruno](https://github.com/usebruno/bruno))
- Git - [Download & Install Git](https://git-scm.com/downloads)

## 🚀 Getting Started

## 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. 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
```

## Docker Setup

If bulding locally, follow the Docker setup steps in the [DockerSetup](DockerSetup) file.

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

## 📝 License

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": "user@example.com",
"password": "secure_password"
}
```

- `POST /auth/login` - Login and get JWT token
```json
\{
"email": "user@example.com",
"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