mirror of
https://github.com/escalante29/healthy-fit.git
synced 2026-03-21 12:28:46 +01:00
- Supplement tracking: CRUD endpoints, /today, /logs, Supplements page - Kettlebell workouts: session tracking, analytics endpoint, ActiveSession page - Calendar module: events CRUD, calendar components - Push notifications: VAPID keys, PushSubscription model, APScheduler reminders, service worker with push/notificationclick handlers, Profile notifications UI - PWA: vite-plugin-pwa, manifest, icons, service worker generation - Frontend: TypeScript types, API modules, ConfirmModal, toast notifications - Auth fixes: password hashing, nutrition endpoint auth - CLAUDE.md: project documentation and development guide Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
69 lines
1.7 KiB
Python
69 lines
1.7 KiB
Python
from typing import Any
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException
|
|
from sqlmodel import Session, select
|
|
|
|
from app.api import deps
|
|
from app.core import security
|
|
from app.models.user import User
|
|
from app.schemas.user import UserCreate, UserRead, UserUpdate
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.post("/", response_model=UserRead)
|
|
def create_user(
|
|
*,
|
|
session: Session = Depends(deps.get_session),
|
|
user_in: UserCreate,
|
|
) -> Any:
|
|
"""
|
|
Create new user.
|
|
"""
|
|
user = session.exec(select(User).where(User.email == user_in.email)).first()
|
|
if user:
|
|
raise HTTPException(
|
|
status_code=400,
|
|
detail="The user with this email already exists in the system",
|
|
)
|
|
|
|
user = User(
|
|
email=user_in.email,
|
|
username=user_in.username,
|
|
password_hash=security.get_password_hash(user_in.password),
|
|
)
|
|
session.add(user)
|
|
session.commit()
|
|
session.refresh(user)
|
|
return user
|
|
|
|
|
|
@router.get("/me", response_model=UserRead)
|
|
def read_user_me(
|
|
current_user: deps.CurrentUser,
|
|
) -> Any:
|
|
"""
|
|
Get current user.
|
|
"""
|
|
return current_user
|
|
|
|
|
|
@router.put("/me", response_model=UserRead)
|
|
def update_user_me(
|
|
*,
|
|
session: Session = Depends(deps.get_session),
|
|
user_in: UserUpdate,
|
|
current_user: deps.CurrentUser,
|
|
) -> Any:
|
|
"""
|
|
Update own user.
|
|
"""
|
|
user_data = user_in.model_dump(exclude_unset=True)
|
|
if "password" in user_data:
|
|
user_data["password_hash"] = security.get_password_hash(user_data.pop("password"))
|
|
current_user.sqlmodel_update(user_data)
|
|
session.add(current_user)
|
|
session.commit()
|
|
session.refresh(current_user)
|
|
return current_user
|