Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added backend/app/model/__init__.py
Empty file.
32 changes: 32 additions & 0 deletions backend/app/model/user_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from pydantic import BaseModel, EmailStr, Field
from typing import Optional, List
from datetime import datetime

class User(BaseModel):
id: str = Field(..., description="Unique identifier for the user")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

your IDs should either be int or uuid.

Copy link
Contributor

@khodizoda khodizoda Jul 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id here should be a str, because MongoDB's ObjectId is not JSON serializable. @DerekGuijt plz, wrap str as a PyObjectId: PyObjectId = Annotated[str, BeforeValidator(str)]

email: EmailStr = Field(..., description="User's email address")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

email-validator is required to use EmailStr. Please add email-validator to the requirements.txt. Double check the correct package needed for email-validator.

username: str = Field(..., min_length=3, max_length=50, description="User's chosen username")
password_hash: str = Field(..., description="Hashed password")
full_name: Optional[str] = Field(None, description="User's full name")
is_active: bool = Field(default=True, description="Whether the user account is active")
created_at: datetime = Field(default_factory=datetime.utcnow, description="Timestamp of account creation")
last_login: Optional[datetime] = Field(None, description="Timestamp of last login")
watch_history: List[str] = Field(default_factory=list, description="List of IDs of watched content")
bookmark: List[str] = Field(default_factory=list, description="List of IDs of content in bookmarks")

class Config:
allow_population_by_field_name = True
schema_extra = {
"example": {
"id": "user123",
"email": "user@example.com",
"username": "netflixfan",
"password_hash": "hashed_password_here",
"full_name": "John Doe",
"is_active": True,
"created_at": "2023-01-01T00:00:00",
"last_login": "2023-07-16T12:30:00",
"watch_history": ["movie123", "series456"],
"bookmark": ["movie789", "series101"]
}
}