added child endpoint, ability to add and edit child as well as auto redirect to add-child page when user without child accesses home page
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
"""Child-related request and response models."""
|
||||
|
||||
from datetime import datetime
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class CreateChildRequest(BaseModel):
|
||||
"""Request model for creating a child."""
|
||||
|
||||
name: str = Field(..., min_length=1, max_length=100)
|
||||
birth_time: datetime
|
||||
birth_weight: float = Field(..., gt=0, description="Birth weight in grams")
|
||||
|
||||
|
||||
class ChildResponse(BaseModel):
|
||||
"""Response model for child data."""
|
||||
|
||||
id: int
|
||||
name: str
|
||||
birth_time: datetime
|
||||
birth_weight: float
|
||||
user_id: int
|
||||
created_at: datetime
|
||||
@@ -0,0 +1,28 @@
|
||||
"""Child database model."""
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
from sqlalchemy import Column, Integer, String, DateTime, Float, ForeignKey
|
||||
from datetime import datetime
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from sqlalchemy.orm import DeclarativeBase
|
||||
|
||||
Base = DeclarativeBase
|
||||
else:
|
||||
from baby_monitor.repositories.dependencies.get_database import Base
|
||||
|
||||
|
||||
class Child(Base):
|
||||
"""Child database model."""
|
||||
|
||||
__tablename__ = "children"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String, nullable=False)
|
||||
birth_time = Column(DateTime, nullable=False)
|
||||
birth_weight = Column(Float, nullable=False) # in grams
|
||||
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
|
||||
created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<Child(id={self.id}, name='{self.name}', user_id={self.user_id})>"
|
||||
Reference in New Issue
Block a user