Skip to content

Commit

Permalink
Merge pull request #2 from mrpbennett/fe
Browse files Browse the repository at this point in the history
front end done
  • Loading branch information
mrpbennett authored Jan 2, 2024
2 parents 70c5688 + b449478 commit 7040ace
Show file tree
Hide file tree
Showing 11 changed files with 1,209 additions and 129 deletions.
41 changes: 20 additions & 21 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,33 @@ name: Python package

on:
push:
branches: [ "main" ]
branches: ['main']
pull_request:
branches: [ "main" ]
branches: ['main']

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11"]
python-version: ['3.9', '3.10', '3.11']

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
python -m pip install pipenv
if [ -f Pipfile ]; then pipenv install; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
23 changes: 18 additions & 5 deletions api.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
""" Data Retrieval and Serialization """

import json
import logging

import psycopg2
import tomli
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles

from caching import get_user_from_redis

Expand All @@ -13,11 +15,22 @@
format="%(asctime)s - %(levelname)s - line:%(lineno)d - %(message)s",
)

app = FastAPI()

with open("config.toml", "rb") as f:
c = tomli.load(f)

app = FastAPI()

app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

# Mount the Frontend
app.mount("/static", StaticFiles(directory="./static/dist"), name="static")


@app.get("/")
async def root():
Expand Down Expand Up @@ -76,9 +89,9 @@ async def get_user(user_id: str):
)
result = curs.fetchall()

return {"postgres_data": result}
return result

except psycopg2.Error as e:
return {"message": str(e)}
else:
return {"redis_data": redis}
return redis
2 changes: 1 addition & 1 deletion get_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def get_user_data() -> dict:
try:
# MAX requests is 100
response = requests.get(
f"https://random-data-api.com/api/v2/users?size=5&response_type=json"
f"https://random-data-api.com/api/v2/users?size=100&response_type=json"
)

response.raise_for_status()
Expand Down
Loading

0 comments on commit 7040ace

Please sign in to comment.