nycplanning / ae-zoning-api Goto Github PK
View Code? Open in Web Editor NEWThis application is API for serving data related to zoning and tax lots.
This application is API for serving data related to zoning and tax lots.
Implement zoning district endpoints using Drizzle. The drizzle endpoints implementation may have outpaced the implementation in Mikro-orm. If the endpoint is not yet suppporeted in Mikro-orm, then the Feature flag route for Mikro Orm should throw an error.
tax-lots/<bbl>/zoning-districts
tax-lots/<bbl>/zoning-districts/classes
zoning-district-classes
zoning-district-classes/category-colors
zoning-district-classes/<id>
zoning-districts/<uuid>/classes
zoning-districts/<uuid>
From discussion #55, document the possible errors for zoning district class endpoints
The following endpoints describe their listed error codes
zoning-district-classes
zoning-district-classes/category-colors
zoning-district-classes/<id>
Blocked by #67
The Reusing Responses documentation describes how to use response components to describe a response on an endpoint. Use the appropriate responses created in ticket #67 to describe the responses for these endpoints.
From discussion #55, we need to validate route parameters. We want to base this validation on the route params detailed in the openapi.yaml
file. We are going to use Kubb to generate types and zod schemas based on the openapi spec file. This initial ticket is to create the schemas used for validation, and to implement the 400
validation response for one endpoint. It will be followed by other tickets to actually implement the validation for other endpoints.
/tax-lots/<bbl>
endpoint to serve as reference code for other endpointsThe description for the colors types omit the opacity from the format and the example. This is reflected in the length of the regex and the structure of the example. These need to be updated.
Also, the index.html has not been rerendered to reflect the restructuring of the category colors.
ff
appended to it
npm run redoc:build
From discussion #55, we need to implement error handling for borough and land use endpoints. Database access is the primary point of errors. This is accomplished differently in drizzle and mikro. Consequently, they will be implemented separately. This is the ticket to implement mikro.
boroughs
land-uses
blocked by #68 to document the endpoints
blocked by #72 to implement the messages to throw
From discussion #55, we need to implement error handling for zoning district endpoints. Schema enforcement and database access are primary points of errors. Each of these are accomplished differently in drizzle and mikro. Consequently, they will be implemented separately. This is the ticket to implement mikro.
zoning-districts/<uuid>
zoning-districts/<uuid>/classes
blocked by #70 to document the endpoints
blocked by #72 to implement the messages to throw
blocked by #74 to implement zod schemas
Discussion #58 outlines the pitfalls of returning top-level arrays and suggests a refactor to instead return an object in which the array is held as a value in an object. This issue is to update the existing implementations to reflect this structure. (Drizzle and Mikro each have their own queries to implement these endpoints. Though, not all of the endpoints have been implemented in Mikro. If Mikro has implemented this endpoint, then it should be updated to reflect the structure. If Mikro has not implemented this endpoint, it does not need to be updated).
The implementations for the following endpoints are updated to return objects with the following structures:
/boroughs
{ boroughs: Array<borough> }
/land-uses
{ landUses: Array<landUse> }
tax-lots/<bbl>/zoning-districts
{ zoningDistricts: Array<zoningDistrict> }
tax-lots/<bbl>/zoning-districts/classes
{ zoningDistrictClasses: Array<zoningDistrictClass> }
zoning-districts/<uuid>/classes
{ zoningDistrictClasses: Array<zoningDistrictClass> }
zoning-district-classes
{ zoningDistrictClasses: Array<zoningDistrictClass> }
zoning-district-classes/category-colors
{ zoningDistrictCatagoryColors: Array<zoningDistrictCatagoryColor> }
Add the OpenAPI schema for the /boroughs
endpoint to the Zoning API.
From discussion #55, we need to implement error handling for tax lot endpoints. Schema enforcement and database access are primary points of errors. Each of these are accomplished differently in drizzle and mikro. Consequently, they will be implemented separately. This is the ticket to implement drizzle. The code examples are meant to show general structure. Actual implementation may vary.
tax-lots/<bbl>
tax-lots/<bbl>/geojson
tax-lots/<bbl>/zoning-districts
tax-lots/<bbl>/zoning-districts/classes
blocked by #69 to document the endpoints
blocked by #72 to implement the messages to throw
blocked by #73 to implement zod schemas
In support of tax lot and zoning district tables, Mikro Orm will need multipolygon geometry and geography types
Open API documentation as outlined in #21, second ticket of three
land-uses
tax-lots/<bbl>
tax-lots/<bbl>/geojson
tax-lots/<bbl>/zoning-districts
Mark all properties guaranteed to be returned by the API as "required" in the OpenAPI documentation
Originally posted by TangoYankee December 6, 2023
@TylerMatteo Should we be more diligent in marking properties/parameters as required in the Open API documentation? I noticed that when we neglect to mark them, Kubb marks them as possible undefined. I think this will lead to more defensive programming than necessary- checking for undefined
values where they will never reasonably occur (because an error would have occurred first).
Relevant to any @NYCPlanning/open-source-engineering writing documentation
From discussion #63, our placement of database calls in the service
files violates the separation of concerns between services and repositories. Services should handle the business logic and repositories should handle the database access.
We want to move the database access from the service to a repository. This is a drizzle-specific implementation. As such, we will need a drizzle specific repository. Mikro-orm already has the repository
namespace: ie) borough.repository.ts with a class named BoroughRepository
. Consequently, drizzle will use the abbreviated repo
namespace to avoid a conflict ie) borough.repo.ts with a class named BoroughRepo
.
borough
folder called borough.repo.ts
borough.repo.ts
file exports a class called BoroughRepo
BoroughRepo
class has db
property with access to the drizzle DB
provider (tax lot example)BoroughRepo
to list of providers in the borough moduleland-use
folder called land-use.repo.ts
land-use.repo.ts
file exports a class called LandUseRepo
LandUseRepo
class has db
property with access to the drizzle DB
provider (tax lot example)LandUseRepo
to list of providers in the land use moduleIn continuation of #46 , we will implement tax-lot related end points using Drizzle. This will require spatial types, schemas, and the endpoints themselves. An example of the spatial types can be found in the drizzle-pgis folder of purple-hawk
drizzle-pgis
folder, inspired by purple-hawkland-uses
tax-lots/<bbl>
tax-lots/<bbl>/geojson
From discussion #55, document the possible errors for borough and land use endpoints
Blocked by #67
The Reusing Responses documentation describes how to use response components to describe a response on an endpoint. Use the appropriate responses created in ticket #67 to describe the responses for these endpoints.
From discussion #55, we need to implement error handling for zoning district class endpoints. Schema enforcement and database access are primary points of errors. Each of these are accomplished differently in drizzle and mikro. Consequently, they will be implemented separately. This is the ticket to implement drizzle.
zoning-district-classes
zoning-district-classes/category-colors
zoning-district-classes/<id>
blocked by #70 to document the endpoints
blocked by #72 to implement the messages to throw
blocked by #73 to implement zod schemas
From discussion #55, we need to validate route parameters. To facilitate this validation, we will first create zod schemas for the route parameters. (These schemas will apply specifically to mikro-orm because drizzle will have its own schemas generated from its own package.)
entity
file.
tax-lot.entity.ts
zoning-district.entity.ts
^((C[1-8])|(M[1-3])|(R([1-9]|10)))$
zoning-district-class.entity.ts
From discussion #55, we need to implement error handling for borough and land use endpoints. Database access is the primary point of errors. This is accomplished differently in drizzle and mikro. Consequently, they will be implemented separately. This is the ticket to implement drizzle.
boroughs
land-uses
blocked by #68 to document the endpoints
blocked by #72 to implement the messages to throw
We want frontends to be able to reference a single service for their data needs. However, the vector tilesets are hosted under a digital ocean space with a separate url. To consolidate these services from the perspective of frontends, we want the api to redirect to the spaces
/api/zoning-districts/<z>/<x>/<y>.pbf
Redirects to the zoning district tileset where z, x, and y are zoom parameters/api/tax-lots/<z>/<x>/<y>.pbf
Redirects to the tax lot tileset, where z, x, and y are zoom parameters302
Document existence of tilesets endpoints in the api
Add the schemas related to the zoning district tables outlined in Data Engineering 302 ERD
2/tax-lot-schema
, the tax-lot entity demonstrates how to use the spatial typesFrom discussion #55, we need to implement error handling for tax lot endpoints. Schema enforcement and database access are primary points of errors. Each of these are accomplished differently in drizzle and mikro. Consequently, they will be implemented separately. This is the ticket to implement mikro.
tax-lots/<bbl>
tax-lots/<bbl>/geojson
tax-lots/<bbl>/zoning-districts
tax-lots/<bbl>/zoning-districts/classes
blocked by #69 to document the endpoints
blocked by #72 to implement the messages to throw
blocked by #74 to implement zod schemas
From discussion #55 , create the reusable components of the errors. This includes the error schema and the three responses that use it.
If copying code directly, be careful to adjust indentation to valid depths. Also, be mindful that the schema
key may already exist in the documentation. The error schema should be placed within the existing schema key, rather than creating a new one.
components:
responses:
Bad Request:
description: Invalid client request.
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
Not Found:
description: Requested resource does not exist or is unavailable.
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
Internal Server Error:
description: Server side error.
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
schemas:
Error:
type: object
properties:
statusCode:
type: number
message:
type: string
error:
type: string
required:
- statusCode
- message
Per ERD, the Zoning District Class should also include the URL property
zoning-district-classes
url
propertyThe zoning-district-classes/category-colors
endpoint was overlooked in #88. The documentation for the endpoint has been previously updated.
The implementation for the following endpoint is updated to return an object with the following structure:
zoning-district-classes/category-colors
{ zoningDistrictClassCategoryColors: Array<zoningDistrictClassCategoryColor > }
Create the drizzle schemas for zoning district, zoning district classes, and their relationships. These schemas are outlined in the ERD written on Data Engineering ticket 302
load.sql
file is updated to load the relevant data into the the databaseFrom discussion #55, document the possible errors for tax lot endpoints
The following endpoints describe their listed error codes
tax-lots/<bbl>
tax-lots/<bbl>/geojson
tax-lots/<bbl>/zoning-districts
tax-lots/<bbl>/zoning-districts/classes
Blocked by #67
The Reusing Responses documentation describes how to use response components to describe a response on an endpoint. Use the appropriate responses created in ticket #67 to describe the responses for these endpoints.
From discussion #63, our placement of database calls in the service
files violates the separation of concerns between services and repositories. Services should handle the business logic and repositories should handle the database access.
We want to move the database access from the service to a repository. This is a drizzle-specific implementation. As such, we will need a drizzle specific repository. Mikro-orm already has the repository
namespace: ie) tax-lot.repository.ts with a class named TaxLotRepository
. Consequently, drizzle will use the abbreviated repo
namespace to avoid a conflict ie) tax-lot.repo.ts with a class named TaxLotRepo
.
tax-lot
folder called tax-lot.repo.ts
tax-lot.repo.ts
file exports a class called TaxLotRepo
TaxLotRepo
class has db
property with access to the drizzle DB
provider (tax lot example)#checkTaxLotByBbl
prepared query statement is moved to the TaxLotRepo.
TaxLotRepo
to list of providers in the tax lot moduleAs a developer, I would like an opportunity to compare Mikro-orm and Drizzle orm. Mikro orm is already integrated into the application but Drizzle is not. I would like to install drizzle orm. Because applications should only be served by a single orm at a time, the use of drizzle should be kept behind a feature flag. Future tickets will implement the full application functionality. However, this ticket should also have an MVP endpoint, to verify a successful installation. An example of integrating drizzle with nest is available at @tangoyankee/purple-hawk
schema
folder is created within the src
directory to store drizzle schemasborough.ts
file within the schema
folderOpen API documentation as outlined in #21, third ticket of three
tax-lots/<bbl>/zoning-districts/classes
zoning-districts/<uuid>/classes
zoning-district-classes
zoning-district-classes/category-colors
zoning-district-classes/<id>
Open API documentation as outlined in #21, first ticket of three
zoning-districts/<uuid>
From discussion #55, we need to implement error handling for zoning district endpoints. Schema enforcement and database access are primary points of errors. Each of these are accomplished differently in drizzle and mikro. Consequently, they will be implemented separately. This is the ticket to implement drizzle.
zoning-districts/<uuid>
zoning-districts/<uuid>/classes
blocked by #70 to document the endpoints
blocked by #72 to implement the messages to throw
blocked by #73 to implement zod schemas
Update documentation for endpoints to returning an object in which the array is held as a value in an object.
The documentation for the paths
=> /<path>
=> response
=> description
following endpoints are updated to indicate endpoint will return return objects:
/boroughs
description: An object containing a list of boroughs
/land-uses
description: An object containing a list of land uses
tax-lots/<bbl>/zoning-districts
description: An object containing zoning districts
tax-lots/<bbl>/zoning-districts/classes
description: An object containing zoning district class schemas
zoning-districts/<uuid>/classes
description: An object of class schemas for the zoning district
zoning-district-classes
description: An object containing list of all zoning district class schemas
zoning-district-classes/category-colors
description: An object containing list of all zoning district category colors
From discussion #55, we need to implement error handling for zoning district class endpoints. Schema enforcement and database access are primary points of errors. Each of these are accomplished differently in drizzle and mikro. Consequently, they will be implemented separately. This is the ticket to implement mikro.
zoning-district-classes
zoning-district-classes/category-colors
zoning-district-classes/<id>
blocked by #70 to document the endpoints
blocked by #72 to implement the messages to throw
blocked by #74 to implement zod schemas
Discussion #58 outlines the pitfalls of returning top-level arrays and suggests a refactor to instead return an object in which the array is held as a value in an object. This issue is to update the OpenAPI documentation to reflect this structure.
Open API documentation for the following endpoints are updated to reflect returning objects with the following structures
/boroughs
{ boroughs: Array<borough> }
/land-uses
{ landUses: Array<landUse> }
tax-lots/<bbl>/zoning-districts
{ zoningDistricts: Array<zoningDistrict> }
tax-lots/<bbl>/zoning-districts/classes
{ zoningDistrictClasses: Array<zoningDistrictClass> }
zoning-districts/<uuid>/classes
{ zoningDistrictClasses: Array<zoningDistrictClass> }
zoning-district-classes
{ zoningDistrictClasses: Array<zoningDistrictClass> }
zoning-district-classes/category-colors
{ zoningDistrictClassCategoryColors: Array<zoningDistrictClassCategoryColor> }
The actual schema change will be to take the existing schema and nest it inside a property. For example, borough will go from:
main
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Borough'
to:
example branch
content:
application/json:
schema:
type: object
properties:
boroughs:
type: array
items:
$ref: '#/components/schemas/Borough'
From discussion #55, document the possible errors for zoning district endpoints
The following endpoints describe their listed error codes
zoning-districts/<uuid>
zoning-districts/<uuid>/classes
Blocked by #67
The Reusing Responses documentation describes how to use response components to describe a response on an endpoint. Use the appropriate responses created in ticket #67 to describe the responses for these endpoints.
From discussion #55, custom handled errors (in contrast to errors handled automatically by nest) should use exceptions with standardized messages. The standard messages are:
As these are the first error messages, we will need to create place to hold them (and any future exceptions). This structure is outlined in the first half of the acceptance criteria. An example of this structure is on the experimental branch exp/repo
. The custom errors are defined within an error
folder. An example of using the error is shown on tax-lot service, line 25
error
folder under the src
folder
message
file defines and exports error messages
exception
file defines and exports exceptions
index
file exports the definitions from the message
and exception
files to the rest of the applicationindex
file exports all messages and exceptionsA declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.