Merge pull request 'more moving of files' (#7) from another-refactor into main
Reviewed-on: #7
This commit is contained in:
@@ -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
|
||||
|
||||
1
server/app/__init__.py
Normal file
1
server/app/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .main import app # noqa: F401
|
||||
@@ -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()
|
||||
31
server/app/model/queries.py
Normal file
31
server/app/model/queries.py
Normal 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)
|
||||
@@ -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):
|
||||
0
server/app/utils/__init__.py
Normal file
0
server/app/utils/__init__.py
Normal 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
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import os
|
||||
import uvicorn
|
||||
from main import app
|
||||
from app import app
|
||||
from dotenv import load_dotenv
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user