Skip to content

Commit

Permalink
feat: Allow strata hotel registration number in host application (#331)
Browse files Browse the repository at this point in the history
  • Loading branch information
kris-daxiom authored Nov 22, 2024
1 parent 5171bf4 commit 3359c86
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 1 deletion.
37 changes: 37 additions & 0 deletions strr-api/migrations/versions/20241122_2030_9f1cd9a7258f_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""empty message
Revision ID: 9f1cd9a7258f
Revises: bb586f56f51a
Create Date: 2024-11-22 20:30:42.842000
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = '9f1cd9a7258f'
down_revision = 'bb586f56f51a'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
with op.batch_alter_table('rental_properties', schema=None) as batch_op:
batch_op.add_column(sa.Column('strata_hotel_registration_number', sa.String(), nullable=True))

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

# ### 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('strata_hotel_registration_number')

with op.batch_alter_table('rental_properties', schema=None) as batch_op:
batch_op.drop_column('strata_hotel_registration_number')
# ### end Alembic commands ###
1 change: 1 addition & 0 deletions strr-api/src/strr_api/models/rental.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class HostResidence(BaseEnum):
host_residence = db.Column(db.Enum(HostResidence), nullable=True)
is_unit_on_principal_residence_property = db.Column(db.Boolean, nullable=False)
number_of_rooms_for_rent = db.Column(db.Integer, nullable=False)
strata_hotel_registration_number = db.Column(db.String, nullable=True)

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
2 changes: 2 additions & 0 deletions strr-api/src/strr_api/requests/RegistrationRequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def __init__(
parcelIdentifier=None,
businessLicense=None,
businessLicenseExpiryDate=None,
strataHotelRegistrationNumber=None,
):
self.propertyType = propertyType
self.ownershipType = ownershipType
Expand All @@ -130,6 +131,7 @@ def __init__(
self.isUnitOnPrincipalResidenceProperty = isUnitOnPrincipalResidenceProperty
self.numberOfRoomsForRent = numberOfRoomsForRent
self.businessLicenseExpiryDate = businessLicenseExpiryDate
self.strataHotelRegistrationNumber = strataHotelRegistrationNumber


class MailingAddress:
Expand Down
31 changes: 31 additions & 0 deletions strr-api/src/strr_api/resources/registrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from flask_cors import cross_origin

from strr_api.common.auth import jwt
from strr_api.enums.enum import ErrorMessage
from strr_api.exceptions import AuthException, ExternalServiceException, error_response, exception_response
from strr_api.models import User
from strr_api.responses import Events
Expand Down Expand Up @@ -140,6 +141,36 @@ def get_registration(registration_id):
return exception_response(auth_exception)


@bp.route("/<registration_number>/validate", methods=("GET",))
@swag_from({"security": [{"Bearer": []}]})
@cross_origin(origin="*")
@jwt.requires_auth
def validate_registration(registration_number):
"""
Returns whether a registration is valid or not.
---
tags:
- registration
parameters:
- in: path
name: registration_number
type: string
required: true
description: Registration Number
responses:
200:
description:
401:
description:
"""

try:
return {"isValid": RegistrationService.is_registration_valid(registration_number)}, HTTPStatus.OK
except Exception as exception:
logger.error("Error in validating registration number: %s", repr(exception))
return error_response(ErrorMessage.PROCESSING_ERROR.value, HTTPStatus.INTERNAL_SERVER_ERROR)


@bp.route("/<registration_id>/documents/<file_key>", methods=("GET",))
@swag_from({"security": [{"Bearer": []}]})
@cross_origin(origin="*")
Expand Down
1 change: 1 addition & 0 deletions strr-api/src/strr_api/responses/RegistrationSerializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ def populate_host_registration_details(cls, registration_data: dict, registratio
"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,
"strataHotelRegistrationNumber": registration.rental_property.strata_hotel_registration_number,
}

registration_data["listingDetails"] = [
Expand Down
3 changes: 3 additions & 0 deletions strr-api/src/strr_api/schemas/schemas/host-registration.json
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@
"RENT",
"CO_OWN"
]
},
"strataHotelRegistrationNumber": {
"type": "string"
}
},
"required": [
Expand Down
10 changes: 10 additions & 0 deletions strr-api/src/strr_api/services/registration_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ def _create_host_registration(cls, registration_request: dict) -> RentalProperty
pr_exempt_reason=registration_request.principalResidence.nonPrincipalOption,
service_provider=registration_request.principalResidence.specifiedServiceProvider,
property_listings=[PropertyListing(url=listing.url) for listing in registration_request.listingDetails],
strata_hotel_registration_number=registration_request.unitDetails.strataHotelRegistrationNumber,
)

if property_manager := registration_request.propertyManager:
Expand Down Expand Up @@ -441,6 +442,15 @@ def get_registration(cls, account_id, registration_id):
query = query.filter_by(sbc_account_id=account_id)
return query.one_or_none()

@classmethod
def is_registration_valid(cls, registration_number) -> bool:
"""Returns whether a registration number is valid."""
is_valid = False
registration = Registration.query.filter_by(registration_number=registration_number).one_or_none()
if registration and registration.status == RegistrationStatus.ACTIVE:
is_valid = True
return is_valid

@classmethod
def generate_registration_certificate(cls, registration: Registration):
"""Generate registration PDF certificate."""
Expand Down
37 changes: 36 additions & 1 deletion strr-api/tests/postman/strr-api.postman_collection.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info": {
"_postman_id": "22e88e3b-9a92-4098-ae9e-578f2af2859c",
"_postman_id": "a0b2883b-75ca-4130-853f-dabb7d473484",
"name": "strr-api",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "31792407"
Expand Down Expand Up @@ -1085,6 +1085,41 @@
},
"response": []
},
{
"name": "Validate Registration number",
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{token}}",
"type": "string"
}
]
},
"method": "GET",
"header": [
{
"key": "Account-Id",
"value": "{{account_id}}",
"type": "text"
}
],
"url": {
"raw": "{{api_url}}/registrations/{{registration_number}}/validate",
"host": [
"{{api_url}}"
],
"path": [
"registrations",
"{{registration_number}}",
"validate"
]
}
},
"response": []
},
{
"name": "Get Registration Events",
"request": {
Expand Down

0 comments on commit 3359c86

Please sign in to comment.