Adding the first routes.

Signed-off-by: Cliff Hill <xlorep@darkhelm.org>
This commit is contained in:
2025-08-23 21:47:53 -04:00
parent 442de8036a
commit a668f02b52
3 changed files with 34 additions and 0 deletions

View File

@@ -0,0 +1 @@
"""Dependencies for the Numinar coding project backend."""

View File

@@ -0,0 +1 @@
"""Routes for the Numinar coding project backend."""

View File

@@ -0,0 +1,32 @@
"""Routes for user-related operations in the Numinar coding project backend."""
from fastapi import APIRouter
from fastapi import HTTPException
from sqlalchemy.exc import NoResultFound
from backend.dependencies.db import SessionDep
from backend.schemas.users import UserResponse
from backend.services.users import get_user
from backend.services.users import get_users
router = APIRouter(prefix="/users", tags=["users"])
@router.get("/", response_model=list[UserResponse])
async def read_users(session: SessionDep):
"""Endpoint to retrieve all users."""
users = await get_users(session)
return users
@router.get("/{email}", response_model=UserResponse)
async def read_user(email: str, session: SessionDep):
"""Endpoint to retrieve a user by email."""
try:
user = await get_user(session, email)
except NoResultFound as e:
raise HTTPException(
status_code=404, detail=f"User with email {email} not found"
) from e
return user