working auth + users systems
This commit is contained in:
30
backend/modules/admin/api.py
Normal file
30
backend/modules/admin/api.py
Normal file
@@ -0,0 +1,30 @@
|
||||
# modules/admin/api.py
|
||||
from typing import Annotated
|
||||
from fastapi import APIRouter, Depends
|
||||
from sqlalchemy.orm import Session
|
||||
from core.database import Base, get_db
|
||||
from modules.auth.models import User, UserRole
|
||||
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.get("/")
|
||||
def read_admin():
|
||||
return {"message": "Admin route"}
|
||||
|
||||
@router.get("/cleardb")
|
||||
def clear_db(db: Annotated[Session, Depends(get_db)]):
|
||||
"""
|
||||
Clear the database.
|
||||
"""
|
||||
tables = Base.metadata.tables.keys()
|
||||
for table in tables:
|
||||
# delete all tables that isn't the users table
|
||||
if table != "users":
|
||||
table = Base.metadata.tables[table]
|
||||
db.execute(table.delete())
|
||||
|
||||
# delete all non-admin accounts
|
||||
db.query(User).filter(User.role != UserRole.ADMIN).delete()
|
||||
db.commit()
|
||||
return {"message": "Database cleared"}
|
||||
Reference in New Issue
Block a user