fix: TypeAdapter
This commit is contained in:
		@@ -3,8 +3,6 @@ import math
 | 
			
		||||
 | 
			
		||||
from datetime import datetime, timezone
 | 
			
		||||
 | 
			
		||||
from pydantic import TypeAdapter
 | 
			
		||||
 | 
			
		||||
from sqlalchemy import insert, select, func
 | 
			
		||||
from sqlalchemy.ext.asyncio import AsyncConnection
 | 
			
		||||
from enum import Enum
 | 
			
		||||
@@ -12,7 +10,7 @@ from enum import Enum
 | 
			
		||||
from api.db.tables.account import account_table
 | 
			
		||||
 | 
			
		||||
from api.schemas.account.account import User
 | 
			
		||||
from api.schemas.endpoints.account import AllUser, AllUserResponse
 | 
			
		||||
from api.schemas.endpoints.account import AllUserResponse, all_user_adapter
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
async def get_all_users_login_and_id(connection: AsyncConnection, page, limit) -> Optional[User]:
 | 
			
		||||
@@ -20,9 +18,6 @@ async def get_all_users_login_and_id(connection: AsyncConnection, page, limit) -
 | 
			
		||||
    Получает id и login всех юзеров
 | 
			
		||||
    """
 | 
			
		||||
 | 
			
		||||
    user_adapter = TypeAdapter(AllUser)
 | 
			
		||||
    response_adapter = TypeAdapter(AllUserResponse)
 | 
			
		||||
 | 
			
		||||
    first_user = page*limit-(limit)
 | 
			
		||||
 | 
			
		||||
    query = (
 | 
			
		||||
@@ -41,16 +36,15 @@ async def get_all_users_login_and_id(connection: AsyncConnection, page, limit) -
 | 
			
		||||
    total_count = count_result.scalar()
 | 
			
		||||
    total_pages = math.ceil(total_count / limit)
 | 
			
		||||
 | 
			
		||||
    validated_users = [
 | 
			
		||||
        user_adapter.validate_python({"id": u.id, "login": u.login})
 | 
			
		||||
        for u in users_data
 | 
			
		||||
    ]
 | 
			
		||||
    validated_users = all_user_adapter.validate_python(
 | 
			
		||||
        [{"id": u.id, "login": u.login} for u in users_data]
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    return response_adapter.validate_python({
 | 
			
		||||
        "users": validated_users,
 | 
			
		||||
        "amount_count": total_count,
 | 
			
		||||
        "amount_pages": total_pages
 | 
			
		||||
    })
 | 
			
		||||
    return AllUserResponse(
 | 
			
		||||
        users=validated_users,
 | 
			
		||||
        amount_count=total_count,
 | 
			
		||||
        amount_pages=total_pages
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
async def get_user_id(connection: AsyncConnection, id: int) -> Optional[User]:
 | 
			
		||||
 
 | 
			
		||||
@@ -1,11 +1,8 @@
 | 
			
		||||
from fastapi import (
 | 
			
		||||
    APIRouter,
 | 
			
		||||
    Body,
 | 
			
		||||
    Depends,
 | 
			
		||||
    Form,
 | 
			
		||||
    HTTPException,
 | 
			
		||||
    Request,
 | 
			
		||||
    Response,
 | 
			
		||||
    status,
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
from enum import Enum
 | 
			
		||||
from typing import Optional, List
 | 
			
		||||
from datetime import datetime
 | 
			
		||||
from pydantic import BaseModel, EmailStr, Field
 | 
			
		||||
from pydantic import BaseModel, EmailStr, Field, TypeAdapter
 | 
			
		||||
 | 
			
		||||
# Таблица для получения информации из запроса
 | 
			
		||||
 | 
			
		||||
@@ -37,3 +37,5 @@ class AllUserResponse(BaseModel):
 | 
			
		||||
    users: List[AllUser]
 | 
			
		||||
    amount_count: int
 | 
			
		||||
    amount_pages: int
 | 
			
		||||
 | 
			
		||||
all_user_adapter = TypeAdapter(List[AllUser])
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user