78 lines
1.9 KiB
Python
78 lines
1.9 KiB
Python
# from pydantic import BaseModel, Field, HttpUrl
|
|
# from typing import Optional, List, Literal
|
|
# from uuid import UUID
|
|
|
|
# class ProfileCreate(BaseModel):
|
|
# gender: Literal["male", "female", "other"]
|
|
# city: str
|
|
# languages: List[str] = []
|
|
# interests: List[str] = []
|
|
|
|
# class ProfileUpdate(BaseModel):
|
|
# gender: Optional[Literal["male", "female", "other"]] = None
|
|
# city: Optional[str] = None
|
|
# languages: Optional[List[str]] = None
|
|
# interests: Optional[List[str]] = None
|
|
# photo_url: Optional[Optional[str]] = Field(default=None)
|
|
|
|
# class ProfileOut(BaseModel):
|
|
# id: UUID
|
|
# user_id: UUID
|
|
# gender: Literal["male", "female", "other"]
|
|
# city: str
|
|
# languages: List[str] = []
|
|
# interests: List[str] = []
|
|
# photo_url: Optional[str] = None
|
|
|
|
# from pydantic import ConfigDict
|
|
# model_config = ConfigDict(from_attributes=True)
|
|
|
|
# class LikesList(BaseModel):
|
|
# items: List[str]
|
|
|
|
|
|
# services/profiles/src/app/schemas/profile.py
|
|
from __future__ import annotations
|
|
|
|
from typing import List, Optional
|
|
from uuid import UUID
|
|
|
|
from pydantic import BaseModel, ConfigDict
|
|
|
|
|
|
# Базовые поля профиля
|
|
class ProfileBase(BaseModel):
|
|
gender: str
|
|
city: str
|
|
languages: List[str]
|
|
interests: List[str]
|
|
|
|
|
|
# Для POST /profiles/v1/profiles
|
|
class ProfileCreate(ProfileBase):
|
|
pass
|
|
|
|
|
|
# Для PATCH /profiles/v1/profiles/me (все поля опциональные)
|
|
class ProfileUpdate(BaseModel):
|
|
gender: Optional[str] = None
|
|
city: Optional[str] = None
|
|
languages: Optional[List[str]] = None
|
|
interests: Optional[List[str]] = None
|
|
photo_url: Optional[str] = None # nullable
|
|
|
|
|
|
# Для ответов
|
|
class ProfileOut(ProfileBase):
|
|
id: UUID
|
|
user_id: UUID
|
|
photo_url: Optional[str] = None
|
|
|
|
# Важно: для возврата ORM-объектов
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
# Для лайков
|
|
class LikesList(BaseModel):
|
|
items: List[UUID]
|