[V1.0] Working application, added notifications.

Ready to upload to store.
This commit is contained in:
c-d-p
2025-04-27 00:39:52 +02:00
parent 04d9136b96
commit 62d6b8bdfd
86 changed files with 2250 additions and 240 deletions

View File

@@ -1,6 +1,7 @@
from typing import Annotated
from fastapi import APIRouter, Depends
from typing import Annotated, Optional
from fastapi import APIRouter, Depends, HTTPException, status
from sqlalchemy.orm import Session
from pydantic import BaseModel
from core.database import get_db
from core.exceptions import not_found_exception, forbidden_exception
@@ -11,6 +12,41 @@ from modules.auth.models import User
router = APIRouter(prefix="/user", tags=["user"])
# --- Pydantic Schema for Push Token --- #
class PushTokenData(BaseModel):
token: str
device_name: Optional[str] = None
token_type: str # Expecting 'expo'
@router.post("/push-token", status_code=status.HTTP_200_OK)
def save_push_token(
token_data: PushTokenData,
db: Annotated[Session, Depends(get_db)],
current_user: Annotated[User, Depends(get_current_user)],
):
"""
Save the Expo push token for the current user.
Requires user to be logged in.
"""
if token_data.token_type != "expo":
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="Invalid token_type. Only 'expo' is supported.",
)
# Update the user's push token
current_user.expo_push_token = token_data.token
# Optionally, you could store device_name somewhere if needed, perhaps in a separate table
# For now, we just update the token on the user model
db.add(current_user)
db.commit()
db.refresh(current_user)
return {"message": "Push token saved successfully"}
@router.get("/me", response_model=UserResponse)
def me(
db: Annotated[Session, Depends(get_db)],