mirror of
https://github.com/khoaliber/LetterFeed.git
synced 2026-03-09 05:39:13 +00:00
v0.1.0
This commit is contained in:
1
backend/app/schemas/__init__.py
Normal file
1
backend/app/schemas/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Pydantic schemas for data validation and serialization."""
|
||||
23
backend/app/schemas/entries.py
Normal file
23
backend/app/schemas/entries.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import datetime
|
||||
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
|
||||
|
||||
class EntryBase(BaseModel):
|
||||
"""Base schema for an entry."""
|
||||
subject: str
|
||||
body: str
|
||||
|
||||
|
||||
class EntryCreate(EntryBase):
|
||||
"""Schema for creating a new entry."""
|
||||
pass
|
||||
|
||||
|
||||
class Entry(EntryBase):
|
||||
"""Schema for retrieving an entry with its ID and newsletter ID."""
|
||||
id: int
|
||||
newsletter_id: int
|
||||
received_at: datetime.datetime
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
46
backend/app/schemas/newsletters.py
Normal file
46
backend/app/schemas/newsletters.py
Normal file
@@ -0,0 +1,46 @@
|
||||
from typing import List
|
||||
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
|
||||
|
||||
class SenderBase(BaseModel):
|
||||
"""Base schema for a sender."""
|
||||
email: str
|
||||
|
||||
|
||||
class SenderCreate(SenderBase):
|
||||
"""Schema for creating a new sender."""
|
||||
pass
|
||||
|
||||
|
||||
class Sender(SenderBase):
|
||||
"""Schema for retrieving a sender with its ID and newsletter ID."""
|
||||
id: int
|
||||
newsletter_id: int
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
class NewsletterBase(BaseModel):
|
||||
"""Base schema for a newsletter."""
|
||||
name: str
|
||||
|
||||
|
||||
class NewsletterCreate(NewsletterBase):
|
||||
"""Schema for creating a new newsletter."""
|
||||
sender_emails: List[str]
|
||||
|
||||
|
||||
class NewsletterUpdate(NewsletterBase):
|
||||
"""Schema for updating an existing newsletter."""
|
||||
sender_emails: List[str]
|
||||
|
||||
|
||||
class Newsletter(NewsletterBase):
|
||||
"""Schema for retrieving a newsletter with its ID, active status, senders, and entries count."""
|
||||
id: int
|
||||
is_active: bool
|
||||
senders: List[Sender] = []
|
||||
entries_count: int
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
28
backend/app/schemas/settings.py
Normal file
28
backend/app/schemas/settings.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from typing import List
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class SettingsBase(BaseModel):
|
||||
"""Base schema for application settings."""
|
||||
imap_server: str
|
||||
imap_username: str
|
||||
search_folder: str = "INBOX"
|
||||
move_to_folder: str | None = None
|
||||
mark_as_read: bool = False
|
||||
email_check_interval: int = 15
|
||||
auto_add_new_senders: bool = False
|
||||
|
||||
|
||||
class SettingsCreate(SettingsBase):
|
||||
"""Schema for creating or updating settings, including the IMAP password."""
|
||||
imap_password: str
|
||||
|
||||
|
||||
class Settings(SettingsBase):
|
||||
"""Schema for retrieving settings, with password excluded by default."""
|
||||
id: int
|
||||
imap_password: str | None = Field(None, exclude=True)
|
||||
locked_fields: List[str] = []
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
Reference in New Issue
Block a user