WIP checkpoint: Scaffold FastAPI backend project structure
This commit is contained in:
@@ -13,7 +13,7 @@ from app.models.user import User
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
# ── Pydantic schemas ────────────────────────────────────────────────
|
||||
# ── Pydantic schemas ──────────────────────────────────────────────────────────
|
||||
|
||||
class UserCreate(BaseModel):
|
||||
username: str
|
||||
@@ -35,14 +35,17 @@ class UserUpdate(BaseModel):
|
||||
is_active: bool | None = None
|
||||
|
||||
|
||||
# ── Endpoints ────────────────────────────────────────────────────────
|
||||
# ── Endpoints ─────────────────────────────────────────────────────────────────
|
||||
|
||||
@router.post(
|
||||
"/",
|
||||
response_model=UserResponse,
|
||||
status_code=status.HTTP_201_CREATED,
|
||||
)
|
||||
async def create_user(user_in: UserCreate, db: Annotated[AsyncSession, Depends(get_db)]):
|
||||
async def create_user(
|
||||
user_in: UserCreate,
|
||||
db: Annotated[AsyncSession, Depends(get_db)],
|
||||
):
|
||||
"""Register a new user."""
|
||||
# Check uniqueness of username
|
||||
existing = await db.execute(select(User).where(User.username == user_in.username))
|
||||
@@ -54,8 +57,9 @@ async def create_user(user_in: UserCreate, db: Annotated[AsyncSession, Depends(g
|
||||
if existing.scalar_one_or_none():
|
||||
raise HTTPException(status_code=400, detail="Email already registered")
|
||||
|
||||
from app.routers.auth import hash_password
|
||||
hashed = hash_password(user_in.password)
|
||||
from app.routers.auth import _get_password_hash
|
||||
|
||||
hashed = _get_password_hash(user_in.password)
|
||||
|
||||
user = User(
|
||||
username=user_in.username,
|
||||
|
||||
Reference in New Issue
Block a user