Skip to content

Commit

Permalink
fix: host updates
Browse files Browse the repository at this point in the history
  • Loading branch information
kris-daxiom committed Dec 12, 2024
1 parent 5ed568c commit 6f26efc
Show file tree
Hide file tree
Showing 19 changed files with 286 additions and 439 deletions.
46 changes: 46 additions & 0 deletions strr-api/migrations/versions/20241212_0611_0fb49e0b4707_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""empty message
Revision ID: 0fb49e0b4707
Revises: 8912b6965de6
Create Date: 2024-12-12 06:11:20.394557
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '0fb49e0b4707'
down_revision = '8912b6965de6'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('contacts', schema=None) as batch_op:
batch_op.alter_column('firstname',
existing_type=sa.VARCHAR(),
nullable=True)

with op.batch_alter_table('contacts_history', schema=None) as batch_op:
batch_op.alter_column('firstname',
existing_type=sa.VARCHAR(length=1000),
nullable=True,
autoincrement=False)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('contacts_history', schema=None) as batch_op:
batch_op.alter_column('firstname',
existing_type=sa.VARCHAR(length=1000),
nullable=False,
autoincrement=False)

with op.batch_alter_table('contacts', schema=None) as batch_op:
batch_op.alter_column('firstname',
existing_type=sa.VARCHAR(),
nullable=False)
# ### end Alembic commands ###
2 changes: 1 addition & 1 deletion strr-api/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "strr-api"
version = "0.0.25"
version = "0.0.26"
description = ""
authors = ["thorwolpert <thor@wolpert.ca>"]
license = "BSD 3-Clause"
Expand Down
2 changes: 1 addition & 1 deletion strr-api/src/strr_api/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Contact(Versioned, db.Model):
__tablename__ = "contacts"

id = db.Column(db.Integer, primary_key=True, autoincrement=True)
firstname = db.Column(db.String(1000), nullable=False)
firstname = db.Column(db.String(1000), nullable=True)
lastname = db.Column(db.String(1000), nullable=False)
middlename = db.Column(db.String(1000))
address_id = db.Column(db.Integer, db.ForeignKey("addresses.id"), nullable=True)
Expand Down
74 changes: 25 additions & 49 deletions strr-api/src/strr_api/requests/RegistrationRequest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# pylint: disable=C0103
# pylint: disable=R0913
# pylint: disable=R0917
# pylint: disable=R0914
"""
Registration request payload objects.
"""
Expand All @@ -22,21 +23,21 @@ def __init__( # pylint: disable=W0102
unitAddress,
unitDetails,
listingDetails,
principalResidence,
secondaryContact=None,
documents=[], # pylint: disable=W0102
registrationType=None,
propertyManager=None,
strRequirements=None,
):
self.primaryContact = Contact(**primaryContact)
self.secondaryContact = Contact(**secondaryContact) if secondaryContact else None
self.unitAddress = UnitAddress(**unitAddress)
self.unitDetails = UnitDetails(**unitDetails)
self.listingDetails = [ListingDetails(**item) for item in listingDetails]
self.principalResidence = PrincipalResidence(**principalResidence)
self.documents = [Document(**document) for document in documents]
self.registrationType = registrationType
self.propertyManager = PropertyManager(**propertyManager) if propertyManager else None
self.strRequirements = strRequirements


class PropertyManager:
Expand Down Expand Up @@ -99,24 +100,6 @@ def __init__(
self.mailingAddress = MailingAddress(**mailingAddress) if mailingAddress else None


class PrincipalResidence:
"""PrincipalResidence payload object."""

def __init__(
self,
isPrincipalResidence,
agreedToRentalAct,
agreedToSubmit,
nonPrincipalOption=None,
specifiedServiceProvider=None,
):
self.isPrincipalResidence = isPrincipalResidence
self.agreedToRentalAct = agreedToRentalAct
self.agreedToSubmit = agreedToSubmit
self.nonPrincipalOption = nonPrincipalOption
self.specifiedServiceProvider = specifiedServiceProvider


class ListingDetails:
"""ListingDetails payload object."""

Expand All @@ -139,6 +122,7 @@ def __init__(
businessLicense=None,
businessLicenseExpiryDate=None,
strataHotelRegistrationNumber=None,
prExemptReason=None,
):
self.propertyType = propertyType
self.ownershipType = ownershipType
Expand All @@ -150,6 +134,7 @@ def __init__(
self.numberOfRoomsForRent = numberOfRoomsForRent
self.businessLicenseExpiryDate = businessLicenseExpiryDate
self.strataHotelRegistrationNumber = strataHotelRegistrationNumber
self.prExemptReason = prExemptReason


class MailingAddress:
Expand Down Expand Up @@ -190,51 +175,42 @@ def __init__(
self.unitNumber = unitNumber


class ContactName:
"""ContactName payload object."""

def __init__(self, firstName, lastName, middleName=None):
self.firstName = firstName
self.lastName = lastName
self.middleName = middleName


class ContactDetails:
"""ContactDetails payload object."""

def __init__(
self, phoneNumber, emailAddress, preferredName=None, extension=None, faxNumber=None, phoneCountryCode=None
):
self.phoneNumber = phoneNumber
self.emailAddress = emailAddress
self.preferredName = preferredName
self.extension = extension
self.faxNumber = faxNumber
self.phoneCountryCode = phoneCountryCode


class Contact:
"""Contact payload object."""

def __init__(
self,
name,
details,
mailingAddress,
firstName=None,
lastName=None,
middleName=None,
mailingAddress=None,
socialInsuranceNumber=None,
businessNumber=None,
businessLegalName=None,
contactType=None,
dateOfBirth=None,
phoneNumber=None,
emailAddress=None,
preferredName=None,
extension=None,
faxNumber=None,
phoneCountryCode=None,
):
self.name = ContactName(**name)
self.firstName = firstName
self.lastName = lastName
self.middleName = middleName
self.dateOfBirth = dateOfBirth
self.socialInsuranceNumber = socialInsuranceNumber
self.businessNumber = businessNumber
self.details = ContactDetails(**details)
self.mailingAddress = MailingAddress(**mailingAddress)
self.businessLegalName = businessLegalName
self.contactType = contactType
self.phoneNumber = phoneNumber
self.emailAddress = emailAddress
self.preferredName = preferredName
self.extension = extension
self.faxNumber = faxNumber
self.phoneCountryCode = phoneCountryCode
self.mailingAddress = MailingAddress(**mailingAddress)


class Document:
Expand Down
52 changes: 19 additions & 33 deletions strr-api/src/strr_api/responses/RegistrationSerializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,26 +191,22 @@ def populate_host_registration_details(cls, registration_data: dict, registratio
secondary_property_contact = secondary_property_contacts[0] if secondary_property_contacts else None

registration_data["primaryContact"] = {
"name": {
"firstName": primary_property_contact.contact.firstname,
"middleName": primary_property_contact.contact.middlename,
"lastName": primary_property_contact.contact.lastname,
},
"firstName": primary_property_contact.contact.firstname,
"middleName": primary_property_contact.contact.middlename,
"lastName": primary_property_contact.contact.lastname,
"dateOfBirth": primary_property_contact.contact.date_of_birth.strftime("%Y-%m-%d")
if primary_property_contact.contact.date_of_birth
else None,
"socialInsuranceNumber": primary_property_contact.contact.social_insurance_number,
"businessNumber": primary_property_contact.contact.business_number,
"contactType": primary_property_contact.contact_type,
"businessLegalName": primary_property_contact.business_legal_name,
"details": {
"preferredName": primary_property_contact.contact.preferredname,
"phoneNumber": primary_property_contact.contact.phone_number,
"phoneCountryCode": primary_property_contact.contact.phone_country_code,
"extension": primary_property_contact.contact.phone_extension,
"faxNumber": primary_property_contact.contact.fax_number,
"emailAddress": primary_property_contact.contact.email,
},
"preferredName": primary_property_contact.contact.preferredname,
"phoneNumber": primary_property_contact.contact.phone_number,
"phoneCountryCode": primary_property_contact.contact.phone_country_code,
"extension": primary_property_contact.contact.phone_extension,
"faxNumber": primary_property_contact.contact.fax_number,
"emailAddress": primary_property_contact.contact.email,
"mailingAddress": {
"address": primary_property_contact.contact.address.street_address,
"addressLineTwo": primary_property_contact.contact.address.street_address_additional, # noqa: E501
Expand All @@ -224,25 +220,21 @@ def populate_host_registration_details(cls, registration_data: dict, registratio
registration_data["secondaryContact"] = None
if secondary_property_contact:
registration_data["secondaryContact"] = {
"name": {
"firstName": secondary_property_contact.contact.firstname,
"middleName": secondary_property_contact.contact.middlename,
"lastName": secondary_property_contact.contact.lastname,
},
"firstName": secondary_property_contact.contact.firstname,
"middleName": secondary_property_contact.contact.middlename,
"lastName": secondary_property_contact.contact.lastname,
"dateOfBirth": secondary_property_contact.contact.date_of_birth.strftime("%Y-%m-%d")
if secondary_property_contact.contact.date_of_birth
else None,
"socialInsuranceNumber": secondary_property_contact.contact.social_insurance_number,
"contactType": secondary_property_contact.contact_type,
"businessNumber": secondary_property_contact.contact.business_number,
"details": {
"preferredName": secondary_property_contact.contact.preferredname,
"phoneNumber": secondary_property_contact.contact.phone_number,
"phoneCountryCode": secondary_property_contact.contact.phone_country_code,
"extension": secondary_property_contact.contact.phone_extension,
"faxNumber": secondary_property_contact.contact.fax_number,
"emailAddress": secondary_property_contact.contact.email,
},
"preferredName": secondary_property_contact.contact.preferredname,
"phoneNumber": secondary_property_contact.contact.phone_number,
"phoneCountryCode": secondary_property_contact.contact.phone_country_code,
"extension": secondary_property_contact.contact.phone_extension,
"faxNumber": secondary_property_contact.contact.fax_number,
"emailAddress": secondary_property_contact.contact.email,
"mailingAddress": {
"address": secondary_property_contact.contact.address.street_address,
"addressLineTwo": secondary_property_contact.contact.address.street_address_additional,
Expand Down Expand Up @@ -281,19 +273,13 @@ def populate_host_registration_details(cls, registration_data: dict, registratio
"isUnitOnPrincipalResidenceProperty": registration.rental_property.is_unit_on_principal_residence_property,
"numberOfRoomsForRent": registration.rental_property.number_of_rooms_for_rent,
"strataHotelRegistrationNumber": registration.rental_property.strata_hotel_registration_number,
"prExemptReason": registration.rental_property.pr_exempt_reason,
}

registration_data["listingDetails"] = [
{"url": platform.url} for platform in registration.rental_property.property_listings
]

registration_data["principalResidence"] = {
"isPrincipalResidence": registration.rental_property.is_principal_residence,
"agreedToRentalAct": registration.rental_property.rental_act_accepted,
"nonPrincipalOption": registration.rental_property.pr_exempt_reason,
"specifiedServiceProvider": registration.rental_property.service_provider,
}

if property_manager := registration.rental_property.property_manager:
if property_manager.property_manager_type == PropertyManager.PropertyManagerType.BUSINESS:
registration_data["propertyManager"] = {
Expand Down
26 changes: 25 additions & 1 deletion strr-api/src/strr_api/schemas/schemas/contact.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,28 @@
"preferredName": {
"type": "string"
},
"dateOfBirth": {
"type": "string",
"format": "date",
"description": "YYYY-MM-DD"
},
"socialInsuranceNumber": {
"type": "string"
},
"businessNumber": {
"type": "string"
},
"businessLegalName": {
"type": "string"
},
"contactType": {
"type": "string",
"enum": [
"INDIVIDUAL",
"BUSINESS"
],
"default": "INDIVIDUAL"
},
"phoneNumber": {
"type": "string"
},
Expand All @@ -31,10 +53,12 @@
"emailAddress": {
"type": "string",
"format": "email"
},
"mailingAddress": {
"$ref": "https://strr.gov.bc.ca/.well_known/schemas/address"
}
},
"required": [
"firstName",
"lastName",
"phoneNumber",
"emailAddress"
Expand Down
Loading

0 comments on commit 6f26efc

Please sign in to comment.