Skip to content
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

#450 Attempt to fix #450 by converting address-based-urls to bbl-based-urls #984

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions project/urls.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from django.contrib import admin
from django.urls import path, include
from . import views


urlpatterns = [
path("admin/", admin.site.urls),
path("api/", include("wow.urls")),
path("auth/", include("jfauthprovider.urls")),
path("address", views.address_query, name="address_query"),
path("bbl/<str:bbl>/", views.property_by_bbl, name="property_by_bbl"),
]

handler500 = "wow.views.server_error"
17 changes: 17 additions & 0 deletions sql/get_property_by_bbl.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CREATE OR REPLACE FUNCTION get_property_by_bbl(bbl VARCHAR)
RETURNS TABLE(
property_name TEXT,
owner_name TEXT,
address TEXT,
units INTEGER
) AS $$
BEGIN
RETURN QUERY SELECT
property_name,
owner_name,
address,
units
FROM properties
WHERE bbl = bbl;
END;
$$ LANGUAGE plpgsql;
23 changes: 23 additions & 0 deletions wow/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
from django.urls import path
from django.shortcuts import redirect

from . import views

app_name = "wow"


def redirect_to_bbl(request):
"""
Redirect address-based URLs to BBL-based URLs.
"""
# Extract parameters from the request (e.g., city, street, number)
city = request.GET.get("city")
street = request.GET.get("street")
number = request.GET.get("number")

# Fetch the corresponding BBL from the database
bbl = call_db_func("get_bbl_from_address", [city, street, number])

if not bbl:
return JsonResponse({"error": "Address not found"}, status=404)

return redirect("wow:property_by_bbl", bbl=bbl)

urlpatterns += [
path("address/<str:city>/<str:street>/<str:number>/", redirect_to_bbl),
]

urlpatterns = [
path("address", views.address_query, name="address_query"),
path(
Expand Down
16 changes: 16 additions & 0 deletions wow/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,3 +379,19 @@ def server_error(request):
from django.views import defaults

return defaults.server_error(request)


def property_by_bbl(request, bbl):
"""
Fetch property details based on the provided BBL.
"""
# Call database function to get associated property data for the given BBL
property_data = call_db_func("get_property_by_bbl", [bbl])

if not property_data:
return JsonResponse({"error": "BBL not found"}, status=404)

return JsonResponse({
"bbl": bbl,
"property_data": property_data,
})