43 lines
930 B
Python
43 lines
930 B
Python
"""
|
|
Pydantic schemas for Article model.
|
|
"""
|
|
|
|
from datetime import datetime
|
|
from typing import Optional
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class ArticleBase(BaseModel):
|
|
"""Base article schema."""
|
|
|
|
title: str = Field(..., min_length=1, max_length=200)
|
|
content: str = Field(..., min_length=1)
|
|
|
|
|
|
class ArticleCreate(ArticleBase):
|
|
"""Schema for creating a new article."""
|
|
|
|
author_id: int = Field(..., ge=1)
|
|
category_id: int = Field(..., ge=1)
|
|
|
|
|
|
class ArticleUpdate(BaseModel):
|
|
"""Schema for updating an article."""
|
|
|
|
title: Optional[str] = Field(None, min_length=1, max_length=200)
|
|
content: Optional[str] = Field(None, min_length=1)
|
|
published: Optional[bool] = None
|
|
|
|
|
|
class ArticleResponse(ArticleBase):
|
|
"""Schema for article response."""
|
|
|
|
id: int
|
|
author_id: int
|
|
category_id: int
|
|
created_at: datetime
|
|
published: bool
|
|
|
|
class Config:
|
|
from_attributes = True
|