more moving of files

This commit is contained in:
Lucas Jensen
2024-07-06 10:57:10 -07:00
parent 50d0e8cdd6
commit 68dedbf1ec
13 changed files with 40 additions and 79 deletions

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)