初始提交:极码 GeekCode 全栈项目(FastAPI + Vue3)
This commit is contained in:
69
backend/schemas/post.py
Normal file
69
backend/schemas/post.py
Normal file
@@ -0,0 +1,69 @@
|
||||
"""帖子相关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
|
||||
Reference in New Issue
Block a user