add contracts

This commit is contained in:
2023-01-02 14:46:59 +01:00
parent 10b7f89831
commit 07dff73152
36 changed files with 1671 additions and 45 deletions

View File

@ -11,19 +11,6 @@ ARG CONF_DIR="${APP_DIR}/config"
RUN \
apt update && \
apt install -y postgresql-client-common && \
pip3 install psycopg2 && \
pip3 install dateparser && \
pip3 install connexion && \
pip3 install connexion[swagger-ui] && \
pip3 install uwsgi && \
pip3 install flask-cors && \
pip3 install python-jose[cryptography] && \
pip3 install loguru && \
pip3 install Cheetah3
RUN \
mkdir -p ${APP_DIR} && \
mkdir -p ${CONF_DIR} && \
useradd -d ${APP_DIR} -u 1000 user
@ -31,11 +18,15 @@ RUN \
COPY *.py ${APP_DIR}/
COPY openapi.yaml ${APP_DIR}/
COPY methods.py ${APP_DIR}/
COPY requirements.txt ${APP_DIR}/
COPY server.ini ${CONF_DIR}/
WORKDIR ${APP_DIR}
VOLUME ${CONF_DIR}
RUN \
pip3 install -r requirements.txt
USER 1000:1000
EXPOSE 5000

View File

@ -1584,3 +1584,103 @@ SELECT
}
)
def get_contracts(user, token_info):
return dbGetMany(user, token_info, {
"statement": """
SELECT
id
,supplier
,content
,identifier
,notes
FROM contract_t
ORDER BY
supplier
,content
""",
"params": ()
}
)
def insert_contract(user, token_info, **args):
try:
body = args["body"]
v_supplier = body["supplier"]
v_content = body["content"]
v_identifier = body["identifier"]
v_notes = body["notes"]
return dbInsert(user, token_info, {
"statement": """
INSERT INTO contract_t
(
supplier
,content
,identifier
,notes
) VALUES (
%s
,%s
,%s
,%s
)
RETURNING *
""",
"params": [
v_supplier
,v_content
,v_identifier
,v_notes
]
})
except KeyError as e:
logger.warning("insert_contract: parameter missing: {}".format(e))
raise werkzeug.exceptions.UnprocessableEntity("parameter missing: {}".format(e))
def get_contract(user, token_info, contractId=None):
return dbGetOne(user, token_info, {
"statement": """
SELECT
id
,supplier
,content
,identifier
,notes
FROM contract_t
WHERE id = %s
""",
"params": (contractId, )
}
)
def update_contract(user, token_info, contractId=None, **args):
try:
body = args["body"]
v_supplier = body["supplier"]
v_content = body["content"]
v_identifier = body["identifier"]
v_notes = body["notes"]
return dbUpdate(user, token_info, {
"statement": """
UPDATE contract_t
SET
supplier = %s
,content = %s
,identifier = %s
,notes = %s
WHERE id = %s
RETURNING *
""",
"params": [
v_supplier,
v_content,
v_identifier,
v_notes,
contractId
]
})
except KeyError as e:
logger.warning("update_contract: parameter missing: {}".format(e))
raise werkzeug.exceptions.UnprocessableEntity("parameter missing: {}".format(e))

View File

@ -1440,6 +1440,92 @@ paths:
$ref: '#/components/schemas/note'
security:
- jwt: ['secret']
/v1/contracts:
get:
tags: [ "contract" ]
summary: Return all normalized contracts
operationId: methods.get_contracts
responses:
'200':
description: contracts response
content:
'application/json':
schema:
type: array
items:
$ref: '#/components/schemas/contract'
security:
- jwt: ['secret']
post:
tags: [ "contract" ]
summary: Insert a contract
operationId: methods.insert_contract
requestBody:
description: contract
content:
application/json:
schema:
$ref: '#/components/schemas/contract'
responses:
'200':
description: contract successfully inserted
content:
'application/json':
schema:
type: array
items:
$ref: '#/components/schemas/contract'
security:
- jwt: ['secret']
/v1/contracts/{contractId}:
get:
tags: [ "contract" ]
summary: Return the normalized contract with given id
operationId: methods.get_contract
parameters:
- name: contractId
in: path
required: true
schema:
type: integer
responses:
'200':
description: contract response
content:
'application/json':
schema:
type: array
items:
$ref: '#/components/schemas/contract'
security:
- jwt: ['secret']
put:
tags: [ "contract" ]
summary: Update a contract
operationId: methods.update_contract
parameters:
- name: contractId
in: path
required: true
schema:
type: integer
requestBody:
description: contract
content:
application/json:
schema:
$ref: '#/components/schemas/contract'
responses:
'200':
description: contract successfully inserted
content:
'application/json':
schema:
type: array
items:
$ref: '#/components/schemas/contract'
security:
- jwt: ['secret']
# -------------------------------------------------------------------
# ATTENTION: This file will not be parsed by Cheetah
@ -1818,6 +1904,21 @@ components:
type: integer
note:
type: string
contract:
description: contract
type: object
properties:
id:
type: integer
supplier:
type: string
content:
type: string
identifier:
type: string
notes:
type: string
nullable: true
# -------------------------------------------------------------------
# ATTENTION: This file will not be parsed by Cheetah

40
api/requirements.txt Normal file
View File

@ -0,0 +1,40 @@
attrs==22.2.0
certifi==2022.12.7
cffi==1.15.1
charset-normalizer==2.1.1
Cheetah3==3.2.6.post1
click==8.1.3
clickclick==20.10.2
connexion==2.14.1
cryptography==39.0.0
dateparser==1.1.5
ecdsa==0.18.0
Flask==2.2.2
Flask-Cors==3.0.10
idna==3.4
inflection==0.5.1
itsdangerous==2.1.2
Jinja2==3.1.2
jsonschema==4.17.3
loguru==0.6.0
MarkupSafe==2.1.1
packaging==22.0
psycopg2==2.9.5
pyasn1==0.4.8
pycparser==2.21
pyrsistent==0.19.3
python-dateutil==2.8.2
python-jose==3.3.0
pytz==2022.7
pytz-deprecation-shim==0.1.0.post0
PyYAML==6.0
regex==2022.10.31
requests==2.28.1
rsa==4.9
six==1.16.0
swagger-ui-bundle==0.0.9
tzdata==2022.7
tzlocal==4.2
urllib3==1.26.13
uWSGI==2.0.21
Werkzeug==2.2.2