From 68dedbf1ec69bf8eaf999de03afc222942e8f45c Mon Sep 17 00:00:00 2001 From: Lucas Jensen Date: Sat, 6 Jul 2024 10:57:10 -0700 Subject: [PATCH] more moving of files --- server/.env.example | 10 ++-- server/app/__init__.py | 1 + server/{ => app}/main.py | 4 +- server/{utils => app/model}/__init__.py | 0 server/app/model/queries.py | 31 ++++++++++++ server/{ => app}/types/__init__.py | 0 server/{ => app}/types/about.py | 0 server/{ => app}/types/lucas.py | 4 +- server/{ => app}/types/project.py | 0 server/app/utils/__init__.py | 0 server/{ => app}/utils/db.py | 0 server/model/queries.py | 67 ------------------------- server/run.py | 2 +- 13 files changed, 40 insertions(+), 79 deletions(-) create mode 100644 server/app/__init__.py rename server/{ => app}/main.py (96%) rename server/{utils => app/model}/__init__.py (100%) create mode 100644 server/app/model/queries.py rename server/{ => app}/types/__init__.py (100%) rename server/{ => app}/types/about.py (100%) rename server/{ => app}/types/lucas.py (65%) rename server/{ => app}/types/project.py (100%) create mode 100644 server/app/utils/__init__.py rename server/{ => app}/utils/db.py (100%) delete mode 100644 server/model/queries.py diff --git a/server/.env.example b/server/.env.example index da0825b..96b789b 100644 --- a/server/.env.example +++ b/server/.env.example @@ -1,12 +1,8 @@ +[mysql] DB_USER=username DB_PASS=password DB_NAME=portfolio DB_HOST=localhost -AUTH0_DOMAIN=domain.auth0.com -AUTH0_API_AUDIENCE=https://audience.auth0.com/api/v2/ -AUTH0_ISSUER=https://issuer.auth0.com/ -AUTH0_ALGORITHMS=RS256 - -CLIENT_SECRET=secret -CLIENT_ID=id +[application] +PORT=8080 diff --git a/server/app/__init__.py b/server/app/__init__.py new file mode 100644 index 0000000..ee978aa --- /dev/null +++ b/server/app/__init__.py @@ -0,0 +1 @@ +from .main import app # noqa: F401 diff --git a/server/main.py b/server/app/main.py similarity index 96% rename from server/main.py rename to server/app/main.py index fe517d8..0922544 100644 --- a/server/main.py +++ b/server/app/main.py @@ -3,8 +3,8 @@ from fastapi import FastAPI, HTTPException, status from fastapi.middleware.cors import CORSMiddleware from fastapi.staticfiles import StaticFiles -from model import queries -from types import About, Project, Lucas +from app.model import queries +from app.types import About, Project, Lucas load_dotenv() app = FastAPI() diff --git a/server/utils/__init__.py b/server/app/model/__init__.py similarity index 100% rename from server/utils/__init__.py rename to server/app/model/__init__.py diff --git a/server/app/model/queries.py b/server/app/model/queries.py new file mode 100644 index 0000000..dac6972 --- /dev/null +++ b/server/app/model/queries.py @@ -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) diff --git a/server/types/__init__.py b/server/app/types/__init__.py similarity index 100% rename from server/types/__init__.py rename to server/app/types/__init__.py diff --git a/server/types/about.py b/server/app/types/about.py similarity index 100% rename from server/types/about.py rename to server/app/types/about.py diff --git a/server/types/lucas.py b/server/app/types/lucas.py similarity index 65% rename from server/types/lucas.py rename to server/app/types/lucas.py index a491eee..a334aa5 100644 --- a/server/types/lucas.py +++ b/server/app/types/lucas.py @@ -1,6 +1,6 @@ from pydantic import BaseModel -from about import About -from project import Project +from .about import About +from .project import Project class Lucas(BaseModel): diff --git a/server/types/project.py b/server/app/types/project.py similarity index 100% rename from server/types/project.py rename to server/app/types/project.py diff --git a/server/app/utils/__init__.py b/server/app/utils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/server/utils/db.py b/server/app/utils/db.py similarity index 100% rename from server/utils/db.py rename to server/app/utils/db.py diff --git a/server/model/queries.py b/server/model/queries.py deleted file mode 100644 index b580fef..0000000 --- a/server/model/queries.py +++ /dev/null @@ -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 diff --git a/server/run.py b/server/run.py index bb25949..b2e88b2 100755 --- a/server/run.py +++ b/server/run.py @@ -2,7 +2,7 @@ import os import uvicorn -from main import app +from app import app from dotenv import load_dotenv