Merge pull request 'more moving of files' (#7) from another-refactor into main

Reviewed-on: #7
This commit is contained in:
Lucas Jensen
2024-07-06 17:57:32 +00:00
13 changed files with 40 additions and 79 deletions

View File

@@ -1,12 +1,8 @@
[mysql]
DB_USER=username DB_USER=username
DB_PASS=password DB_PASS=password
DB_NAME=portfolio DB_NAME=portfolio
DB_HOST=localhost DB_HOST=localhost
AUTH0_DOMAIN=domain.auth0.com [application]
AUTH0_API_AUDIENCE=https://audience.auth0.com/api/v2/ PORT=8080
AUTH0_ISSUER=https://issuer.auth0.com/
AUTH0_ALGORITHMS=RS256
CLIENT_SECRET=secret
CLIENT_ID=id

1
server/app/__init__.py Normal file
View File

@@ -0,0 +1 @@
from .main import app # noqa: F401

View File

@@ -3,8 +3,8 @@ from fastapi import FastAPI, HTTPException, status
from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles from fastapi.staticfiles import StaticFiles
from model import queries from app.model import queries
from types import About, Project, Lucas from app.types import About, Project, Lucas
load_dotenv() load_dotenv()
app = FastAPI() app = FastAPI()

View File

@@ -0,0 +1,31 @@
from app.utils.db import connect_db
from app.types import About, Project
def get_projects() -> list[Project]:
db = connect_db()
cursor = db.cursor(dictionary=True)
cursor.execute("SELECT * FROM projects")
data = cursor.fetchall()
projects = [Project(**p) for p in data] # type: ignore
db.close()
return projects
def get_project(project_id: int) -> Project | None:
db = connect_db()
cursor = db.cursor(dictionary=True)
cursor.execute("SELECT * FROM projects WHERE id=%s", (project_id,))
data = cursor.fetchone()
db.close()
return None if data is None else Project(**data) # type: ignore
def get_about() -> About:
db = connect_db()
cursor = db.cursor(dictionary=True)
cursor.execute("SELECT name, email, bio, github, gitea FROM self")
data = {key: val for key, val in cursor.fetchone().items()} # type: ignore
db.close()
return About(**data)

View File

@@ -1,6 +1,6 @@
from pydantic import BaseModel from pydantic import BaseModel
from about import About from .about import About
from project import Project from .project import Project
class Lucas(BaseModel): class Lucas(BaseModel):

View File

View File

@@ -1,67 +0,0 @@
from utils.db import connect_db
from models import About, Project
def get_projects() -> list[Project]:
db = connect_db()
cursor = db.cursor(dictionary=True)
cursor.execute("SELECT * FROM projects")
data = cursor.fetchall()
projects = [Project(**p) for p in data] # type: ignore
db.close()
return projects
def get_project(project_id: int) -> Project | None:
db = connect_db()
cursor = db.cursor(dictionary=True)
cursor.execute("SELECT * FROM projects WHERE id=%s", (project_id,))
data = cursor.fetchone()
db.close()
return None if data is None else Project(**data) # type: ignore
def create_project(project: Project) -> Project:
db = connect_db()
cursor = db.cursor(dictionary=True)
cursor.execute(
"INSERT INTO projects (name, description, source, live, is_self_hosted) VALUES (%s, %s, %s, %s, %s)",
(
project.name,
project.description,
project.source,
project.live,
project.is_self_hosted,
),
)
db.commit()
project.id = cursor.lastrowid
db.close()
return project
def delete_project(project_id: int) -> None:
db = connect_db()
cursor = db.cursor(dictionary=True)
cursor.execute("DELETE FROM projects WHERE id=%s", (project_id,))
db.commit()
db.close()
def get_about() -> About:
db = connect_db()
cursor = db.cursor(dictionary=True)
cursor.execute("SELECT name, email, bio, github, gitea FROM self")
data = {key: val for key, val in cursor.fetchone().items()} # type: ignore
db.close()
return About(**data)
def get_subs() -> dict[str, str]:
db = connect_db()
cursor = db.cursor(dictionary=True)
cursor.execute("SELECT auth0_sub, test_sub FROM self")
data = {key: val for key, val in cursor.fetchone().items()} # type: ignore
db.close()
return data

View File

@@ -2,7 +2,7 @@
import os import os
import uvicorn import uvicorn
from main import app from app import app
from dotenv import load_dotenv from dotenv import load_dotenv