Skip to content

Commit

Permalink
API changes - Property Details (bcgov#216)
Browse files Browse the repository at this point in the history
* API changes - Property Details

* Added max length for location description
  • Loading branch information
kris-daxiom authored Oct 24, 2024
1 parent 7d5f20f commit 7cd6379
Show file tree
Hide file tree
Showing 14 changed files with 168 additions and 10 deletions.
69 changes: 69 additions & 0 deletions strr-api/migrations/versions/20241023_2357_dbca5f95ed31_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"""empty message
Revision ID: dbca5f95ed31
Revises: a3cf5bb26f36
Create Date: 2024-10-23 23:57:23.616885
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = 'dbca5f95ed31'
down_revision = 'a3cf5bb26f36'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
rentalunitspacetype = postgresql.ENUM('ENTIRE_HOME', 'SHARED_ACCOMMODATION', name='rentalunitspacetype')
rentalunitspacetype.create(op.get_bind(), checkfirst=True)

hostresidence = postgresql.ENUM('SAME_UNIT', 'ANOTHER_UNIT', name='hostresidence')
hostresidence.create(op.get_bind(), checkfirst=True)

with op.batch_alter_table('addresses', schema=None) as batch_op:
batch_op.add_column(sa.Column('location_description', sa.String(), nullable=True))

with op.batch_alter_table('addresses_history', schema=None) as batch_op:
batch_op.add_column(sa.Column('location_description', sa.String(), autoincrement=False, nullable=True))

with op.batch_alter_table('rental_properties', schema=None) as batch_op:
batch_op.add_column(sa.Column('space_type', rentalunitspacetype, nullable=False))
batch_op.add_column(sa.Column('host_residence', hostresidence, nullable=False))
batch_op.add_column(sa.Column('is_unit_on_principal_residence_property', sa.Boolean(), nullable=False))
batch_op.add_column(sa.Column('number_of_rooms_for_rent', sa.Integer(), nullable=False))

with op.batch_alter_table('rental_properties_history', schema=None) as batch_op:
batch_op.add_column(sa.Column('space_type', sa.Enum('ENTIRE_HOME', 'SHARED_ACCOMMODATION', name='rentalunitspacetype'), autoincrement=False, nullable=False))
batch_op.add_column(sa.Column('host_residence', sa.Enum('SAME_UNIT', 'ANOTHER_UNIT', name='hostresidence'), autoincrement=False, nullable=False))
batch_op.add_column(sa.Column('is_unit_on_principal_residence_property', sa.Boolean(), autoincrement=False, nullable=False))
batch_op.add_column(sa.Column('number_of_rooms_for_rent', sa.Integer(), autoincrement=False, nullable=False))
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('rental_properties_history', schema=None) as batch_op:
batch_op.drop_column('number_of_rooms_for_rent')
batch_op.drop_column('is_unit_on_principal_residence_property')
batch_op.drop_column('host_residence')
batch_op.drop_column('space_type')

with op.batch_alter_table('rental_properties', schema=None) as batch_op:
batch_op.drop_column('number_of_rooms_for_rent')
batch_op.drop_column('is_unit_on_principal_residence_property')
batch_op.drop_column('host_residence')
batch_op.drop_column('space_type')

with op.batch_alter_table('addresses_history', schema=None) as batch_op:
batch_op.drop_column('location_description')

with op.batch_alter_table('addresses', schema=None) as batch_op:
batch_op.drop_column('location_description')

op.execute("DROP TYPE IF EXISTS rentalunitspacetype;")
op.execute("DROP TYPE IF EXISTS propertytype;")
# ### end Alembic commands ###
1 change: 1 addition & 0 deletions strr-api/src/strr_api/models/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Address(Versioned, BaseModel):
city = db.Column(db.String, nullable=False)
province = db.Column(db.String, nullable=False)
postal_code = db.Column(db.String, nullable=False)
location_description = db.Column(db.String, nullable=True)

contact = relationship("Contact", back_populates="address", foreign_keys="Contact.address_id")
rental_properties_address = relationship(
Expand Down
16 changes: 16 additions & 0 deletions strr-api/src/strr_api/models/rental.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ class RegistrationType(BaseEnum):
class RentalProperty(Versioned, BaseModel):
"""Rental Property"""

class RentalUnitSpaceType(BaseEnum):
"""Enum of rental unit space type."""

ENTIRE_HOME = auto() # pylint: disable=invalid-name
SHARED_ACCOMMODATION = auto() # pylint: disable=invalid-name

class HostResidence(BaseEnum):
"""Enum of host residence option."""

SAME_UNIT = auto() # pylint: disable=invalid-name
ANOTHER_UNIT = auto() # pylint: disable=invalid-name

__tablename__ = "rental_properties"

id = db.Column(db.Integer, primary_key=True, autoincrement=True)
Expand All @@ -65,6 +77,10 @@ class RentalProperty(Versioned, BaseModel):
rental_act_accepted = db.Column(db.Boolean, nullable=False, default=False)
pr_exempt_reason = db.Column(db.String, nullable=True)
service_provider = db.Column(db.String, nullable=True)
space_type = db.Column(db.Enum(RentalUnitSpaceType), nullable=False)
host_residence = db.Column(db.Enum(HostResidence), nullable=False)
is_unit_on_principal_residence_property = db.Column(db.Boolean, nullable=False)
number_of_rooms_for_rent = db.Column(db.Integer, nullable=False)

address_id = db.Column(db.Integer, db.ForeignKey("addresses.id"), nullable=False)
registration_id = db.Column(db.Integer, db.ForeignKey("registrations.id"), nullable=False)
Expand Down
15 changes: 14 additions & 1 deletion strr-api/src/strr_api/requests/RegistrationRequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,25 @@ class UnitDetails:
"""UnitDetails payload object."""

def __init__(
self, propertyType, ownershipType, parcelIdentifier=None, businessLicense=None, businessLicenseExpiryDate=None
self,
propertyType,
ownershipType,
rentalUnitSpaceType,
hostResidence,
isUnitOnPrincipalResidenceProperty,
numberOfRoomsForRent,
parcelIdentifier=None,
businessLicense=None,
businessLicenseExpiryDate=None,
):
self.propertyType = propertyType
self.ownershipType = ownershipType
self.parcelIdentifier = parcelIdentifier
self.businessLicense = businessLicense
self.rentalUnitSpaceType = rentalUnitSpaceType
self.hostResidence = hostResidence
self.isUnitOnPrincipalResidenceProperty = isUnitOnPrincipalResidenceProperty
self.numberOfRoomsForRent = numberOfRoomsForRent
self.businessLicenseExpiryDate = businessLicenseExpiryDate


Expand Down
6 changes: 6 additions & 0 deletions strr-api/src/strr_api/responses/RegistrationSerializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def populate_platform_registration_details(cls, registration_data: dict, registr
"postalCode": platform.mailingAddress.postal_code,
"province": platform.mailingAddress.province,
"country": platform.mailingAddress.country,
"locationDescription": platform.mailingAddress.location_description,
},
}
if platform.registered_office_attorney_mailing_address_id:
Expand All @@ -65,6 +66,7 @@ def populate_platform_registration_details(cls, registration_data: dict, registr
"postalCode": attorney_mailing_address.postal_code,
"province": attorney_mailing_address.province,
"country": attorney_mailing_address.country,
"locationDescription": attorney_mailing_address.location_description,
},
}

Expand Down Expand Up @@ -177,6 +179,10 @@ def populate_host_registration_details(cls, registration_data: dict, registratio
else None,
"propertyType": registration.rental_property.property_type.name,
"ownershipType": registration.rental_property.ownership_type.name,
"rentalUnitSpaceType": registration.rental_property.space_type,
"hostResidence": registration.rental_property.host_residence,
"isUnitOnPrincipalResidenceProperty": registration.rental_property.is_unit_on_principal_residence_property,
"numberOfRoomsForRent": registration.rental_property.number_of_rooms_for_rent,
}

registration_data["listingDetails"] = [
Expand Down
5 changes: 5 additions & 0 deletions strr-api/src/strr_api/schemas/schemas/address.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
"type": "string",
"maxLength": 2,
"description": "The 2-letter country code (ISO 3166-1) for this address."
},
"locationDescription": {
"type": "string",
"maxLength": 1000,
"description": "Location description."
}
},
"required": [
Expand Down
26 changes: 25 additions & 1 deletion strr-api/src/strr_api/schemas/schemas/host-registration.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,26 @@
"type": "string",
"format": "date"
},
"rentalUnitSpaceType": {
"type": "string",
"enum": [
"ENTIRE_HOME",
"SHARED_ACCOMMODATION"
]
},
"hostResidence": {
"type": "string",
"enum": [
"SAME_UNIT",
"ANOTHER_UNIT"
]
},
"isUnitOnPrincipalResidenceProperty": {
"type": "boolean"
},
"numberOfRoomsForRent": {
"type": "integer"
},
"propertyType": {
"type": "string",
"enum": [
Expand All @@ -184,7 +204,11 @@
},
"required": [
"propertyType",
"ownershipType"
"ownershipType",
"rentalUnitSpaceType",
"hostResidence",
"isUnitOnPrincipalResidenceProperty",
"numberOfRoomsForRent"
]
},
"listingDetails": {
Expand Down
6 changes: 6 additions & 0 deletions strr-api/src/strr_api/services/registration_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ def _create_platform_registration(cls, registration_request: dict) -> PlatformRe
city=mailing_address.get("city"),
province=mailing_address.get("province"),
postal_code=mailing_address.get("postalCode"),
location_description=mailing_address.get("locationDescription"),
),
brands=platform_brands,
representatives=representatives,
Expand All @@ -160,6 +161,7 @@ def _create_platform_registration(cls, registration_request: dict) -> PlatformRe
city=attorney_mailing_address_dict.get("city"),
province=attorney_mailing_address_dict.get("province"),
postal_code=attorney_mailing_address_dict.get("postalCode"),
location_description=mailing_address.get("locationDescription"),
)

platform_registration = PlatformRegistration(platform=platform)
Expand All @@ -186,6 +188,10 @@ def _create_host_registration(cls, registration_request: dict) -> RentalProperty
).date()
if registration_request.unitDetails.businessLicenseExpiryDate
else None,
space_type=registration_request.unitDetails.rentalUnitSpaceType,
host_residence=registration_request.unitDetails.hostResidence,
is_unit_on_principal_residence_property=registration_request.unitDetails.isUnitOnPrincipalResidenceProperty,
number_of_rooms_for_rent=registration_request.unitDetails.numberOfRoomsForRent,
property_type=registration_request.unitDetails.propertyType,
ownership_type=registration_request.unitDetails.ownershipType,
is_principal_residence=registration_request.principalResidence.isPrincipalResidence,
Expand Down
6 changes: 5 additions & 1 deletion strr-api/tests/mocks/json/host_registration.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@
"businessLicense": "7777777",
"businessLicenseExpiryDate": "2025-01-01",
"propertyType": "SINGLE_FAMILY_HOME",
"ownershipType": "OWN"
"ownershipType": "OWN",
"rentalUnitSpaceType": "ENTIRE_HOME",
"hostResidence": "SAME_UNIT",
"isUnitOnPrincipalResidenceProperty": true,
"numberOfRoomsForRent": 1
},
"unitAddress": {
"nickname": "My Rental Property",
Expand Down
6 changes: 5 additions & 1 deletion strr-api/tests/mocks/json/host_registration_ltsa.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
"parcelIdentifier": "018-850-570",
"businessLicense": "7777777",
"propertyType": "SINGLE_FAMILY_HOME",
"ownershipType": "OWN"
"ownershipType": "OWN",
"rentalUnitSpaceType": "ENTIRE_HOME",
"hostResidence": "SAME_UNIT",
"isUnitOnPrincipalResidenceProperty": true,
"numberOfRoomsForRent": 1
},
"unitAddress": {
"country": "CA",
Expand Down
6 changes: 5 additions & 1 deletion strr-api/tests/mocks/json/host_registration_minimum.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
},
"unitDetails": {
"propertyType": "SINGLE_FAMILY_HOME",
"ownershipType": "OWN"
"ownershipType": "OWN",
"rentalUnitSpaceType": "ENTIRE_HOME",
"hostResidence": "SAME_UNIT",
"isUnitOnPrincipalResidenceProperty": true,
"numberOfRoomsForRent": 1
},
"unitAddress": {
"country": "CA",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@
"businessLicense": "7777777",
"businessLicenseExpiryDate": "2025-01-01",
"propertyType": "SINGLE_FAMILY_HOME",
"ownershipType": "OWN"
"ownershipType": "OWN",
"rentalUnitSpaceType": "ENTIRE_HOME",
"hostResidence": "SAME_UNIT",
"isUnitOnPrincipalResidenceProperty": true,
"numberOfRoomsForRent": 1
},
"unitAddress": {
"nickname": "My Rental Property",
Expand Down
6 changes: 4 additions & 2 deletions strr-api/tests/mocks/json/platform_registration.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
"addressLineTwo": "",
"city": "MAPLE RIDGE",
"province": "BC",
"postalCode": "V2X 6K6"
"postalCode": "V2X 6K6",
"locationDescription": "Test Location"
},
"registeredOfficeOrAttorneyForServiceDetails": {
"attorneyName": "Test",
Expand All @@ -57,7 +58,8 @@
"addressLineTwo": "",
"city": "MAPLE RIDGE",
"province": "BC",
"postalCode": "V2X 6K6"
"postalCode": "V2X 6K6",
"locationDescription": "Test Location"
}
}
},
Expand Down
Loading

0 comments on commit 7cd6379

Please sign in to comment.