diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..7d6e641 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,12 @@ +FROM mcr.microsoft.com/devcontainers/python:1-3-bookworm + +ENV PYTHONUNBUFFERED 1 + +# [Optional] If your requirements rarely change, uncomment this section to add them to the image. +# COPY requirements.txt /tmp/pip-tmp/ +# RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \ +# && rm -rf /tmp/pip-tmp + +# [Optional] Uncomment this section to install additional OS packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 292c1c7..c73d7a3 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,40 +1,28 @@ // For format details, see https://aka.ms/devcontainer.json. For config options, see the -// README at: https://github.com/devcontainers/templates/tree/main/src/go +// README at: https://github.com/devcontainers/templates/tree/main/src/postgres { - "name": "Game of Life Walkthrough", - // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile - "image": "mcr.microsoft.com/devcontainers/universal:latest", - - // Use 'forwardPorts' to make a list of ports inside the container available locally. - "forwardPorts": [ - 3000 - ], - - // Use 'postCreateCommand' to run commands after the container is created. - // "postCreateCommand": "" - - // Configure tool-specific properties. - "customizations": { - "codespaces": { - "openFiles": [ - "index.html", - "README.md" - ] - }, - "vscode": { - "extensions": [ - "GitHub.codespaces", - "GitHub.copilot", - "GitHub.copilot-chat", - "github.copilot-workspace", - "GitHub.remotehub", - "github.vscode-github-actions", - "GitHub.vscode-pull-request-github", - "ms-vscode.live-server" - ] - } - } - - // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. - // "remoteUser": "root" - } + "name": "Python 3 & PostgreSQL", + "dockerComposeFile": "docker-compose.yml", + "service": "app", + "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}", + "features": { + "ghcr.io/devcontainers/features/github-cli:1": {}, + "ghcr.io/devcontainers/features/node:1": {} + } + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // This can be used to network with other containers or the host. + // "forwardPorts": [5000, 5432], + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "pip install --user -r requirements.txt", + + // Configure tool-specific properties. + // "customizations": {}, + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} \ No newline at end of file diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..42dfa2a --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,35 @@ +version: '3.8' + +services: + app: + build: + context: .. + dockerfile: .devcontainer/Dockerfile + + volumes: + - ../..:/workspaces:cached + + # Overrides default command so things don't shut down after the process ends. + command: sleep infinity + + # Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function. + network_mode: service:db + + # Use "forwardPorts" in **devcontainer.json** to forward an app port locally. + # (Adding the "ports" property to this file will not forward from a Codespace.) + + db: + image: postgres:latest + restart: unless-stopped + volumes: + - postgres-data:/var/lib/postgresql/data + environment: + POSTGRES_USER: postgres + POSTGRES_DB: postgres + POSTGRES_PASSWORD: postgres + + # Add "forwardPorts": ["5432"] to **devcontainer.json** to forward PostgreSQL locally. + # (Adding the "ports" property to this file will not forward from a Codespace.) + +volumes: + postgres-data: \ No newline at end of file diff --git a/.gitignore b/.gitignore index 51e4ddf..1b51498 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,181 @@ -# Replace the .gitignore with the appropriate one from https://github.com/github/gitignore \ No newline at end of file +.vscode +# Bruno adds a dir to your vscode workspace +Planventure +__pycache__ +.DS_Store + +# Add the .gitignore from https://github.com/github/gitignore/blob/main/Python.gitignore +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# UV +# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +#uv.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/latest/usage/project/#working-with-version-control +.pdm.toml +.pdm-python +.pdm-build/ + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ + +# Ruff stuff: +.ruff_cache/ + +# PyPI configuration file +.pypirc \ No newline at end of file diff --git a/README.md b/README.md index 404aa9f..165606a 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,58 @@ -# 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 - [sign up for FREE](https://github.com) +- 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 + +## 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 + +## 📝 License + +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. \ No newline at end of file diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..c176aa9 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,31 @@ +# Security + +Thanks for helping make GitHub safe for everyone. + +GitHub takes the security of our software products and services seriously, including all of the open source code repositories managed through our GitHub organizations, such as [GitHub](https://github.com/GitHub). + +Even though [open source repositories are outside of the scope of our bug bounty program](https://bounty.github.com/index.html#scope) and therefore not eligible for bounty rewards, we will ensure that your finding gets passed along to the appropriate maintainers for remediation. + +## Reporting Security Issues + +If you believe you have found a security vulnerability in any GitHub-owned repository, please report it to us through coordinated disclosure. + +**Please do not report security vulnerabilities through public GitHub issues, discussions, or pull requests.** + +Instead, please send an email to opensource-security[@]github.com. + +Please include as much of the information listed below as you can to help us better understand and resolve the issue: + + * The type of issue (e.g., buffer overflow, SQL injection, or cross-site scripting) + * Full paths of source file(s) related to the manifestation of the issue + * The location of the affected source code (tag/branch/commit or direct URL) + * Any special configuration required to reproduce the issue + * Step-by-step instructions to reproduce the issue + * Proof-of-concept or exploit code (if possible) + * Impact of the issue, including how an attacker might exploit the issue + +This information will help us triage your report more quickly. + +## Policy + +See [GitHub's Safe Harbor Policy](https://docs.github.com/en/site-policy/security-policies/github-bug-bounty-program-legal-safe-harbor#1-safe-harbor-terms) \ No newline at end of file diff --git a/SUPPORT.md b/SUPPORT.md index 0726719..be056c0 100644 --- a/SUPPORT.md +++ b/SUPPORT.md @@ -1,20 +1,14 @@ -# TODO: The maintainer of this repo has not updated this file - # Support ## How to file issues and get help This project uses GitHub issues to track bugs and feature requests. Please search the existing issues before filing new issues to avoid duplicates. For new issues, file your bug or feature request as a new issue. -For help or questions about using this project, please **TODO:** REPO MAINTAINER TO INSERT INSTRUCTIONS ON HOW TO ENGAGE REPO OWNERS OR COMMUNITY FOR HELP. COULD BE A SLACK OR DISCORD OR OTHER CHANNEL FOR HELP. WHERE WILL YOU HELP PEOPLE? +For help or questions about using this project, please open a new issue. The maintainers and community will try to help you as best as they can. -**TODO: REPO MAINTAINERS** Please include one of the following statements file: +**PLANVENTURE** is not actively developed but is maintained by GitHub staff **AND THE COMMUNITY**. We will do our best to respond to support and community questions in a timely manner. -- **THIS PROJECT NAME** is under active development and maintained by GitHub staff **AND THE COMMUNITY**. We will do our best to respond to support, feature requests, and community questions in a timely manner. -- **THIS PROJECT NAME** is not actively developed but is maintained by GitHub staff **AND THE COMMUNITY**. We will do our best to respond to support and community questions in a timely manner. -- **THIS PROJECT NAME** is no longer supported or maintained by GitHub staff. We will not respond to support or community questions. -- **THIS PROJECT NAME** is archived and deprecated. As an unsupported project, feel free to fork. ## GitHub Support Policy diff --git a/docs/0-pre-requisites.md b/docs/0-pre-requisites.md deleted file mode 100644 index e0d51b4..0000000 --- a/docs/0-pre-requisites.md +++ /dev/null @@ -1,16 +0,0 @@ -# Pre-requisites - -| [← Back to README][walkthrough-previous] | [Next: Introduction →][walkthrough-next] | -|:-----------------------------------|------------------------------------------:| - -List all the pre-requisites needed for this walkthrough. This may include software, tools, accounts, etc. - -- Pre-requisite 1 -- Pre-requisite 2 -- Pre-requisite 3 - -| [← Back to README][walkthrough-previous] | [Next: Introduction →][walkthrough-next] | -|:-----------------------------------|------------------------------------------:| - -[walkthrough-previous]: ../README.md -[walkthrough-next]: 1-introduction.md diff --git a/docs/1-introduction.md b/docs/1-introduction.md deleted file mode 100644 index 66a07fe..0000000 --- a/docs/1-introduction.md +++ /dev/null @@ -1,16 +0,0 @@ -# Introduction - -| [← Back to Pre-requisites][walkthrough-previous] | [Next: Template →][walkthrough-next] | -|:-----------------------------------|------------------------------------------:| - -Provide an introduction to your walkthrough. Explain the purpose, goals, and any other relevant information. - -- Overview of the walkthrough -- Objectives -- Expected outcomes - -| [← Back to Pre-requisites][walkthrough-previous] | [Next: Template →][walkthrough-next] | -|:-----------------------------------|------------------------------------------:| - -[walkthrough-previous]: 0-pre-requisites.md -[walkthrough-next]: template.md diff --git a/docs/README.md b/docs/README.md deleted file mode 100644 index 36a21d1..0000000 --- a/docs/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# Table of Contents - -This folder contains the documentation for your walkthrough. Please update the individual pages to reflect the content of your walkthrough. - -## Pages - -1. [Pre-requisites](0-pre-requisites.md) -2. [Introduction](1-introduction.md) -3. [Template](template.md) - -Feel free to add more pages as needed. diff --git a/docs/images/README.md b/docs/images/README.md deleted file mode 100644 index 2fd76e4..0000000 --- a/docs/images/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Supporting Images - -Please upload your images to this folder for consistency. \ No newline at end of file diff --git a/docs/template.md b/docs/template.md deleted file mode 100644 index e68d394..0000000 --- a/docs/template.md +++ /dev/null @@ -1,24 +0,0 @@ -# Page Title - -| [← Back to Introduction][walkthrough-previous] | [Next: (Next Page) →][walkthrough-next] | -|:-----------------------------------|------------------------------------------:| - -Use this template to create new pages for your walkthrough. Replace the headings and content with your own. - -## Heading 1 - -Content for heading 1. - -## Heading 2 - -Content for heading 2. - -## Heading 3 - -Content for heading 3. - -| [← Back to Introduction][walkthrough-previous] | [Next: (Next Page) →][walkthrough-next] | -|:-----------------------------------|------------------------------------------:| - -[walkthrough-previous]: 1-introduction.md -[walkthrough-next]: (next-page).md diff --git a/index.html b/index.html deleted file mode 100644 index e69de29..0000000 diff --git a/planventure-api/.sample.env b/planventure-api/.sample.env new file mode 100644 index 0000000..53df029 --- /dev/null +++ b/planventure-api/.sample.env @@ -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 \ No newline at end of file diff --git a/planventure-api/PROMPTS.md b/planventure-api/PROMPTS.md new file mode 100644 index 0000000..60b4ee9 --- /dev/null +++ b/planventure-api/PROMPTS.md @@ -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": "user@example.com", + "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! \ No newline at end of file diff --git a/planventure-api/app.py b/planventure-api/app.py new file mode 100644 index 0000000..3f778d8 --- /dev/null +++ b/planventure-api/app.py @@ -0,0 +1,16 @@ +from flask import Flask, jsonify +from flask_cors import CORS + +app = Flask(__name__) +CORS(app) + +@app.route('/') +def home(): + return jsonify({"message": "Welcome to PlanVenture API"}) + +@app.route('/health') +def health_check(): + return jsonify({"status": "healthy"}) + +if __name__ == '__main__': + app.run(debug=True) diff --git a/planventure-api/requirements.txt b/planventure-api/requirements.txt new file mode 100644 index 0000000..11babe5 --- /dev/null +++ b/planventure-api/requirements.txt @@ -0,0 +1,5 @@ +# Core dependencies +flask==2.3.3 +flask-sqlalchemy==3.1.1 +flask-cors==4.0.0 +python-dotenv==1.0.0 \ No newline at end of file pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy