Skip to content

Commit

Permalink
mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed Dec 10, 2024
1 parent 16c19cb commit b358fb4
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ async def join_and_update_from_pre_registration_details(
)

@staticmethod
async def get_billing_details(conn: SAConnection, user_id: int) -> RowProxy | None:
result = await conn.execute(
def get_billing_details_query(user_id: int):
return (
sa.select(
users.c.first_name,
users.c.last_name,
Expand All @@ -155,6 +155,12 @@ async def get_billing_details(conn: SAConnection, user_id: int) -> RowProxy | No
)
.where(users.c.id == user_id)
)

@staticmethod
async def get_billing_details(conn: SAConnection, user_id: int) -> RowProxy | None:
result = await conn.execute(
UsersRepo.get_billing_details_query(user_id=user_id)
)
value: RowProxy | None = await result.fetchone()
return value

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Annotated, Any, Self
from typing import Annotated, Any, NamedTuple, Self

from models_library.emails import LowerCaseEmailStr
from pydantic import BaseModel, ConfigDict, Field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@
field_validator,
model_validator,
)
from servicelib.aiohttp import status
from servicelib.request_keys import RQT_USERID_KEY
from simcore_postgres_database.models.users import UserStatus

from .._constants import RQ_PRODUCT_KEY
from ._schemas import PreUserProfile


class UsersRequestContext(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from models_library.users import GroupID, UserBillingDetails, UserID
from simcore_postgres_database.models.groups import groups, user_to_groups
from simcore_postgres_database.models.products import products
from simcore_postgres_database.models.users import UserStatus, user_to_groups, users
from simcore_postgres_database.models.users import UserStatus, users
from simcore_postgres_database.models.users_details import (
users_pre_registration_details,
)
Expand Down Expand Up @@ -243,7 +243,9 @@ async def get_user_billing_details(
BillingDetailsNotFoundError
"""
async with pass_or_acquire_connection(engine, connection) as conn:
user_billing_details = await UsersRepo.get_billing_details(conn, user_id)
if not user_billing_details:
query = UsersRepo.get_billing_details_query(user_id=user_id)
result = await conn.stream(query)
row = await result.fetchone()
if not row:
raise BillingDetailsNotFoundError(user_id=user_id)
return UserBillingDetails.model_validate(user_billing_details)
return UserBillingDetails.model_validate(row)
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async def wrapper(request: web.Request) -> web.StreamResponse:
async def get_my_profile(request: web.Request) -> web.Response:
req_ctx = UsersRequestContext.model_validate(request)
profile: MyProfileGet = await api.get_user_profile(
request.app, req_ctx.user_id, req_ctx.product_name
request.app, user_id=req_ctx.user_id, product_name=req_ctx.product_name
)
return envelope_json_response(profile)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from aiohttp import web
from models_library.emails import LowerCaseEmailStr
from models_library.payments import UserInvoiceAddress
from models_library.products import ProductName
from models_library.users import UserBillingDetails, UserID
from pydantic import TypeAdapter
from simcore_postgres_database.models.users import UserStatus
from simcore_service_webserver.products._api import ProductName

from ..db.plugin import get_asyncpg_engine
from . import _schemas, _users_repository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import simcore_postgres_database.errors as db_errors
import sqlalchemy as sa
from aiohttp import web
from aiopg.sa.result import RowProxy
from models_library.api_schemas_webserver.users import (
MyProfileGet,
MyProfilePatch,
Expand All @@ -31,6 +30,7 @@
transaction_context,
)
from simcore_postgres_database.utils_users import generate_alternative_username
from sqlalchemy.engine.row import Row

from ..db.plugin import get_asyncpg_engine
from ..login.storage import AsyncpgStorage, get_plugin_storage
Expand Down Expand Up @@ -62,7 +62,7 @@


def _convert_groups_db_to_schema(
db_row: RowProxy, *, prefix: str | None = "", **kwargs
db_row: Row, *, prefix: str | None = "", **kwargs
) -> dict:
# NOTE: Deprecated. has to be replaced with
converted_dict = {
Expand Down Expand Up @@ -346,10 +346,11 @@ async def get_user(app: web.Application, user_id: UserID) -> dict[str, Any]:
"""
:raises UserNotFoundError:
"""
row = await _users_repository.get_user_or_raise(
row: Row = await _users_repository.get_user_or_raise(
engine=get_asyncpg_engine(app), user_id=user_id
)
return row._asdict()
user: dict[str, Any] = row._asdict()
return user


async def get_user_id_from_gid(app: web.Application, primary_gid: int) -> UserID:
Expand Down

0 comments on commit b358fb4

Please sign in to comment.