70 lines
1.4 KiB
Python
70 lines
1.4 KiB
Python
"""帖子相关Schema"""
|
|
from pydantic import BaseModel
|
|
from datetime import datetime
|
|
from typing import Optional, List
|
|
|
|
|
|
class PostCreate(BaseModel):
|
|
title: str
|
|
content: str
|
|
category: str = ""
|
|
tags: List[str] = []
|
|
is_public: bool = True
|
|
is_draft: bool = False
|
|
|
|
|
|
class PostUpdate(BaseModel):
|
|
title: Optional[str] = None
|
|
content: Optional[str] = None
|
|
category: Optional[str] = None
|
|
tags: Optional[List[str]] = None
|
|
is_public: Optional[bool] = None
|
|
is_draft: Optional[bool] = None
|
|
|
|
|
|
class PostResponse(BaseModel):
|
|
id: int
|
|
user_id: int
|
|
title: str
|
|
content: str
|
|
category: str = ""
|
|
tags: str = ""
|
|
is_public: bool = True
|
|
is_draft: bool = False
|
|
view_count: int = 0
|
|
like_count: int = 0
|
|
collect_count: int = 0
|
|
comment_count: int = 0
|
|
created_at: datetime
|
|
updated_at: datetime
|
|
# 额外字段(查询时填充)
|
|
author_name: str = ""
|
|
is_liked: bool = False
|
|
is_collected: bool = False
|
|
|
|
class Config:
|
|
from_attributes = True
|
|
|
|
|
|
class PostListResponse(BaseModel):
|
|
items: List[PostResponse]
|
|
total: int
|
|
page: int
|
|
page_size: int
|
|
|
|
|
|
class CommentCreate(BaseModel):
|
|
content: str
|
|
|
|
|
|
class CommentResponse(BaseModel):
|
|
id: int
|
|
post_id: int
|
|
user_id: int
|
|
content: str
|
|
created_at: datetime
|
|
author_name: str = ""
|
|
|
|
class Config:
|
|
from_attributes = True
|