add post method to api
This commit is contained in:
427
api/methods.py
427
api/methods.py
@ -5,7 +5,8 @@
|
||||
# -----------------------------------------
|
||||
|
||||
|
||||
from db import dbGetMany, dbGetOne
|
||||
from db import dbGetMany, dbGetOne, dbInsert
|
||||
from loguru import logger
|
||||
|
||||
def get_accounts(user, token_info):
|
||||
return dbGetMany(user, token_info, {
|
||||
@ -21,6 +22,29 @@ SELECT
|
||||
}
|
||||
)
|
||||
|
||||
def insert_account(user, token_info, **args):
|
||||
try:
|
||||
body = args["body"]
|
||||
v_description = body["description"]
|
||||
return dbInsert(user, token_info, {
|
||||
"statement": """
|
||||
INSERT INTO account_t
|
||||
(
|
||||
description
|
||||
) VALUES (
|
||||
%s
|
||||
)
|
||||
RETURNING *
|
||||
""",
|
||||
"params": [
|
||||
v_description
|
||||
]
|
||||
})
|
||||
except KeyError as e:
|
||||
logger.warning("insert_account: parameter missing: {}".format(e))
|
||||
raise werkzeug.exceptions.UnprocessableEntity("parameter missing: {}".format(e))
|
||||
|
||||
|
||||
def get_account(user, token_info, accountId=None):
|
||||
return dbGetOne(user, token_info, {
|
||||
"statement": """
|
||||
@ -59,6 +83,73 @@ SELECT
|
||||
}
|
||||
)
|
||||
|
||||
def insert_tenant(user, token_info, **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"]
|
||||
v_account = body["account"]
|
||||
return dbInsert(user, token_info, {
|
||||
"statement": """
|
||||
INSERT INTO tenant_t
|
||||
(
|
||||
salutation
|
||||
,firstname
|
||||
,lastname
|
||||
,address1
|
||||
,address2
|
||||
,address3
|
||||
,zip
|
||||
,city
|
||||
,phone1
|
||||
,phone2
|
||||
,iban
|
||||
,account
|
||||
) VALUES (
|
||||
%s
|
||||
,%s
|
||||
,%s
|
||||
,%s
|
||||
,%s
|
||||
,%s
|
||||
,%s
|
||||
,%s
|
||||
,%s
|
||||
,%s
|
||||
,%s
|
||||
,%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
|
||||
,v_account
|
||||
]
|
||||
})
|
||||
except KeyError as e:
|
||||
logger.warning("insert_tenant: parameter missing: {}".format(e))
|
||||
raise werkzeug.exceptions.UnprocessableEntity("parameter missing: {}".format(e))
|
||||
|
||||
|
||||
def get_tenant(user, token_info, tenantId=None):
|
||||
return dbGetOne(user, token_info, {
|
||||
"statement": """
|
||||
@ -99,6 +190,41 @@ SELECT
|
||||
}
|
||||
)
|
||||
|
||||
def insert_premise(user, token_info, **args):
|
||||
try:
|
||||
body = args["body"]
|
||||
v_description = body["description"]
|
||||
v_street = body["street"]
|
||||
v_zip = body["zip"]
|
||||
v_city = body["city"]
|
||||
return dbInsert(user, token_info, {
|
||||
"statement": """
|
||||
INSERT INTO premise_t
|
||||
(
|
||||
description
|
||||
,street
|
||||
,zip
|
||||
,city
|
||||
) VALUES (
|
||||
%s
|
||||
,%s
|
||||
,%s
|
||||
,%s
|
||||
)
|
||||
RETURNING *
|
||||
""",
|
||||
"params": [
|
||||
v_description
|
||||
,v_street
|
||||
,v_zip
|
||||
,v_city
|
||||
]
|
||||
})
|
||||
except KeyError as e:
|
||||
logger.warning("insert_premise: parameter missing: {}".format(e))
|
||||
raise werkzeug.exceptions.UnprocessableEntity("parameter missing: {}".format(e))
|
||||
|
||||
|
||||
def get_premise(user, token_info, premiseId=None):
|
||||
return dbGetOne(user, token_info, {
|
||||
"statement": """
|
||||
@ -132,6 +258,41 @@ SELECT
|
||||
}
|
||||
)
|
||||
|
||||
def insert_flat(user, token_info, **args):
|
||||
try:
|
||||
body = args["body"]
|
||||
v_description = body["description"]
|
||||
v_premise = body["premise"]
|
||||
v_area = body["area"]
|
||||
v_flat_no = body["flat_no"]
|
||||
return dbInsert(user, token_info, {
|
||||
"statement": """
|
||||
INSERT INTO flat_t
|
||||
(
|
||||
description
|
||||
,premise
|
||||
,area
|
||||
,flat_no
|
||||
) VALUES (
|
||||
%s
|
||||
,%s
|
||||
,%s
|
||||
,%s
|
||||
)
|
||||
RETURNING *
|
||||
""",
|
||||
"params": [
|
||||
v_description
|
||||
,v_premise
|
||||
,v_area
|
||||
,v_flat_no
|
||||
]
|
||||
})
|
||||
except KeyError as e:
|
||||
logger.warning("insert_flat: parameter missing: {}".format(e))
|
||||
raise werkzeug.exceptions.UnprocessableEntity("parameter missing: {}".format(e))
|
||||
|
||||
|
||||
def get_flat(user, token_info, flatId=None):
|
||||
return dbGetOne(user, token_info, {
|
||||
"statement": """
|
||||
@ -165,6 +326,41 @@ SELECT
|
||||
}
|
||||
)
|
||||
|
||||
def insert_overhead_advance(user, token_info, **args):
|
||||
try:
|
||||
body = args["body"]
|
||||
v_description = body["description"]
|
||||
v_amount = body["amount"]
|
||||
v_startdate = body["startdate"]
|
||||
v_enddate = body["enddate"]
|
||||
return dbInsert(user, token_info, {
|
||||
"statement": """
|
||||
INSERT INTO overhead_advance_t
|
||||
(
|
||||
description
|
||||
,amount
|
||||
,startdate
|
||||
,enddate
|
||||
) VALUES (
|
||||
%s
|
||||
,%s
|
||||
,%s
|
||||
,%s
|
||||
)
|
||||
RETURNING *
|
||||
""",
|
||||
"params": [
|
||||
v_description
|
||||
,v_amount
|
||||
,v_startdate
|
||||
,v_enddate
|
||||
]
|
||||
})
|
||||
except KeyError as e:
|
||||
logger.warning("insert_overhead_advance: parameter missing: {}".format(e))
|
||||
raise werkzeug.exceptions.UnprocessableEntity("parameter missing: {}".format(e))
|
||||
|
||||
|
||||
def get_overhead_advance(user, token_info, overhead_advanceId=None):
|
||||
return dbGetOne(user, token_info, {
|
||||
"statement": """
|
||||
@ -196,6 +392,33 @@ SELECT
|
||||
}
|
||||
)
|
||||
|
||||
def insert_overhead_advance_flat_mapping(user, token_info, **args):
|
||||
try:
|
||||
body = args["body"]
|
||||
v_overhead_advance = body["overhead_advance"]
|
||||
v_flat = body["flat"]
|
||||
return dbInsert(user, token_info, {
|
||||
"statement": """
|
||||
INSERT INTO overhead_advance_flat_mapping_t
|
||||
(
|
||||
overhead_advance
|
||||
,flat
|
||||
) VALUES (
|
||||
%s
|
||||
,%s
|
||||
)
|
||||
RETURNING *
|
||||
""",
|
||||
"params": [
|
||||
v_overhead_advance
|
||||
,v_flat
|
||||
]
|
||||
})
|
||||
except KeyError as e:
|
||||
logger.warning("insert_overhead_advance_flat_mapping: parameter missing: {}".format(e))
|
||||
raise werkzeug.exceptions.UnprocessableEntity("parameter missing: {}".format(e))
|
||||
|
||||
|
||||
def get_overhead_advance_flat_mapping(user, token_info, overhead_advance_flat_mappingId=None):
|
||||
return dbGetOne(user, token_info, {
|
||||
"statement": """
|
||||
@ -225,6 +448,33 @@ SELECT
|
||||
}
|
||||
)
|
||||
|
||||
def insert_parking(user, token_info, **args):
|
||||
try:
|
||||
body = args["body"]
|
||||
v_description = body["description"]
|
||||
v_premise = body["premise"]
|
||||
return dbInsert(user, token_info, {
|
||||
"statement": """
|
||||
INSERT INTO parking_t
|
||||
(
|
||||
description
|
||||
,premise
|
||||
) VALUES (
|
||||
%s
|
||||
,%s
|
||||
)
|
||||
RETURNING *
|
||||
""",
|
||||
"params": [
|
||||
v_description
|
||||
,v_premise
|
||||
]
|
||||
})
|
||||
except KeyError as e:
|
||||
logger.warning("insert_parking: parameter missing: {}".format(e))
|
||||
raise werkzeug.exceptions.UnprocessableEntity("parameter missing: {}".format(e))
|
||||
|
||||
|
||||
def get_parking(user, token_info, parkingId=None):
|
||||
return dbGetOne(user, token_info, {
|
||||
"statement": """
|
||||
@ -254,6 +504,33 @@ SELECT
|
||||
}
|
||||
)
|
||||
|
||||
def insert_commercial_premise(user, token_info, **args):
|
||||
try:
|
||||
body = args["body"]
|
||||
v_description = body["description"]
|
||||
v_premise = body["premise"]
|
||||
return dbInsert(user, token_info, {
|
||||
"statement": """
|
||||
INSERT INTO commercial_premise_t
|
||||
(
|
||||
description
|
||||
,premise
|
||||
) VALUES (
|
||||
%s
|
||||
,%s
|
||||
)
|
||||
RETURNING *
|
||||
""",
|
||||
"params": [
|
||||
v_description
|
||||
,v_premise
|
||||
]
|
||||
})
|
||||
except KeyError as e:
|
||||
logger.warning("insert_commercial_premise: parameter missing: {}".format(e))
|
||||
raise werkzeug.exceptions.UnprocessableEntity("parameter missing: {}".format(e))
|
||||
|
||||
|
||||
def get_commercial_premise(user, token_info, commercial_premiseId=None):
|
||||
return dbGetOne(user, token_info, {
|
||||
"statement": """
|
||||
@ -288,6 +565,53 @@ SELECT
|
||||
}
|
||||
)
|
||||
|
||||
def insert_tenancy(user, token_info, **args):
|
||||
try:
|
||||
body = args["body"]
|
||||
v_description = body["description"]
|
||||
v_tenant = body["tenant"]
|
||||
v_flat = body["flat"]
|
||||
v_parking = body["parking"]
|
||||
v_commercial_premise = body["commercial_premise"]
|
||||
v_startdate = body["startdate"]
|
||||
v_enddate = body["enddate"]
|
||||
return dbInsert(user, token_info, {
|
||||
"statement": """
|
||||
INSERT INTO tenancy_t
|
||||
(
|
||||
description
|
||||
,tenant
|
||||
,flat
|
||||
,parking
|
||||
,commercial_premise
|
||||
,startdate
|
||||
,enddate
|
||||
) VALUES (
|
||||
%s
|
||||
,%s
|
||||
,%s
|
||||
,%s
|
||||
,%s
|
||||
,%s
|
||||
,%s
|
||||
)
|
||||
RETURNING *
|
||||
""",
|
||||
"params": [
|
||||
v_description
|
||||
,v_tenant
|
||||
,v_flat
|
||||
,v_parking
|
||||
,v_commercial_premise
|
||||
,v_startdate
|
||||
,v_enddate
|
||||
]
|
||||
})
|
||||
except KeyError as e:
|
||||
logger.warning("insert_tenancy: parameter missing: {}".format(e))
|
||||
raise werkzeug.exceptions.UnprocessableEntity("parameter missing: {}".format(e))
|
||||
|
||||
|
||||
def get_tenancy(user, token_info, tenancyId=None):
|
||||
return dbGetOne(user, token_info, {
|
||||
"statement": """
|
||||
@ -325,6 +649,45 @@ SELECT
|
||||
}
|
||||
)
|
||||
|
||||
def insert_fee(user, token_info, **args):
|
||||
try:
|
||||
body = args["body"]
|
||||
v_description = body["description"]
|
||||
v_amount = body["amount"]
|
||||
v_fee_type = body["fee_type"]
|
||||
v_startdate = body["startdate"]
|
||||
v_enddate = body["enddate"]
|
||||
return dbInsert(user, token_info, {
|
||||
"statement": """
|
||||
INSERT INTO fee_t
|
||||
(
|
||||
description
|
||||
,amount
|
||||
,fee_type
|
||||
,startdate
|
||||
,enddate
|
||||
) VALUES (
|
||||
%s
|
||||
,%s
|
||||
,%s
|
||||
,%s
|
||||
,%s
|
||||
)
|
||||
RETURNING *
|
||||
""",
|
||||
"params": [
|
||||
v_description
|
||||
,v_amount
|
||||
,v_fee_type
|
||||
,v_startdate
|
||||
,v_enddate
|
||||
]
|
||||
})
|
||||
except KeyError as e:
|
||||
logger.warning("insert_fee: parameter missing: {}".format(e))
|
||||
raise werkzeug.exceptions.UnprocessableEntity("parameter missing: {}".format(e))
|
||||
|
||||
|
||||
def get_fee(user, token_info, feeId=None):
|
||||
return dbGetOne(user, token_info, {
|
||||
"statement": """
|
||||
@ -354,6 +717,33 @@ SELECT
|
||||
}
|
||||
)
|
||||
|
||||
def insert_tenancy_fee_mapping(user, token_info, **args):
|
||||
try:
|
||||
body = args["body"]
|
||||
v_tenancy = body["tenancy"]
|
||||
v_fee = body["fee"]
|
||||
return dbInsert(user, token_info, {
|
||||
"statement": """
|
||||
INSERT INTO tenancy_fee_mapping_t
|
||||
(
|
||||
tenancy
|
||||
,fee
|
||||
) VALUES (
|
||||
%s
|
||||
,%s
|
||||
)
|
||||
RETURNING *
|
||||
""",
|
||||
"params": [
|
||||
v_tenancy
|
||||
,v_fee
|
||||
]
|
||||
})
|
||||
except KeyError as e:
|
||||
logger.warning("insert_tenancy_fee_mapping: parameter missing: {}".format(e))
|
||||
raise werkzeug.exceptions.UnprocessableEntity("parameter missing: {}".format(e))
|
||||
|
||||
|
||||
def get_tenancy_fee_mapping(user, token_info, tenancy_fee_mappingId=None):
|
||||
return dbGetOne(user, token_info, {
|
||||
"statement": """
|
||||
@ -382,6 +772,41 @@ SELECT
|
||||
}
|
||||
)
|
||||
|
||||
def insert_account_entry(user, token_info, **args):
|
||||
try:
|
||||
body = args["body"]
|
||||
v_description = body["description"]
|
||||
v_account = body["account"]
|
||||
v_created_at = body["created_at"]
|
||||
v_amount = body["amount"]
|
||||
return dbInsert(user, token_info, {
|
||||
"statement": """
|
||||
INSERT INTO account_entry_t
|
||||
(
|
||||
description
|
||||
,account
|
||||
,created_at
|
||||
,amount
|
||||
) VALUES (
|
||||
%s
|
||||
,%s
|
||||
,%s
|
||||
,%s
|
||||
)
|
||||
RETURNING *
|
||||
""",
|
||||
"params": [
|
||||
v_description
|
||||
,v_account
|
||||
,v_created_at
|
||||
,v_amount
|
||||
]
|
||||
})
|
||||
except KeyError as e:
|
||||
logger.warning("insert_account_entry: parameter missing: {}".format(e))
|
||||
raise werkzeug.exceptions.UnprocessableEntity("parameter missing: {}".format(e))
|
||||
|
||||
|
||||
def get_account_entry(user, token_info, account_entryId=None):
|
||||
return dbGetOne(user, token_info, {
|
||||
"statement": """
|
||||
|
Reference in New Issue
Block a user