From fdd4a31ac0412be5397a7dafa663b91327a15257 Mon Sep 17 00:00:00 2001 From: Peter Yefi Date: Fri, 20 Jan 2023 13:41:46 -0500 Subject: [PATCH 1/2] Added openapi specs for construction and construction catalog --- hub_api/construction_catalog.py | 10 +- hub_api/docs/openapi-specs.yml | 309 ++++++++++++++++++++++++++++++++ 2 files changed, 315 insertions(+), 4 deletions(-) diff --git a/hub_api/construction_catalog.py b/hub_api/construction_catalog.py index b1c50d7..8607026 100644 --- a/hub_api/construction_catalog.py +++ b/hub_api/construction_catalog.py @@ -14,6 +14,8 @@ from catalog_factories.data_models.construction.construction import Construction from catalog_factories.data_models.construction.material import Material from catalog_factories.data_models.construction.window import Window from hub_api.helpers.session_helper import refresh_session +from hub_api.helpers.auth import role_required +from persistence.models import UserRoles class ToJson: @@ -96,8 +98,8 @@ class ConstructionCatalogEntry(Resource): def __init__(self): pass - @staticmethod - def post(): + @role_required([UserRoles.Admin.value, UserRoles.Hub_Reader.value]) + def post(self): session = refresh_session(request) if session is None: return Response(json.dumps({'error': 'invalid session'}), status=401) @@ -129,8 +131,8 @@ class ConstructionCatalogEntries(Resource): def __init__(self): pass - @staticmethod - def post(): + @role_required([UserRoles.Admin.value, UserRoles.Hub_Reader.value]) + def post(self): session = refresh_session(request) if session is None: return Response(json.dumps({'error': 'invalid session'}), status=401) diff --git a/hub_api/docs/openapi-specs.yml b/hub_api/docs/openapi-specs.yml index 78be2be..73d3dde 100644 --- a/hub_api/docs/openapi-specs.yml +++ b/hub_api/docs/openapi-specs.yml @@ -342,6 +342,180 @@ paths: application/json: schema: $ref: '#/components/schemas/ApiResponse' + /v1.4/construction/{city_id}: + put: + tags: + - construction + summary: updates a city with building construction + description: updates a city with building construction + operationId: updateConstruction + parameters: + - in: header + name: appId + schema: + type: string + required: true + description: the Id of the application access this API + - in: path + name: city_id + schema: + type: integer + required: true + description: Numeric ID of the city to get + requestBody: + description: creates building construction catalog + content: + application/json: + schema: + $ref: '#/components/schemas/Construction' + application/xml: + schema: + $ref: '#/components/schemas/Construction' + responses: + '201': + description: city updated with building construction successfully + content: + application/json: + schema: + $ref: '#/components/schemas/Construction' + '400': + description: Bad Request + content: + application/json: + schema: + $ref: '#/components/schemas/ApiResponse' + '403': + description: Forbidden + content: + application/json: + schema: + $ref: '#/components/schemas/ApiResponse' + '401': + description: Unauthorized + content: + application/json: + schema: + $ref: '#/components/schemas/ApiResponse' + '500': + description: Internal server error + content: + application/json: + schema: + $ref: '#/components/schemas/ApiResponse' + security: + - BearerAuth: [ ] + /v1.4/construction-catalog/entries: + post: + tags: + - construction-catalog + summary: creates building construction catalog entries + description: create the construction catalog entries + operationId: catalogEntries + parameters: + - in: header + name: appId + schema: + type: string + required: true + description: the Id of the application access this API + requestBody: + description: creates building construction catalog + content: + application/json: + schema: + $ref: '#/components/schemas/ConstructionCatalogEntries' + application/xml: + schema: + $ref: '#/components/schemas/ConstructionCatalogEntries' + responses: + '201': + description: Construction catalog entries created successfully + content: + application/json: + schema: + $ref: '#/components/schemas/ConstructionCatalogEntries' + '400': + description: Bad Request + content: + application/json: + schema: + $ref: '#/components/schemas/ApiResponse' + '403': + description: Forbidden + content: + application/json: + schema: + $ref: '#/components/schemas/ApiResponse' + '401': + description: Unauthorized + content: + application/json: + schema: + $ref: '#/components/schemas/ApiResponse' + '500': + description: Internal server error + content: + application/json: + schema: + $ref: '#/components/schemas/ApiResponse' + security: + - BearerAuth: [ ] + /v1.4/construction-catalog/entry: + post: + tags: + - construction-catalog + summary: creates building construction catalog + description: create the construction catalog of a building + operationId: catalogEntry + parameters: + - in: header + name: appId + schema: + type: string + required: true + description: the Id of the application access this API + requestBody: + description: creates building construction catalog + content: + application/json: + schema: + $ref: '#/components/schemas/ConstructionCatalogEntry' + application/xml: + schema: + $ref: '#/components/schemas/ConstructionCatalogEntry' + responses: + '201': + description: Construction catalog created successfully + content: + application/json: + schema: + $ref: '#/components/schemas/ConstructionCatalogEntry' + '400': + description: Bad Request + content: + application/json: + schema: + $ref: '#/components/schemas/ApiResponse' + '403': + description: Forbidden + content: + application/json: + schema: + $ref: '#/components/schemas/ApiResponse' + '401': + description: Unauthorized + content: + application/json: + schema: + $ref: '#/components/schemas/ApiResponse' + '500': + description: Internal server error + content: + application/json: + schema: + $ref: '#/components/schemas/ApiResponse' + security: + - BearerAuth: [ ] components: schemas: City: @@ -472,6 +646,132 @@ components: items: type: float example: [ 610.610, 754.746, 288.338 ] + required: + - SimType + - EnergyDemand + - HeatPumpModel + - HeatPumpType + - FuelEF + - FuelDensity + - FuelPrice + - FuelLHV + - BuildingSuppTemp + - TemperatureDifference + - HoursOfStorageAtMaxDemand + - MaximumHPEnergyInput + - StartYear + - EndYear + ConstructionCatalogEntry: + type: object + properties: + name: + type: string + example: 189.1-2009 Nonres 4B Ext Wall Mass + required: + - name + ConstructionCatalogEntries: + type: object + properties: + category: + type: string + example: archetypes + required: + - category + Construction: + type: object + properties: + building_names: + type: array + items: + type: string + example: ["Dompark"] + extra_loses_due_to_thermal_bridges: + type: float + example: 0.15 + indirect_heated_ratio: + type: float + example: 0.15 + infiltration_rate_for_ventilation_system_off: + type: float + example: 0.5 + infiltration_rate_for_ventilation_system_on: + type: float + example: 0.0 + constructions: + type: array + items: + type: object + properties: + name: + type: string + example: 189.1-2009 Res 4B Ext Wall Steel-Framed + type: + type: string + example: Wall + layers: + type: array + items: + type: object + $ref: '#components/schemas/Layers' + + required: + - building_names + - extra_loses_due_to_thermal_bridges + - indirect_heated_ratio + - infiltration_rate_for_ventilation_system_off + - infiltration_rate_for_ventilation_system_on + - constructions + Layers: + type: object + properties: + name: + type: string + example: Layer 1 + thickness: + type: float + example: 0.0 + material: + type: object + $ref: '#/components/schemas/Material' + Material: + type: object + properties: + id: + type: integer + format: int64 + example: 12 + name: + type: string + example: MAT-SHEAT + solar_absorptance: + type: float + example: 0.7 + thermal_absorptance: + type: float + example: 0.9 + visible_absorptance: + type: float + example: 0.7 + no_mass: + type: string + example: "True" + thermal_resistance: + type: float + example: 0.36256 + conductivity: + type: string + density: + type: string + specific_heat: + type: string + required: + - id + - name + - solar_absorptance + - thermal_absorptance + - visible_absorptance + - no_mass + - thermal_resistance User: type: object properties: @@ -484,6 +784,7 @@ components: example: Peter Yefi email: type: string + format: email example: peteryefi@gmail.com password: type: string @@ -493,6 +794,11 @@ components: enum: - Admin - Hub_Reader + required: + - name + - email + - password + - role HeatPumpRes: type: object properties: @@ -525,6 +831,9 @@ components: password: type: string example: 'Hub@183838' + required: + - email + - password LoginRes: type: object properties: From bc76ac86d1995a3e6851101d3bbdba7eae35a17b Mon Sep 17 00:00:00 2001 From: Peter Yefi Date: Fri, 20 Jan 2023 14:01:40 -0500 Subject: [PATCH 2/2] Added documentation for energy demand --- hub_api/docs/openapi-specs.yml | 73 +++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/hub_api/docs/openapi-specs.yml b/hub_api/docs/openapi-specs.yml index 73d3dde..0eed27a 100644 --- a/hub_api/docs/openapi-specs.yml +++ b/hub_api/docs/openapi-specs.yml @@ -342,6 +342,59 @@ paths: application/json: schema: $ref: '#/components/schemas/ApiResponse' + /v1.4/energy-demand/{city_id}: + get: + tags: + - energy-demand + summary: Get energy demand + description: Retrieve energy demand data + operationId: getEnergyDemand + parameters: + - in: header + name: appId + schema: + type: string + required: true + description: the Id of the application access this API + - in: path + name: city_id + schema: + type: integer + required: true + description: Numeric ID of the city to get + responses: + '200': + description: Successfully retrieved energy demand data + content: + application/json: + schema: + $ref: '#/components/schemas/EnergyDemand' + '400': + description: Bad Request + content: + application/json: + schema: + $ref: '#/components/schemas/ApiResponse' + '403': + description: Forbidden + content: + application/json: + schema: + $ref: '#/components/schemas/ApiResponse' + '401': + description: Unauthorized + content: + application/json: + schema: + $ref: '#/components/schemas/ApiResponse' + '500': + description: Internal server error + content: + application/json: + schema: + $ref: '#/components/schemas/ApiResponse' + security: + - BearerAuth: [ ] /v1.4/construction/{city_id}: put: tags: @@ -713,7 +766,6 @@ components: items: type: object $ref: '#components/schemas/Layers' - required: - building_names - extra_loses_due_to_thermal_bridges @@ -822,6 +874,25 @@ components: type: array items: type: object + EnergyDemand: + type: object + properties: + heating_demand: + type: array + items: + type: object + cooling_demand: + type: array + items: + type: object + lighting_demand: + type: array + items: + type: object + appliances_demand: + type: array + items: + type: object Login: type: object properties: