diff --git a/mdrsclient/api/user.py b/mdrsclient/api/user.py index fa17ed2..01e951a 100644 --- a/mdrsclient/api/user.py +++ b/mdrsclient/api/user.py @@ -1,3 +1,4 @@ +from dataclasses import field from typing import Final import requests @@ -6,14 +7,13 @@ from pydantic.dataclasses import dataclass from mdrsclient.api.base import BaseApi from mdrsclient.exceptions import UnauthorizedException -from mdrsclient.models import Token, User +from mdrsclient.models import Laboratory, Token, User @dataclass(frozen=True) class UserAuthResponse(Token): is_reviewer: bool | None = None - laboratory: str | None = None - lab_id: int | None = None + laboratories: list[Laboratory] = field(default_factory=list) class UserApi(BaseApi): @@ -29,7 +29,7 @@ class UserApi(BaseApi): self._raise_response_error(response) obj = TypeAdapter(UserAuthResponse).validate_python(response.json()) token = Token(access=obj.access, refresh=obj.refresh) - laboratory_ids = [obj.lab_id] if obj.lab_id is not None else [] + laboratory_ids = list(map(lambda x: x.id, obj.laboratories)) is_reviewer = obj.is_reviewer if obj.is_reviewer is not None else False user = User(id=token.user_id, username=username, laboratory_ids=laboratory_ids, is_reviewer=is_reviewer) return (user, token)