-
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/refactor dto #16
Changes from 7 commits
e1c46b3
45622e0
c966d10
1422abb
190c8c2
d94a918
64ce0c5
7ebc04f
3de991a
78e21fc
47b8225
7a950ae
c0e1845
d9e3477
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
"""Data transfer object for domain registration.""" | ||
"""Data transfer object for hospital domain registration.""" | ||
from __future__ import annotations | ||
|
||
from typing import Optional | ||
|
||
import pydantic | ||
|
||
from registrations.domain.hospital import registration | ||
from registrations.domain.location.location import Address | ||
from registrations.domain.services import hospital_registration_services | ||
from registrations.utils import enum_utils | ||
|
||
|
||
class RegisterKeyContact( | ||
|
@@ -21,7 +24,7 @@ class RegisterKeyContact( | |
email: Optional[pydantic.EmailStr] | ||
|
||
|
||
class HospitalRegistrationEntry( | ||
class ToHospitalRegistrationEntry( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uninitialized attribute: Attribute Reply with "@sonatype-lift help" for info about LiftBot commands. When talking to LiftBot, you need to refresh the page to see its response. Click here to get to know more about LiftBot commands. Was this a good recommendation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sonatype-lift ignore There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've recorded this as ignored for this pull request. If you change your mind, just comment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uninitialized attribute: Attribute Reply with "@sonatype-lift help" for info about LiftBot commands. When talking to LiftBot, you need to refresh the page to see its response. Click here to get to know more about LiftBot commands. Was this a good recommendation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sonatype-lift ignore There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've recorded this as ignored for this pull request. If you change your mind, just comment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uninitialized attribute: Attribute Reply with "@sonatype-lift help" for info about LiftBot commands. When talking to LiftBot, you need to refresh the page to see its response. Click here to get to know more about LiftBot commands. Was this a good recommendation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sonatype-lift ignore There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've recorded this as ignored for this pull request. If you change your mind, just comment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uninitialized attribute: Attribute Reply with "@sonatype-lift help" for info about LiftBot commands. When talking to LiftBot, you need to refresh the page to see its response. Click here to get to know more about LiftBot commands. Was this a good recommendation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sonatype-lift ignore There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've recorded this as ignored for this pull request. If you change your mind, just comment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uninitialized attribute: Attribute Reply with "@sonatype-lift help" for info about LiftBot commands. When talking to LiftBot, you need to refresh the page to see its response. Click here to get to know more about LiftBot commands. Was this a good recommendation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uninitialized attribute: Attribute Reply with "@sonatype-lift help" for info about LiftBot commands. When talking to LiftBot, you need to refresh the page to see its response. Click here to get to know more about LiftBot commands. Was this a good recommendation? |
||
pydantic.BaseModel, | ||
allow_mutation=False, | ||
validate_assignment=True, | ||
|
@@ -35,3 +38,64 @@ class HospitalRegistrationEntry( | |
key_contact: Optional[RegisterKeyContact] | ||
verified_status: Optional[str] | ||
address: Address | ||
|
||
@pydantic.validator("ownership_type", pre=True) | ||
@classmethod | ||
def validate_ownership_type(cls, ownership_type: str) -> str: | ||
"""Validate ownership is limited to OwnershipType enum.""" | ||
if ownership_type not in registration.OwnershipType.values(): | ||
raise ValueError(f"Invalid ownership type: {ownership_type}") | ||
return ownership_type | ||
|
||
@pydantic.validator("name", pre=True) | ||
@classmethod | ||
def validate_name(cls, name: str) -> str: | ||
"""Validate name has atleast one word with 3 characters.""" | ||
if not (name and len(name.strip().split()[0]) >= 3): | ||
raise ValueError(f"Invalid name: {name}. Not enough characters.") | ||
return name | ||
|
||
@pydantic.root_validator | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Invalid decoration: While applying decorator Reply with "@sonatype-lift help" for info about LiftBot commands. When talking to LiftBot, you need to refresh the page to see its response. Click here to get to know more about LiftBot commands. Was this a good recommendation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sonatype-lift ignore There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've recorded this as ignored for this pull request. If you change your mind, just comment |
||
@classmethod | ||
def validate_hospital_entity(cls, values: dict) -> dict: | ||
"""Validate hospital entity. | ||
|
||
We either get a verification status or an unverified | ||
manual registration entry. We cannot get both. | ||
Either attribute should be accessible via registration_entry | ||
as verified_status or key_contact. | ||
""" | ||
verified_status = values.get("verified_status") | ||
key_contact: Optional[RegisterKeyContact] = values.get("key_contact") | ||
if ( | ||
verified_status | ||
== enum_utils.enum_value_of(registration.VerificationStatus.Unverified) | ||
and not key_contact | ||
) or ( | ||
verified_status | ||
!= enum_utils.enum_value_of(registration.VerificationStatus.Unverified) | ||
and key_contact | ||
): | ||
error_msg = ( | ||
f"Cannot have {verified_status} verification status with " | ||
f"{(key_contact and key_contact.name) or key_contact} key contact." | ||
) | ||
raise ValueError(error_msg) | ||
return values | ||
|
||
def build_hospital_entity_dict(self) -> dict: | ||
"""Build hospital entity. | ||
|
||
:return: dict, the hospital entity dict to register. | ||
""" | ||
builder_dict = self.dict() | ||
if verified_status := builder_dict.get("verified_status"): | ||
builder_dict["verified_status"] = registration.VerificationStatus( | ||
verified_status | ||
) | ||
if key_contact := builder_dict.pop("key_contact", None): | ||
builder_dict["key_contact_registrar"] = key_contact | ||
builder_dict["phone_number"] = registration.PhoneNumber( | ||
number=builder_dict.pop("hospital_contact_number") | ||
) | ||
return builder_dict |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
import enum | ||
|
||
|
||
def enum_value_of(enum_class) -> str: | ||
assert isinstance(enum_class, enum.Enum) | ||
return enum_class.value | ||
|
||
|
||
class EnumWithItems(enum.Enum): | ||
@classmethod | ||
def items(cls) -> dict[str, str]: | ||
return {key.name: key.value for key in cls} | ||
|
||
@classmethod | ||
def values(cls) -> list[str]: | ||
return [key.value for key in cls] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unexpected keyword: Unexpected keyword argument
extra
to callobject.__init_subclass__
.Reply with "@sonatype-lift help" for info about LiftBot commands.
Reply with "@sonatype-lift ignore" to tell LiftBot to leave out the above finding from this PR.
Reply with "@sonatype-lift ignoreall" to tell LiftBot to leave out all the findings from this PR and from the status bar in Github.
When talking to LiftBot, you need to refresh the page to see its response. Click here to get to know more about LiftBot commands.
Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sonatype-lift ignore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've recorded this as ignored for this pull request. If you change your mind, just comment
@sonatype-lift unignore
.