File size: 2,993 Bytes
ed147e2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"""

SQLModel database models for PostgreSQL (Supabase).

Optimized for cloud deployment and mobile app integration.

"""

from datetime import datetime
from typing import Optional, List
from sqlmodel import SQLModel, Field, Relationship


class User(SQLModel, table=True):
    """

    User model for authentication and note ownership.

    

    Attributes:

        id: Primary key, auto-incremented

        email: Unique email address for login

        username: Display name for the user

        password_hash: Bcrypt hashed password

        role: User role (default: "user")

        created_at: Account creation timestamp

        notes: Relationship to user's notes

    """
    __tablename__ = "users"
    
    id: Optional[int] = Field(default=None, primary_key=True)
    email: str = Field(unique=True, index=True, max_length=255, nullable=False)
    username: str = Field(max_length=100, nullable=False)
    password_hash: str = Field(max_length=255, nullable=False)
    role: str = Field(default="user", max_length=50, nullable=False)
    created_at: datetime = Field(default_factory=datetime.utcnow, nullable=False)
    
    # Relationship to notes
    notes: List["Note"] = Relationship(back_populates="owner")
    
    class Config:
        """Pydantic configuration."""
        json_schema_extra = {
            "example": {
                "email": "student@example.com",
                "username": "Student123",
                "role": "user"
            }
        }


class Note(SQLModel, table=True):
    """

    Note model for storing generated study notes.

    

    Attributes:

        id: Primary key, auto-incremented

        user_id: Foreign key to the user who generated this note

        video_url: YouTube video URL

        video_title: Title of the processed video

        summary_content: Generated study notes content (markdown)

        created_at: Note generation timestamp

        owner: Relationship to the user who owns this note

    """
    __tablename__ = "notes"
    
    id: Optional[int] = Field(default=None, primary_key=True)
    user_id: int = Field(foreign_key="users.id", index=True, nullable=False)
    video_url: str = Field(index=True, max_length=500, nullable=False)
    video_title: str = Field(max_length=500, nullable=False)
    summary_content: str = Field(nullable=False)  # Full markdown content
    created_at: datetime = Field(default_factory=datetime.utcnow, nullable=False)
    
    # Relationship to user
    owner: Optional[User] = Relationship(back_populates="notes")
    
    class Config:
        """Pydantic configuration."""
        json_schema_extra = {
            "example": {
                "user_id": 1,
                "video_url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
                "video_title": "Introduction to Python Programming",
                "summary_content": "# Study Notes\\n\\n## Key Concepts..."
            }
        }