Added openapi specs for construction and construction catalog

This commit is contained in:
Peter Yefi 2023-01-20 13:41:46 -05:00
parent c462d75e08
commit fdd4a31ac0
2 changed files with 315 additions and 4 deletions

View File

@ -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.material import Material
from catalog_factories.data_models.construction.window import Window from catalog_factories.data_models.construction.window import Window
from hub_api.helpers.session_helper import refresh_session from hub_api.helpers.session_helper import refresh_session
from hub_api.helpers.auth import role_required
from persistence.models import UserRoles
class ToJson: class ToJson:
@ -96,8 +98,8 @@ class ConstructionCatalogEntry(Resource):
def __init__(self): def __init__(self):
pass pass
@staticmethod @role_required([UserRoles.Admin.value, UserRoles.Hub_Reader.value])
def post(): def post(self):
session = refresh_session(request) session = refresh_session(request)
if session is None: if session is None:
return Response(json.dumps({'error': 'invalid session'}), status=401) return Response(json.dumps({'error': 'invalid session'}), status=401)
@ -129,8 +131,8 @@ class ConstructionCatalogEntries(Resource):
def __init__(self): def __init__(self):
pass pass
@staticmethod @role_required([UserRoles.Admin.value, UserRoles.Hub_Reader.value])
def post(): def post(self):
session = refresh_session(request) session = refresh_session(request)
if session is None: if session is None:
return Response(json.dumps({'error': 'invalid session'}), status=401) return Response(json.dumps({'error': 'invalid session'}), status=401)

View File

@ -342,6 +342,180 @@ paths:
application/json: application/json:
schema: schema:
$ref: '#/components/schemas/ApiResponse' $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: components:
schemas: schemas:
City: City:
@ -472,6 +646,132 @@ components:
items: items:
type: float type: float
example: [ 610.610, 754.746, 288.338 ] 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: User:
type: object type: object
properties: properties:
@ -484,6 +784,7 @@ components:
example: Peter Yefi example: Peter Yefi
email: email:
type: string type: string
format: email
example: peteryefi@gmail.com example: peteryefi@gmail.com
password: password:
type: string type: string
@ -493,6 +794,11 @@ components:
enum: enum:
- Admin - Admin
- Hub_Reader - Hub_Reader
required:
- name
- email
- password
- role
HeatPumpRes: HeatPumpRes:
type: object type: object
properties: properties:
@ -525,6 +831,9 @@ components:
password: password:
type: string type: string
example: 'Hub@183838' example: 'Hub@183838'
required:
- email
- password
LoginRes: LoginRes:
type: object type: object
properties: properties: