Skip to content

Commit

Permalink
feat: Endpoint to get STR Requirements (bcgov#336)
Browse files Browse the repository at this point in the history
* feat: Endpoint to get STR Requirements

* no message

* no message

* no message
  • Loading branch information
kris-daxiom authored Nov 26, 2024
1 parent 1335bca commit b3c567d
Show file tree
Hide file tree
Showing 7 changed files with 215 additions and 1 deletion.
4 changes: 4 additions & 0 deletions strr-api/devops/vaults.gcp.env
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ GCP_CS_PROJECT_ID="op://buckets/$APP_ENV/strr/GCP_CS_PROJECT_ID"
GCP_CS_SA_SCOPE="op://buckets/$APP_ENV/strr/GCP_CS_SA_SCOPE"
GCP_CS_BUCKET_ID="op://buckets/$APP_ENV/strr/GCP_CS_BUCKET_ID"
VPC_CONNECTOR="op://CD/$APP_ENV/strr-api/VPC_CONNECTOR"
STR_DATA_API_CLIENT_ID="op://keycloak/$APP_ENV/str-data-api/STR_DATA_API_CLIENT_ID"
STR_DATA_API_CLIENT_SECRET="op://keycloak/$APP_ENV/str-data-api/STR_DATA_API_CLIENT_SECRET"
STR_DATA_API_TOKEN_URL="op://keycloak/$APP_ENV/str-data-api/STR_DATA_API_TOKEN_URL"
STR_DATA_API_URL="op://API/$APP_ENV/str-data-api/STR_DATA_API_URL"
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.22"
version = "0.0.23"
description = ""
authors = ["thorwolpert <thor@wolpert.ca>"]
license = "BSD 3-Clause"
Expand Down
6 changes: 6 additions & 0 deletions strr-api/src/strr_api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ class Config: # pylint: disable=too-few-public-methods
GCP_CS_BUCKET_ID = os.getenv("GCP_CS_BUCKET_ID")
GCP_AUTH_KEY = os.getenv("GCP_AUTH_KEY")

# DATA PORTAL API
STR_DATA_API_CLIENT_ID = os.getenv("STR_DATA_API_CLIENT_ID", "")
STR_DATA_API_CLIENT_SECRET = os.getenv("STR_DATA_API_CLIENT_SECRET", "")
STR_DATA_API_TOKEN_URL = os.getenv("STR_DATA_API_TOKEN_URL", "")
STR_DATA_API_URL = os.getenv("STR_DATA_API_URL", "")


class Production(Config): # pylint: disable=too-few-public-methods
"""Production class configuration that should override vars for production."""
Expand Down
6 changes: 6 additions & 0 deletions strr-api/src/strr_api/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from .meta import bp as meta_endpoint
from .ops import bp as ops_endpoint
from .registrations import bp as registrations_endpoint
from .str_address_requirements import bp as str_address_requirements
from .users import bp as users_endpoint


Expand Down Expand Up @@ -96,6 +97,11 @@ def register_endpoints(app: Flask):
blueprint=users_endpoint,
)

app.register_blueprint(
url_prefix="/address",
blueprint=str_address_requirements,
)

app.register_blueprint(meta_endpoint)

app.config["SWAGGER"] = {
Expand Down
91 changes: 91 additions & 0 deletions strr-api/src/strr_api/resources/str_address_requirements.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Copyright © 2024 Province of British Columbia
#
# Licensed under the BSD 3 Clause License, (the "License");
# you may not use this file except in compliance with the License.
# The template for the license can be found here
# https://opensource.org/license/bsd-3-clause/
#
# Redistribution and use in source and binary forms,
# with or without modification, are permitted provided that the
# following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS”
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

"""
Endpoints to get the STR data for addresses.
"""

import logging
from http import HTTPStatus

from flasgger import swag_from
from flask import Blueprint, request
from flask_cors import cross_origin

from strr_api.common.auth import jwt
from strr_api.exceptions import ExternalServiceException, error_response
from strr_api.schemas.utils import validate
from strr_api.services.approval_service import ApprovalService

logger = logging.getLogger("api")
bp = Blueprint("str-requirements", __name__)


@bp.route("/requirements", methods=["POST"])
@swag_from({"security": [{"Bearer": []}]})
@cross_origin(origin="*")
@jwt.requires_auth
def get_str_requirements():
"""
Returns the Short Term Rental requirements for this address.
---
tags:
- address
parameters:
- in: body
name: body
schema:
type: object
responses:
200:
description:
400:
description:
"""
try:
address_json = request.get_json()
[valid, errors] = validate(address_json, "rental_unit_address")
if not valid:
return error_response(message="Invalid request", http_status=HTTPStatus.BAD_REQUEST, errors=errors)
unit_address = address_json.get("address")
address_line_1 = ""
if unit_number := unit_address.get("unitNumber"):
address_line_1 = f"{unit_number}-"
address_line_1 = f"{address_line_1}{unit_address.get('streetNumber')} {unit_address.get('streetName')}"
address_line_2 = unit_address.get("addressLineTwo", "")
address = f"{address_line_1} {address_line_2}, {unit_address.get('city'), unit_address.get('province')}"
return ApprovalService.getSTRDataForAddress(address=address), HTTPStatus.OK
except ExternalServiceException as service_exception:
logger.error("Error while getting STR requirements", exc_info=service_exception)
return error_response(service_exception.message, service_exception.status_code)
70 changes: 70 additions & 0 deletions strr-api/src/strr_api/schemas/schemas/rental_unit_address.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://strr.gov.bc.ca/.well_known/schemas/rental_unit_address",
"type": "object",
"title": "Rental Unit Address",
"definitions": {
"rentalUnitAddress": {
"type": "object",
"properties": {
"nickname": {
"type": "string"
},
"unitNumber": {
"type": "string",
"description": "Unit Number."
},
"streetNumber": {
"type": "string",
"description": "Street Number."
},
"streetName": {
"type": "string",
"description": "Street address and name."
},
"addressLineTwo": {
"type": "string",
"description": "Additional street address information."
},
"city": {
"type": "string",
"description": "City, Town, or Village."
},
"postalCode": {
"type": "string",
"maxLength": 15,
"description": "Postal Code in A1A 1A1 format for Canada, or zip code for US addresses."
},
"province": {
"type": "string",
"maxLength": 2,
"description": "The 2-letter province code (ISO 3166-2) for this address."
},
"country": {
"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": [
"streetNumber",
"streetName",
"city",
"province"
]
}
},
"properties": {
"address": {
"$ref": "#/definitions/rentalUnitAddress"
}
},
"required": [
"address"
]
}
37 changes: 37 additions & 0 deletions strr-api/tests/postman/strr-api.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,43 @@
"response": []
}
]
},
{
"name": "STR Requirements",
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "{{token}}",
"type": "string"
}
]
},
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{\n \"address\": {\n \"unitNumber\": \"\",\n \"streetNumber\": \"12166\",\n \"streetName\": \"GREENWELL ST MAPLE RIDGE\",\n \"addressLineTwo\": \"\",\n \"city\": \"MAPLE RIDGE\",\n \"province\": \"BC\"\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{api_url}}/address/requirements",
"host": [
"{{api_url}}"
],
"path": [
"address",
"requirements"
]
}
},
"response": []
}
]
}

0 comments on commit b3c567d

Please sign in to comment.