mirror of
https://github.com/flibusta-apps/users_settings_server.git
synced 2025-12-06 14:45:38 +01:00
Add create_language endpoint
This commit is contained in:
@@ -1,12 +1,15 @@
|
|||||||
from pydantic import BaseModel, constr
|
from pydantic import BaseModel, constr
|
||||||
|
|
||||||
|
|
||||||
class LanguageDetail(BaseModel):
|
class CreateLanguage(BaseModel):
|
||||||
id: int
|
|
||||||
label: constr(max_length=16) # type: ignore
|
label: constr(max_length=16) # type: ignore
|
||||||
code: constr(max_length=4) # type: ignore
|
code: constr(max_length=4) # type: ignore
|
||||||
|
|
||||||
|
|
||||||
|
class LanguageDetail(CreateLanguage):
|
||||||
|
id: int
|
||||||
|
|
||||||
|
|
||||||
class UserBase(BaseModel):
|
class UserBase(BaseModel):
|
||||||
user_id: int
|
user_id: int
|
||||||
last_name: constr(max_length=64) # type: ignore
|
last_name: constr(max_length=64) # type: ignore
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from fastapi_pagination import Page, Params
|
|||||||
from fastapi_pagination.ext.ormar import paginate
|
from fastapi_pagination.ext.ormar import paginate
|
||||||
|
|
||||||
from app.depends import check_token
|
from app.depends import check_token
|
||||||
from app.serializers import UserCreateOrUpdate, UserDetail, LanguageDetail
|
from app.serializers import UserCreateOrUpdate, UserDetail, CreateLanguage, LanguageDetail
|
||||||
from app.models import User, Language
|
from app.models import User, Language
|
||||||
|
|
||||||
|
|
||||||
@@ -76,3 +76,8 @@ async def get_language(code: str):
|
|||||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND)
|
||||||
|
|
||||||
return language
|
return language
|
||||||
|
|
||||||
|
|
||||||
|
@languages_router.post("/", response_model=LanguageDetail)
|
||||||
|
async def create_language(data: CreateLanguage):
|
||||||
|
return await Language.objects.create(**data.dict())
|
||||||
|
|||||||
Reference in New Issue
Block a user