mealie/mealie/schema/response/responses.py
Michael Genson 7a107584c7
feat: Upgrade to Pydantic V2 (#3134)
* bumped pydantic
2024-02-11 16:47:37 +00:00

43 lines
1.2 KiB
Python

from pydantic import BaseModel
from mealie.schema._mealie import MealieModel
class ErrorResponse(BaseModel):
message: str
error: bool = True
exception: str | None = None
@classmethod
def respond(cls, message: str, exception: str | None = None) -> dict:
"""
This method is an helper to create an object and convert to a dictionary
in the same call, for use while providing details to a HTTPException
"""
return cls(message=message, exception=exception).model_dump()
class SuccessResponse(BaseModel):
message: str
error: bool = False
@classmethod
def respond(cls, message: str) -> dict:
"""
This method is an helper to create an object and convert to a dictionary
in the same call, for use while providing details to a HTTPException
"""
return cls(message=message).model_dump()
class FileTokenResponse(MealieModel):
file_token: str
@classmethod
def respond(cls, token: str) -> dict:
"""
This method is an helper to create an object and convert to a dictionary
in the same call, for use while providing details to a HTTPException
"""
return cls(file_token=token).model_dump()