diff --git a/api/db.py b/api/db.py index 987b8f3..cbceade 100644 --- a/api/db.py +++ b/api/db.py @@ -112,3 +112,11 @@ def dbInsert(user, token_info, params): except Exception as e: logger.error(f"Exception: {e}") raise werkzeug.exceptions.InternalServerError + +def dbUpdate(user, token_info, params): + logger.info("params: {}, token: {}".format(params, json.dumps(token_info))) + try: + return execDatabaseOperation(_opGetOne, params) + except Exception as e: + logger.error(f"Exception: {e}") + raise werkzeug.exceptions.InternalServerError diff --git a/api/methods.py b/api/methods.py index 4ecc2d5..0ddfb72 100644 --- a/api/methods.py +++ b/api/methods.py @@ -5,8 +5,9 @@ # ----------------------------------------- -from db import dbGetMany, dbGetOne, dbInsert +from db import dbGetMany, dbGetOne, dbInsert, dbUpdate from loguru import logger +import werkzeug def get_accounts(user, token_info): return dbGetMany(user, token_info, { @@ -57,6 +58,28 @@ SELECT "params": (accountId, ) } ) + +def update_account(user, token_info, accountId=None, **args): + try: + body = args["body"] + v_description = body["description"] + return dbUpdate(user, token_info, { + "statement": """ +UPDATE account_t + SET + description = %s + WHERE id = %s + RETURNING * +""", + "params": [ + v_description, + accountId + ] + }) + except KeyError as e: + logger.warning("update_account: parameter missing: {}".format(e)) + raise werkzeug.exceptions.UnprocessableEntity("parameter missing: {}".format(e)) + def get_tenants(user, token_info): return dbGetMany(user, token_info, { "statement": """ @@ -173,6 +196,58 @@ SELECT "params": (tenantId, ) } ) + +def update_tenant(user, token_info, tenantId=None, **args): + try: + body = args["body"] + v_salutation = body["salutation"] + v_firstname = body["firstname"] + v_lastname = body["lastname"] + v_address1 = body["address1"] + v_address2 = body["address2"] + v_address3 = body["address3"] + v_zip = body["zip"] + v_city = body["city"] + v_phone1 = body["phone1"] + v_phone2 = body["phone2"] + v_iban = body["iban"] + return dbUpdate(user, token_info, { + "statement": """ +UPDATE tenant_t + SET + salutation = %s + ,firstname = %s + ,lastname = %s + ,address1 = %s + ,address2 = %s + ,address3 = %s + ,zip = %s + ,city = %s + ,phone1 = %s + ,phone2 = %s + ,iban = %s + WHERE id = %s + RETURNING * +""", + "params": [ + v_salutation, + v_firstname, + v_lastname, + v_address1, + v_address2, + v_address3, + v_zip, + v_city, + v_phone1, + v_phone2, + v_iban, + tenantId + ] + }) + except KeyError as e: + logger.warning("update_tenant: parameter missing: {}".format(e)) + raise werkzeug.exceptions.UnprocessableEntity("parameter missing: {}".format(e)) + def get_premises(user, token_info): return dbGetMany(user, token_info, { "statement": """ @@ -240,6 +315,37 @@ SELECT "params": (premiseId, ) } ) + +def update_premise(user, token_info, premiseId=None, **args): + try: + body = args["body"] + v_description = body["description"] + v_street = body["street"] + v_zip = body["zip"] + v_city = body["city"] + return dbUpdate(user, token_info, { + "statement": """ +UPDATE premise_t + SET + description = %s + ,street = %s + ,zip = %s + ,city = %s + WHERE id = %s + RETURNING * +""", + "params": [ + v_description, + v_street, + v_zip, + v_city, + premiseId + ] + }) + except KeyError as e: + logger.warning("update_premise: parameter missing: {}".format(e)) + raise werkzeug.exceptions.UnprocessableEntity("parameter missing: {}".format(e)) + def get_flats(user, token_info): return dbGetMany(user, token_info, { "statement": """ @@ -308,6 +414,37 @@ SELECT "params": (flatId, ) } ) + +def update_flat(user, token_info, flatId=None, **args): + try: + body = args["body"] + v_description = body["description"] + v_premise = body["premise"] + v_area = body["area"] + v_flat_no = body["flat_no"] + return dbUpdate(user, token_info, { + "statement": """ +UPDATE flat_t + SET + description = %s + ,premise = %s + ,area = %s + ,flat_no = %s + WHERE id = %s + RETURNING * +""", + "params": [ + v_description, + v_premise, + v_area, + v_flat_no, + flatId + ] + }) + except KeyError as e: + logger.warning("update_flat: parameter missing: {}".format(e)) + raise werkzeug.exceptions.UnprocessableEntity("parameter missing: {}".format(e)) + def get_overhead_advances(user, token_info): return dbGetMany(user, token_info, { "statement": """ @@ -376,6 +513,31 @@ SELECT "params": (overhead_advanceId, ) } ) + +def update_overhead_advance(user, token_info, overhead_advanceId=None, **args): + try: + body = args["body"] + v_description = body["description"] + v_enddate = body["enddate"] + return dbUpdate(user, token_info, { + "statement": """ +UPDATE overhead_advance_t + SET + description = %s + ,enddate = %s + WHERE id = %s + RETURNING * +""", + "params": [ + v_description, + v_enddate, + overhead_advanceId + ] + }) + except KeyError as e: + logger.warning("update_overhead_advance: parameter missing: {}".format(e)) + raise werkzeug.exceptions.UnprocessableEntity("parameter missing: {}".format(e)) + def get_overhead_advance_flat_mappings(user, token_info): return dbGetMany(user, token_info, { "statement": """ @@ -432,6 +594,8 @@ SELECT "params": (overhead_advance_flat_mappingId, ) } ) + + def get_parkings(user, token_info): return dbGetMany(user, token_info, { "statement": """ @@ -488,6 +652,31 @@ SELECT "params": (parkingId, ) } ) + +def update_parking(user, token_info, parkingId=None, **args): + try: + body = args["body"] + v_description = body["description"] + v_premise = body["premise"] + return dbUpdate(user, token_info, { + "statement": """ +UPDATE parking_t + SET + description = %s + ,premise = %s + WHERE id = %s + RETURNING * +""", + "params": [ + v_description, + v_premise, + parkingId + ] + }) + except KeyError as e: + logger.warning("update_parking: parameter missing: {}".format(e)) + raise werkzeug.exceptions.UnprocessableEntity("parameter missing: {}".format(e)) + def get_commercial_premises(user, token_info): return dbGetMany(user, token_info, { "statement": """ @@ -544,6 +733,31 @@ SELECT "params": (commercial_premiseId, ) } ) + +def update_commercial_premise(user, token_info, commercial_premiseId=None, **args): + try: + body = args["body"] + v_description = body["description"] + v_premise = body["premise"] + return dbUpdate(user, token_info, { + "statement": """ +UPDATE commercial_premise_t + SET + description = %s + ,premise = %s + WHERE id = %s + RETURNING * +""", + "params": [ + v_description, + v_premise, + commercial_premiseId + ] + }) + except KeyError as e: + logger.warning("update_commercial_premise: parameter missing: {}".format(e)) + raise werkzeug.exceptions.UnprocessableEntity("parameter missing: {}".format(e)) + def get_tenancys(user, token_info): return dbGetMany(user, token_info, { "statement": """ @@ -630,6 +844,31 @@ SELECT "params": (tenancyId, ) } ) + +def update_tenancy(user, token_info, tenancyId=None, **args): + try: + body = args["body"] + v_description = body["description"] + v_enddate = body["enddate"] + return dbUpdate(user, token_info, { + "statement": """ +UPDATE tenancy_t + SET + description = %s + ,enddate = %s + WHERE id = %s + RETURNING * +""", + "params": [ + v_description, + v_enddate, + tenancyId + ] + }) + except KeyError as e: + logger.warning("update_tenancy: parameter missing: {}".format(e)) + raise werkzeug.exceptions.UnprocessableEntity("parameter missing: {}".format(e)) + def get_fees(user, token_info): return dbGetMany(user, token_info, { "statement": """ @@ -704,6 +943,31 @@ SELECT "params": (feeId, ) } ) + +def update_fee(user, token_info, feeId=None, **args): + try: + body = args["body"] + v_description = body["description"] + v_enddate = body["enddate"] + return dbUpdate(user, token_info, { + "statement": """ +UPDATE fee_t + SET + description = %s + ,enddate = %s + WHERE id = %s + RETURNING * +""", + "params": [ + v_description, + v_enddate, + feeId + ] + }) + except KeyError as e: + logger.warning("update_fee: parameter missing: {}".format(e)) + raise werkzeug.exceptions.UnprocessableEntity("parameter missing: {}".format(e)) + def get_tenancy_fee_mappings(user, token_info): return dbGetMany(user, token_info, { "statement": """ @@ -757,6 +1021,8 @@ SELECT "params": (tenancy_fee_mappingId, ) } ) + + def get_account_entrys(user, token_info): return dbGetMany(user, token_info, { "statement": """ @@ -822,3 +1088,5 @@ SELECT "params": (account_entryId, ) } ) + + diff --git a/api/methods.py.tmpl b/api/methods.py.tmpl index 1a2c00e..07acb70 100644 --- a/api/methods.py.tmpl +++ b/api/methods.py.tmpl @@ -1,7 +1,8 @@ $GENERATED_PYTHON_COMMENT -from db import dbGetMany, dbGetOne, dbInsert +from db import dbGetMany, dbGetOne, dbInsert, dbUpdate from loguru import logger +import werkzeug #for $table in $tables def get_${table.name}s(user, token_info): @@ -77,4 +78,42 @@ SELECT "params": (${table.name}Id, ) } ) + +#if (('immutable' not in $table) or (not $table.immutable)) +def update_${table.name}(user, token_info, ${table.name}Id=None, **args): + try: + body = args["body"] +#for $column in $table.columns +#if (('immutable' not in $column) or (not $column.immutable)) + v_$column.name = body["$column.name"] +#end if +#end for + return dbUpdate(user, token_info, { + "statement": """ +UPDATE ${table.name}_t + SET +#set $sep="" +#for $column in $table.columns +#if (('immutable' not in $column) or (not $column.immutable)) + $sep$column.name = %s +#end if +#set $sep="," +#end for + WHERE id = %s + RETURNING * +""", + "params": [ +#for $column in $table.columns +#if (('immutable' not in $column) or (not $column.immutable)) + v_${column.name}, +#end if +#end for + ${table.name}Id + ] + }) + except KeyError as e: + logger.warning("update_${table.name}: parameter missing: {}".format(e)) + raise werkzeug.exceptions.UnprocessableEntity("parameter missing: {}".format(e)) +#end if + #end for diff --git a/api/openapi.yaml b/api/openapi.yaml index 6c4718e..c14c732 100644 --- a/api/openapi.yaml +++ b/api/openapi.yaml @@ -56,6 +56,27 @@ paths: $ref: '#/components/schemas/account' security: - jwt: ['secret'] + put: + tags: [ "account" ] + summary: Update a account + operationId: methods.update_account + requestBody: + description: account + content: + application/json: + schema: + $ref: '#/components/schemas/account' + responses: + '200': + description: account successfully inserted + content: + 'application/json': + schema: + type: array + items: + $ref: '#/components/schemas/account' + security: + - jwt: ['secret'] /v1/accounts/{accountId}: get: tags: [ "account" ] @@ -78,6 +99,33 @@ paths: $ref: '#/components/schemas/account' security: - jwt: ['secret'] + put: + tags: [ "account" ] + summary: Update a account + operationId: methods.update_account + parameters: + - name: accountId + in: path + required: true + schema: + type: integer + requestBody: + description: account + content: + application/json: + schema: + $ref: '#/components/schemas/account' + responses: + '200': + description: account successfully inserted + content: + 'application/json': + schema: + type: array + items: + $ref: '#/components/schemas/account' + security: + - jwt: ['secret'] /v1/tenants: get: tags: [ "tenant" ] @@ -115,6 +163,27 @@ paths: $ref: '#/components/schemas/tenant' security: - jwt: ['secret'] + put: + tags: [ "tenant" ] + summary: Update a tenant + operationId: methods.update_tenant + requestBody: + description: tenant + content: + application/json: + schema: + $ref: '#/components/schemas/tenant' + responses: + '200': + description: tenant successfully inserted + content: + 'application/json': + schema: + type: array + items: + $ref: '#/components/schemas/tenant' + security: + - jwt: ['secret'] /v1/tenants/{tenantId}: get: tags: [ "tenant" ] @@ -137,6 +206,33 @@ paths: $ref: '#/components/schemas/tenant' security: - jwt: ['secret'] + put: + tags: [ "tenant" ] + summary: Update a tenant + operationId: methods.update_tenant + parameters: + - name: tenantId + in: path + required: true + schema: + type: integer + requestBody: + description: tenant + content: + application/json: + schema: + $ref: '#/components/schemas/tenant' + responses: + '200': + description: tenant successfully inserted + content: + 'application/json': + schema: + type: array + items: + $ref: '#/components/schemas/tenant' + security: + - jwt: ['secret'] /v1/premises: get: tags: [ "premise" ] @@ -174,6 +270,27 @@ paths: $ref: '#/components/schemas/premise' security: - jwt: ['secret'] + put: + tags: [ "premise" ] + summary: Update a premise + operationId: methods.update_premise + requestBody: + description: premise + content: + application/json: + schema: + $ref: '#/components/schemas/premise' + responses: + '200': + description: premise successfully inserted + content: + 'application/json': + schema: + type: array + items: + $ref: '#/components/schemas/premise' + security: + - jwt: ['secret'] /v1/premises/{premiseId}: get: tags: [ "premise" ] @@ -196,6 +313,33 @@ paths: $ref: '#/components/schemas/premise' security: - jwt: ['secret'] + put: + tags: [ "premise" ] + summary: Update a premise + operationId: methods.update_premise + parameters: + - name: premiseId + in: path + required: true + schema: + type: integer + requestBody: + description: premise + content: + application/json: + schema: + $ref: '#/components/schemas/premise' + responses: + '200': + description: premise successfully inserted + content: + 'application/json': + schema: + type: array + items: + $ref: '#/components/schemas/premise' + security: + - jwt: ['secret'] /v1/flats: get: tags: [ "flat" ] @@ -233,6 +377,27 @@ paths: $ref: '#/components/schemas/flat' security: - jwt: ['secret'] + put: + tags: [ "flat" ] + summary: Update a flat + operationId: methods.update_flat + requestBody: + description: flat + content: + application/json: + schema: + $ref: '#/components/schemas/flat' + responses: + '200': + description: flat successfully inserted + content: + 'application/json': + schema: + type: array + items: + $ref: '#/components/schemas/flat' + security: + - jwt: ['secret'] /v1/flats/{flatId}: get: tags: [ "flat" ] @@ -255,6 +420,33 @@ paths: $ref: '#/components/schemas/flat' security: - jwt: ['secret'] + put: + tags: [ "flat" ] + summary: Update a flat + operationId: methods.update_flat + parameters: + - name: flatId + in: path + required: true + schema: + type: integer + requestBody: + description: flat + content: + application/json: + schema: + $ref: '#/components/schemas/flat' + responses: + '200': + description: flat successfully inserted + content: + 'application/json': + schema: + type: array + items: + $ref: '#/components/schemas/flat' + security: + - jwt: ['secret'] /v1/overhead_advances: get: tags: [ "overhead_advance" ] @@ -292,6 +484,27 @@ paths: $ref: '#/components/schemas/overhead_advance' security: - jwt: ['secret'] + put: + tags: [ "overhead_advance" ] + summary: Update a overhead_advance + operationId: methods.update_overhead_advance + requestBody: + description: overhead_advance + content: + application/json: + schema: + $ref: '#/components/schemas/overhead_advance' + responses: + '200': + description: overhead_advance successfully inserted + content: + 'application/json': + schema: + type: array + items: + $ref: '#/components/schemas/overhead_advance' + security: + - jwt: ['secret'] /v1/overhead_advances/{overhead_advanceId}: get: tags: [ "overhead_advance" ] @@ -314,6 +527,33 @@ paths: $ref: '#/components/schemas/overhead_advance' security: - jwt: ['secret'] + put: + tags: [ "overhead_advance" ] + summary: Update a overhead_advance + operationId: methods.update_overhead_advance + parameters: + - name: overhead_advanceId + in: path + required: true + schema: + type: integer + requestBody: + description: overhead_advance + content: + application/json: + schema: + $ref: '#/components/schemas/overhead_advance' + responses: + '200': + description: overhead_advance successfully inserted + content: + 'application/json': + schema: + type: array + items: + $ref: '#/components/schemas/overhead_advance' + security: + - jwt: ['secret'] /v1/overhead_advance_flat_mappings: get: tags: [ "overhead_advance_flat_mapping" ] @@ -351,6 +591,27 @@ paths: $ref: '#/components/schemas/overhead_advance_flat_mapping' security: - jwt: ['secret'] + put: + tags: [ "overhead_advance_flat_mapping" ] + summary: Update a overhead_advance_flat_mapping + operationId: methods.update_overhead_advance_flat_mapping + requestBody: + description: overhead_advance_flat_mapping + content: + application/json: + schema: + $ref: '#/components/schemas/overhead_advance_flat_mapping' + responses: + '200': + description: overhead_advance_flat_mapping successfully inserted + content: + 'application/json': + schema: + type: array + items: + $ref: '#/components/schemas/overhead_advance_flat_mapping' + security: + - jwt: ['secret'] /v1/overhead_advance_flat_mappings/{overhead_advance_flat_mappingId}: get: tags: [ "overhead_advance_flat_mapping" ] @@ -410,6 +671,27 @@ paths: $ref: '#/components/schemas/parking' security: - jwt: ['secret'] + put: + tags: [ "parking" ] + summary: Update a parking + operationId: methods.update_parking + requestBody: + description: parking + content: + application/json: + schema: + $ref: '#/components/schemas/parking' + responses: + '200': + description: parking successfully inserted + content: + 'application/json': + schema: + type: array + items: + $ref: '#/components/schemas/parking' + security: + - jwt: ['secret'] /v1/parkings/{parkingId}: get: tags: [ "parking" ] @@ -432,6 +714,33 @@ paths: $ref: '#/components/schemas/parking' security: - jwt: ['secret'] + put: + tags: [ "parking" ] + summary: Update a parking + operationId: methods.update_parking + parameters: + - name: parkingId + in: path + required: true + schema: + type: integer + requestBody: + description: parking + content: + application/json: + schema: + $ref: '#/components/schemas/parking' + responses: + '200': + description: parking successfully inserted + content: + 'application/json': + schema: + type: array + items: + $ref: '#/components/schemas/parking' + security: + - jwt: ['secret'] /v1/commercial_premises: get: tags: [ "commercial_premise" ] @@ -469,6 +778,27 @@ paths: $ref: '#/components/schemas/commercial_premise' security: - jwt: ['secret'] + put: + tags: [ "commercial_premise" ] + summary: Update a commercial_premise + operationId: methods.update_commercial_premise + requestBody: + description: commercial_premise + content: + application/json: + schema: + $ref: '#/components/schemas/commercial_premise' + responses: + '200': + description: commercial_premise successfully inserted + content: + 'application/json': + schema: + type: array + items: + $ref: '#/components/schemas/commercial_premise' + security: + - jwt: ['secret'] /v1/commercial_premises/{commercial_premiseId}: get: tags: [ "commercial_premise" ] @@ -491,6 +821,33 @@ paths: $ref: '#/components/schemas/commercial_premise' security: - jwt: ['secret'] + put: + tags: [ "commercial_premise" ] + summary: Update a commercial_premise + operationId: methods.update_commercial_premise + parameters: + - name: commercial_premiseId + in: path + required: true + schema: + type: integer + requestBody: + description: commercial_premise + content: + application/json: + schema: + $ref: '#/components/schemas/commercial_premise' + responses: + '200': + description: commercial_premise successfully inserted + content: + 'application/json': + schema: + type: array + items: + $ref: '#/components/schemas/commercial_premise' + security: + - jwt: ['secret'] /v1/tenancys: get: tags: [ "tenancy" ] @@ -528,6 +885,27 @@ paths: $ref: '#/components/schemas/tenancy' security: - jwt: ['secret'] + put: + tags: [ "tenancy" ] + summary: Update a tenancy + operationId: methods.update_tenancy + requestBody: + description: tenancy + content: + application/json: + schema: + $ref: '#/components/schemas/tenancy' + responses: + '200': + description: tenancy successfully inserted + content: + 'application/json': + schema: + type: array + items: + $ref: '#/components/schemas/tenancy' + security: + - jwt: ['secret'] /v1/tenancys/{tenancyId}: get: tags: [ "tenancy" ] @@ -550,6 +928,33 @@ paths: $ref: '#/components/schemas/tenancy' security: - jwt: ['secret'] + put: + tags: [ "tenancy" ] + summary: Update a tenancy + operationId: methods.update_tenancy + parameters: + - name: tenancyId + in: path + required: true + schema: + type: integer + requestBody: + description: tenancy + content: + application/json: + schema: + $ref: '#/components/schemas/tenancy' + responses: + '200': + description: tenancy successfully inserted + content: + 'application/json': + schema: + type: array + items: + $ref: '#/components/schemas/tenancy' + security: + - jwt: ['secret'] /v1/fees: get: tags: [ "fee" ] @@ -587,6 +992,27 @@ paths: $ref: '#/components/schemas/fee' security: - jwt: ['secret'] + put: + tags: [ "fee" ] + summary: Update a fee + operationId: methods.update_fee + requestBody: + description: fee + content: + application/json: + schema: + $ref: '#/components/schemas/fee' + responses: + '200': + description: fee successfully inserted + content: + 'application/json': + schema: + type: array + items: + $ref: '#/components/schemas/fee' + security: + - jwt: ['secret'] /v1/fees/{feeId}: get: tags: [ "fee" ] @@ -609,6 +1035,33 @@ paths: $ref: '#/components/schemas/fee' security: - jwt: ['secret'] + put: + tags: [ "fee" ] + summary: Update a fee + operationId: methods.update_fee + parameters: + - name: feeId + in: path + required: true + schema: + type: integer + requestBody: + description: fee + content: + application/json: + schema: + $ref: '#/components/schemas/fee' + responses: + '200': + description: fee successfully inserted + content: + 'application/json': + schema: + type: array + items: + $ref: '#/components/schemas/fee' + security: + - jwt: ['secret'] /v1/tenancy_fee_mappings: get: tags: [ "tenancy_fee_mapping" ] @@ -646,6 +1099,27 @@ paths: $ref: '#/components/schemas/tenancy_fee_mapping' security: - jwt: ['secret'] + put: + tags: [ "tenancy_fee_mapping" ] + summary: Update a tenancy_fee_mapping + operationId: methods.update_tenancy_fee_mapping + requestBody: + description: tenancy_fee_mapping + content: + application/json: + schema: + $ref: '#/components/schemas/tenancy_fee_mapping' + responses: + '200': + description: tenancy_fee_mapping successfully inserted + content: + 'application/json': + schema: + type: array + items: + $ref: '#/components/schemas/tenancy_fee_mapping' + security: + - jwt: ['secret'] /v1/tenancy_fee_mappings/{tenancy_fee_mappingId}: get: tags: [ "tenancy_fee_mapping" ] @@ -705,6 +1179,27 @@ paths: $ref: '#/components/schemas/account_entry' security: - jwt: ['secret'] + put: + tags: [ "account_entry" ] + summary: Update a account_entry + operationId: methods.update_account_entry + requestBody: + description: account_entry + content: + application/json: + schema: + $ref: '#/components/schemas/account_entry' + responses: + '200': + description: account_entry successfully inserted + content: + 'application/json': + schema: + type: array + items: + $ref: '#/components/schemas/account_entry' + security: + - jwt: ['secret'] /v1/account_entrys/{account_entryId}: get: tags: [ "account_entry" ] diff --git a/api/openapi.yaml.tmpl b/api/openapi.yaml.tmpl index 47e3c4b..be67921 100644 --- a/api/openapi.yaml.tmpl +++ b/api/openapi.yaml.tmpl @@ -52,6 +52,27 @@ paths: \$ref: '#/components/schemas/$table.name' security: - jwt: ['secret'] + put: + tags: [ "$table.name" ] + summary: Update a ${table.name} + operationId: methods.update_${table.name} + requestBody: + description: $table.name + content: + application/json: + schema: + \$ref: '#/components/schemas/$table.name' + responses: + '200': + description: ${table.name} successfully inserted + content: + 'application/json': + schema: + type: array + items: + \$ref: '#/components/schemas/$table.name' + security: + - jwt: ['secret'] /v1/${table.name}s/{${table.name}Id}: get: tags: [ "$table.name" ] @@ -74,6 +95,35 @@ paths: \$ref: '#/components/schemas/$table.name' security: - jwt: ['secret'] +#if (('immutable' not in $table) or (not $table.immutable)) + put: + tags: [ "$table.name" ] + summary: Update a ${table.name} + operationId: methods.update_${table.name} + parameters: + - name: ${table.name}Id + in: path + required: true + schema: + type: integer + requestBody: + description: $table.name + content: + application/json: + schema: + \$ref: '#/components/schemas/$table.name' + responses: + '200': + description: ${table.name} successfully inserted + content: + 'application/json': + schema: + type: array + items: + \$ref: '#/components/schemas/$table.name' + security: + - jwt: ['secret'] +#end if #end for components: diff --git a/schema.json b/schema.json index 7b9eb76..e76fc6d 100644 --- a/schema.json +++ b/schema.json @@ -20,7 +20,7 @@ { "name": "phone1", "sqltype": "varchar(64)" }, { "name": "phone2", "sqltype": "varchar(64)" }, { "name": "iban", "sqltype": "varchar(64)" }, - { "name": "account", "sqltype": "integer", "notnull": true, "foreignkey": true } + { "name": "account", "sqltype": "integer", "notnull": true, "foreignkey": true, "immutable": true } ] }, { @@ -45,13 +45,14 @@ "name": "overhead_advance", "columns": [ { "name": "description", "sqltype": "varchar(128)", "selector": 0 }, - { "name": "amount", "sqltype": "numeric(10,4)", "notnull": true }, - { "name": "startdate", "sqltype": "date", "selector": 1 }, + { "name": "amount", "sqltype": "numeric(10,4)", "notnull": true, "immutable": true }, + { "name": "startdate", "sqltype": "date", "selector": 1, "immutable": true }, { "name": "enddate", "sqltype": "date" } ] }, { "name": "overhead_advance_flat_mapping", + "immutable": true, "columns": [ { "name": "overhead_advance", "sqltype": "integer", "notnull": true, "foreignkey": true, "selector": 0 }, { "name": "flat", "sqltype": "integer", "notnull": true, "foreignkey": true, "selector": 1 } @@ -75,11 +76,11 @@ "name": "tenancy", "columns": [ { "name": "description", "sqltype": "varchar(128)", "selector": 0 }, - { "name": "tenant", "sqltype": "integer", "notnull": true, "foreignkey": true }, - { "name": "flat", "sqltype": "integer", "notnull": false, "foreignkey": true }, - { "name": "parking", "sqltype": "integer", "notnull": false, "foreignkey": true }, - { "name": "commercial_premise", "sqltype": "integer", "notnull": false, "foreignkey": true }, - { "name": "startdate", "sqltype": "date", "notnull": true, "selector": 1 }, + { "name": "tenant", "sqltype": "integer", "notnull": true, "foreignkey": true, "immutable": true }, + { "name": "flat", "sqltype": "integer", "notnull": false, "foreignkey": true, "immutable": true }, + { "name": "parking", "sqltype": "integer", "notnull": false, "foreignkey": true, "immutable": true }, + { "name": "commercial_premise", "sqltype": "integer", "notnull": false, "foreignkey": true, "immutable": true }, + { "name": "startdate", "sqltype": "date", "notnull": true, "selector": 1, "immutable": true }, { "name": "enddate", "sqltype": "date", "notnull": false } ], "tableConstraints": [ @@ -90,9 +91,9 @@ "name": "fee", "columns": [ { "name": "description", "sqltype": "varchar(128)", "selector": 0 }, - { "name": "amount", "sqltype": "numeric(10,2)", "notnull": true }, - { "name": "fee_type", "sqltype": "varchar(10)", "notnull": true }, - { "name": "startdate", "sqltype": "date", "selector": 1 }, + { "name": "amount", "sqltype": "numeric(10,2)", "notnull": true, "immutable": true }, + { "name": "fee_type", "sqltype": "varchar(10)", "notnull": true, "immutable": true }, + { "name": "startdate", "sqltype": "date", "selector": 1, "immutable": true }, { "name": "enddate", "sqltype": "date" } ], "tableConstraints": [ @@ -101,6 +102,7 @@ }, { "name": "tenancy_fee_mapping", + "immutable": true, "columns": [ { "name": "tenancy", "sqltype": "integer", "notnull": true, "foreignkey": true }, { "name": "fee", "sqltype": "integer", "notnull": true, "foreignkey": true } @@ -108,6 +110,7 @@ }, { "name": "account_entry", + "immutable": true, "columns": [ { "name": "description", "sqltype": "varchar(128)", "notnull": true }, { "name": "account", "sqltype": "integer", "notnull": true, "foreignkey": true }, diff --git a/ui/hv2-ui/src/app/config.ts b/ui/hv2-ui/src/app/config.ts index 7144afb..3b143eb 100644 --- a/ui/hv2-ui/src/app/config.ts +++ b/ui/hv2-ui/src/app/config.ts @@ -2,4 +2,4 @@ // export const serviceBaseUrl = "http://172.16.10.38:5000"; export const serviceBaseUrl = "http://localhost:8080" export const authserviceBaseUrl = "https://authservice.hottis.de" - +export const applicationId = "hv2" diff --git a/ui/hv2-ui/src/app/data-object-service.ts b/ui/hv2-ui/src/app/data-object-service.ts index e98a5df..860aa26 100644 --- a/ui/hv2-ui/src/app/data-object-service.ts +++ b/ui/hv2-ui/src/app/data-object-service.ts @@ -7,8 +7,7 @@ import { Injectable } from '@angular/core'; -import { Observable, of } from 'rxjs'; -import { HttpClient, HttpHeaders } from '@angular/common/http'; +import { HttpClient } from '@angular/common/http'; import { MessageService } from './message.service'; import { serviceBaseUrl } from './config'; @@ -54,6 +53,13 @@ export class AccountService { return this.http.post(`${serviceBaseUrl}/v1/accounts`, item).toPromise() } + async putAccount(item: Account): Promise { + let itemStr: string = JSON.stringify(item, undefined, 4) + this.messageService.add(`AccountService: put data for ${itemStr}`) + let id: number = item["id"] + return this.http.put(`${serviceBaseUrl}/v1/accounts/${id}`, item).toPromise() + } + } @Injectable({ providedIn: 'root' }) @@ -76,6 +82,13 @@ export class TenantService { return this.http.post(`${serviceBaseUrl}/v1/tenants`, item).toPromise() } + async putTenant(item: Tenant): Promise { + let itemStr: string = JSON.stringify(item, undefined, 4) + this.messageService.add(`TenantService: put data for ${itemStr}`) + let id: number = item["id"] + return this.http.put(`${serviceBaseUrl}/v1/tenants/${id}`, item).toPromise() + } + } @Injectable({ providedIn: 'root' }) @@ -98,6 +111,13 @@ export class PremiseService { return this.http.post(`${serviceBaseUrl}/v1/premises`, item).toPromise() } + async putPremise(item: Premise): Promise { + let itemStr: string = JSON.stringify(item, undefined, 4) + this.messageService.add(`PremiseService: put data for ${itemStr}`) + let id: number = item["id"] + return this.http.put(`${serviceBaseUrl}/v1/premises/${id}`, item).toPromise() + } + } @Injectable({ providedIn: 'root' }) @@ -120,6 +140,13 @@ export class FlatService { return this.http.post(`${serviceBaseUrl}/v1/flats`, item).toPromise() } + async putFlat(item: Flat): Promise { + let itemStr: string = JSON.stringify(item, undefined, 4) + this.messageService.add(`FlatService: put data for ${itemStr}`) + let id: number = item["id"] + return this.http.put(`${serviceBaseUrl}/v1/flats/${id}`, item).toPromise() + } + } @Injectable({ providedIn: 'root' }) @@ -142,6 +169,13 @@ export class OverheadAdvanceService { return this.http.post(`${serviceBaseUrl}/v1/overhead_advances`, item).toPromise() } + async putOverheadAdvance(item: OverheadAdvance): Promise { + let itemStr: string = JSON.stringify(item, undefined, 4) + this.messageService.add(`OverheadAdvanceService: put data for ${itemStr}`) + let id: number = item["id"] + return this.http.put(`${serviceBaseUrl}/v1/overhead_advances/${id}`, item).toPromise() + } + } @Injectable({ providedIn: 'root' }) @@ -164,6 +198,7 @@ export class OverheadAdvanceFlatMappingService { return this.http.post(`${serviceBaseUrl}/v1/overhead_advance_flat_mappings`, item).toPromise() } + } @Injectable({ providedIn: 'root' }) @@ -186,6 +221,13 @@ export class ParkingService { return this.http.post(`${serviceBaseUrl}/v1/parkings`, item).toPromise() } + async putParking(item: Parking): Promise { + let itemStr: string = JSON.stringify(item, undefined, 4) + this.messageService.add(`ParkingService: put data for ${itemStr}`) + let id: number = item["id"] + return this.http.put(`${serviceBaseUrl}/v1/parkings/${id}`, item).toPromise() + } + } @Injectable({ providedIn: 'root' }) @@ -208,6 +250,13 @@ export class CommercialPremiseService { return this.http.post(`${serviceBaseUrl}/v1/commercial_premises`, item).toPromise() } + async putCommercialPremise(item: CommercialPremise): Promise { + let itemStr: string = JSON.stringify(item, undefined, 4) + this.messageService.add(`CommercialPremiseService: put data for ${itemStr}`) + let id: number = item["id"] + return this.http.put(`${serviceBaseUrl}/v1/commercial_premises/${id}`, item).toPromise() + } + } @Injectable({ providedIn: 'root' }) @@ -230,6 +279,13 @@ export class TenancyService { return this.http.post(`${serviceBaseUrl}/v1/tenancys`, item).toPromise() } + async putTenancy(item: Tenancy): Promise { + let itemStr: string = JSON.stringify(item, undefined, 4) + this.messageService.add(`TenancyService: put data for ${itemStr}`) + let id: number = item["id"] + return this.http.put(`${serviceBaseUrl}/v1/tenancys/${id}`, item).toPromise() + } + } @Injectable({ providedIn: 'root' }) @@ -252,6 +308,13 @@ export class FeeService { return this.http.post(`${serviceBaseUrl}/v1/fees`, item).toPromise() } + async putFee(item: Fee): Promise { + let itemStr: string = JSON.stringify(item, undefined, 4) + this.messageService.add(`FeeService: put data for ${itemStr}`) + let id: number = item["id"] + return this.http.put(`${serviceBaseUrl}/v1/fees/${id}`, item).toPromise() + } + } @Injectable({ providedIn: 'root' }) @@ -274,6 +337,7 @@ export class TenancyFeeMappingService { return this.http.post(`${serviceBaseUrl}/v1/tenancy_fee_mappings`, item).toPromise() } + } @Injectable({ providedIn: 'root' }) @@ -296,6 +360,7 @@ export class AccountEntryService { return this.http.post(`${serviceBaseUrl}/v1/account_entrys`, item).toPromise() } + } diff --git a/ui/hv2-ui/src/app/data-object-service.ts.tmpl b/ui/hv2-ui/src/app/data-object-service.ts.tmpl index 19591a5..4db6e92 100644 --- a/ui/hv2-ui/src/app/data-object-service.ts.tmpl +++ b/ui/hv2-ui/src/app/data-object-service.ts.tmpl @@ -2,8 +2,7 @@ $GENERATED_TS_COMMENT import { Injectable } from '@angular/core'; -import { Observable, of } from 'rxjs'; -import { HttpClient, HttpHeaders } from '@angular/common/http'; +import { HttpClient } from '@angular/common/http'; import { MessageService } from './message.service'; import { serviceBaseUrl } from './config'; @@ -42,6 +41,15 @@ export class ${JsNameConverter($table.name)}Service { return this.http.post<${JsNameConverter($table.name)}>(`\${serviceBaseUrl}/v1/${table.name}s`, item).toPromise() } +#if (('immutable' not in $table) or (not $table.immutable)) + async put${JsNameConverter($table.name)}(item: ${JsNameConverter($table.name)}): Promise<${JsNameConverter($table.name)}> { + let itemStr: string = JSON.stringify(item, undefined, 4) + this.messageService.add(`${JsNameConverter($table.name)}Service: put data for \${itemStr}`) + let id: number = item["id"] + return this.http.put<${JsNameConverter($table.name)}>(`\${serviceBaseUrl}/v1/${table.name}s/\${id}`, item).toPromise() + } +#end if + } #end for diff --git a/ui/hv2-ui/src/app/token.service.ts b/ui/hv2-ui/src/app/token.service.ts index 5a02acc..b63089a 100644 --- a/ui/hv2-ui/src/app/token.service.ts +++ b/ui/hv2-ui/src/app/token.service.ts @@ -5,7 +5,7 @@ import { UserCreds } from './userCreds' import jwt_decode from 'jwt-decode' import { Observable, interval, Subject, Subscription } from 'rxjs' import { map, takeWhile } from 'rxjs/operators' -import { authserviceBaseUrl } from './config' +import { authserviceBaseUrl, applicationId } from './config' interface TokenTuple { @@ -66,7 +66,7 @@ export class TokenService { async login(login: string, password: string) : Promise { this.messageService.add(`TokenService: trying to login and obtain token`) const userCreds : UserCreds = { - "application": "hv2", + "application": applicationId, "login": login, "password": password }