mirror of
https://github.com/aykhans/portfolio-blog.git
synced 2025-09-10 08:00:44 +00:00
First Commit
This commit is contained in:
19
src/app/schemas/__init__.py
Normal file
19
src/app/schemas/__init__.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from .post import (
|
||||
Post,
|
||||
PostCreate,
|
||||
PostInDBBase,
|
||||
PostUpdate,
|
||||
PostInTemplate,
|
||||
ListPostInTemplate
|
||||
)
|
||||
from .user import (
|
||||
User,
|
||||
UserCreate,
|
||||
UserInDBBase,
|
||||
UserUpdate
|
||||
)
|
||||
from .login import (
|
||||
JWTToken,
|
||||
JWTTokenPayload,
|
||||
LoginForm
|
||||
)
|
23
src/app/schemas/login.py
Normal file
23
src/app/schemas/login.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from dataclasses import dataclass
|
||||
from typing import Optional
|
||||
from fastapi import Form
|
||||
|
||||
from pydantic import (
|
||||
BaseModel,
|
||||
EmailStr
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class LoginForm:
|
||||
email: str = Form(...)
|
||||
password: str = Form(...)
|
||||
|
||||
|
||||
class JWTToken(BaseModel):
|
||||
access_token: str
|
||||
token_type: str
|
||||
|
||||
|
||||
class JWTTokenPayload(BaseModel):
|
||||
sub: Optional[EmailStr] = None
|
61
src/app/schemas/post.py
Normal file
61
src/app/schemas/post.py
Normal file
@@ -0,0 +1,61 @@
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import (
|
||||
BaseModel,
|
||||
Field,
|
||||
PastDatetime,
|
||||
computed_field,
|
||||
TypeAdapter
|
||||
)
|
||||
|
||||
from app.core.config import settings
|
||||
|
||||
|
||||
class PostBase(BaseModel):
|
||||
title: Optional[str] = None
|
||||
text: Optional[str] = None
|
||||
image_path: Optional[str] = None
|
||||
|
||||
|
||||
class PostCreate(PostBase):
|
||||
title: str = Field(max_length=100)
|
||||
text: str
|
||||
image_path: str
|
||||
|
||||
|
||||
class PostUpdate(PostBase):
|
||||
title: Optional[str] = Field(max_length=100)
|
||||
|
||||
|
||||
class PostInTemplate(PostBase):
|
||||
title: str
|
||||
text: str
|
||||
created_at: PastDatetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
ListPostInTemplate = TypeAdapter(list[PostInTemplate])
|
||||
|
||||
|
||||
class PostInDBBase(PostBase):
|
||||
slug: str
|
||||
title: str
|
||||
text: str
|
||||
image_path: str
|
||||
owner_id: int
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class Post(PostInDBBase):
|
||||
@computed_field
|
||||
@property
|
||||
def image_url(self) -> str:
|
||||
return str(
|
||||
settings.MEDIA_FOLDER /
|
||||
settings.FILE_FOLDERS['post_images'] /
|
||||
self.image_path
|
||||
)
|
34
src/app/schemas/user.py
Normal file
34
src/app/schemas/user.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel, EmailStr
|
||||
|
||||
|
||||
class UserBase(BaseModel):
|
||||
email: Optional[EmailStr] = None
|
||||
is_active: Optional[bool] = True
|
||||
is_superuser: bool = False
|
||||
username: Optional[str] = None
|
||||
|
||||
|
||||
class UserCreate(UserBase):
|
||||
email: EmailStr
|
||||
password: str
|
||||
|
||||
|
||||
class UserUpdate(UserBase):
|
||||
password: Optional[str] = None
|
||||
|
||||
|
||||
class UserInDBBase(UserBase):
|
||||
id: Optional[int] = None
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class User(UserInDBBase):
|
||||
pass
|
||||
|
||||
|
||||
class UserInDB(UserInDBBase):
|
||||
hashed_password: str
|
Reference in New Issue
Block a user