6 Commits

6 changed files with 350 additions and 186 deletions

37
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,37 @@
stages:
- check
- dockerize
variables:
IMAGE_NAME: $CI_REGISTRY/$CI_PROJECT_PATH
check:
image: registry.hottis.de/dockerized/base-build-env:latest
stage: check
tags:
- hottis
- linux
- docker
rules:
- if: $CI_COMMIT_TAG
script:
- checksemver.py -v
--versionToValidate "$CI_COMMIT_TAG"
--validateMessage
--messageToValidate "$CI_COMMIT_MESSAGE"
dockerize:
image: registry.hottis.de/dockerized/docker-bash:latest
stage: dockerize
tags:
- hottis
- linux
- docker
rules:
- if: $CI_COMMIT_TAG
script:
- docker build --tag $IMAGE_NAME:latest --tag $IMAGE_NAME:$CI_COMMIT_TAG .
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker push $IMAGE_NAME:latest
- docker push $IMAGE_NAME:$CI_COMMIT_TAG

View File

@ -21,6 +21,29 @@ SELECT m.id as id,
w.id = m.wohnung w.id = m.wohnung
""", [], "Mieter") """, [], "Mieter")
def get_mieters_active():
return getMany("""
SELECT m.id as id,
o.id as objekt,
w.id as wohnung,
w.shortname as wohnung_shortname,
o.shortname as objekt_shortname,
COALESCE(m.anrede, '-') as anrede,
COALESCE(m.vorname, '-') as vorname,
m.nachname as nachname,
COALESCE(m.strasse, '-') as strasse,
COALESCE(m.plz, '-') as plz,
COALESCE(m.ort, '-') as ort,
COALESCE(m.telefon, '-') as telefon,
m.einzug as einzug,
COALESCE(m.auszug, '-') as auszug
FROM wohnung w, objekt o, mieter m
WHERE o.id = w.objekt AND
w.id = m.wohnung AND
m.einzug <= curdate() and
(m.auszug is null or m.auszug > curdate())
""", [], "Mieter")
def get_mieter(id=None): def get_mieter(id=None):
return getOne(""" return getOne("""
SELECT m.id as id, SELECT m.id as id,

View File

@ -1,4 +1,4 @@
from dbpool import getConnection, getOne, getMany, putOne from dbpool import getConnection, getOne, getMany, putOne, call
import datetime import datetime
import decimal import decimal
import dateparser import dateparser
@ -106,11 +106,22 @@ WHERE mieter = ? AND
"zahlungen": float(sumZ) "zahlungen": float(sumZ)
} }
def put_zahlung(zahlung): def put_zahlung(**args):
print("Input of put_zahlung: {} {}".format(type(zahlung), zahlung)) try:
datum_soll = dateparser.parse(zahlung["datum_soll"], languages=["de"]) body = args["body"]
datum_ist = dateparser.parse(zahlung["datum_ist"], languages=["de"]) datum_soll_raw = body["datum_soll"]
return putOne(""" datum_ist_raw = body["datum_ist"]
print("Input of put_zahlung: {}".format(body))
datum_soll = dateparser.parse(datum_soll_raw, languages=["de"])
datum_ist = dateparser.parse(datum_ist_raw, languages=["de"])
return putOne("""
INSERT INTO zahlung (datum_soll, datum_ist, mieter, betrag, kommentar) INSERT INTO zahlung (datum_soll, datum_ist, mieter, betrag, kommentar)
VALUES(?, ?, ?, ?, ?) VALUES(?, ?, ?, ?, ?)
""", [ datum_soll, datum_ist, zahlung["mieter"], zahlung["betrag"], zahlung["kommentar"] ], "Zahlung") """, [ datum_soll, datum_ist, body["mieter"], body["betrag"], body["kommentar"] ], "Zahlung")
except KeyError as e:
print("Some parameter missing: {}".format(e))
return str(e), 500
def insertAllForMonth():
return call("insert_monatl_miet_forderung")

View File

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
IMAGE_NAME="registry.hottis.de/hv/hv-service" IMAGE_NAME="registry.hottis.de/hv/hv-service"
VERSION=0.0.3 VERSION=0.0.4
docker build -t ${IMAGE_NAME}:${VERSION} . docker build -t ${IMAGE_NAME}:${VERSION} .
docker push ${IMAGE_NAME}:${VERSION} docker push ${IMAGE_NAME}:${VERSION}

View File

@ -83,6 +83,7 @@ def putOne(stmt, params, objName):
except mariadb.Error as err: except mariadb.Error as err:
dbh.rollback() dbh.rollback()
print("Database error in putOne({}): {}".format(objName, err)) print("Database error in putOne({}): {}".format(objName, err))
return str(err), 500
except Exception as err: except Exception as err:
dbh.rollback() dbh.rollback()
print("Error in putOne({}): {}".format(objName, err)) print("Error in putOne({}): {}".format(objName, err))
@ -93,4 +94,27 @@ def putOne(stmt, params, objName):
cur.close() cur.close()
if dbh: if dbh:
dbh.close() dbh.close()
def call(procName):
dbh = None
cur = None
try:
dbh = getConnection()
cur = dbh.cursor(dictionary=True)
cur.execute("CALL {}(null)".format(procName))
dbh.commit()
return "{} successfully called {}".format(procName), 202
except mariadb.Error as err:
dbh.rollback()
print("Database error in call {}: {}".format(procName, err))
return str(err), 500
except Exception as err:
dbh.rollback()
print("Some error in call {}: {}".format(procName, err))
return str(err), 500
finally:
print("return connection in call {}".format(procName))
if cur:
cur.close()
if dbh:
dbh.close()

View File

@ -1,4 +1,4 @@
swagger: '2.0' openapi: 3.0.0
info: info:
title: Hausverwaltung title: Hausverwaltung
version: "0.1" version: "0.1"
@ -12,10 +12,12 @@ paths:
responses: responses:
200: 200:
description: Successful response. description: Successful response.
schema: content:
type: array 'application/json':
items: schema:
$ref: '#/definitions/Objekt' type: array
items:
$ref: '#/components/schemas/Objekt'
404: 404:
description: No Objekte available description: No Objekte available
500: 500:
@ -28,13 +30,16 @@ paths:
parameters: parameters:
- name: id - name: id
in: path in: path
type: integer
required: true required: true
schema:
type: integer
responses: responses:
200: 200:
description: Successful response. description: Successful response.
schema: content:
$ref: '#/definitions/Objekt' 'application/json':
schema:
$ref: '#/components/schemas/Objekt'
404: 404:
description: Objekt not found description: Objekt not found
500: 500:
@ -47,10 +52,12 @@ paths:
responses: responses:
200: 200:
description: Successful response. description: Successful response.
schema: content:
type: array 'application/json':
items: schema:
$ref: '#/definitions/Wohnung' type: array
items:
$ref: '#/components/schemas/Wohnung'
404: 404:
description: No Wohnung available description: No Wohnung available
500: 500:
@ -63,15 +70,18 @@ paths:
parameters: parameters:
- name: id - name: id
in: path in: path
type: integer
required: true required: true
schema:
type: integer
responses: responses:
200: 200:
description: Successful response. description: Successful response.
schema: content:
type: array 'application/json':
items: schema:
$ref: '#/definitions/Wohnung' type: array
items:
$ref: '#/components/schemas/Wohnung'
404: 404:
description: No Wohnung available description: No Wohnung available
500: 500:
@ -84,13 +94,16 @@ paths:
parameters: parameters:
- name: id - name: id
in: path in: path
type: integer
required: true required: true
schema:
type: integer
responses: responses:
200: 200:
description: Successful response. description: Successful response.
schema: content:
$ref: '#/definitions/Wohnung' 'application/json':
schema:
$ref: '#/components/schemas/Wohnung'
404: 404:
description: Wohnung not found description: Wohnung not found
500: 500:
@ -103,10 +116,30 @@ paths:
responses: responses:
200: 200:
description: Successful response. description: Successful response.
schema: content:
type: array 'application/json':
items: schema:
$ref: '#/definitions/Mieter' type: array
items:
$ref: '#/components/schemas/Mieter'
404:
description: No Mieter available
500:
description: Some server error
/hv/mieters/active:
get:
tags: [ "Mieter" ]
operationId: Mieter.get_mieters_active
summary: Returns all currently active Mieters
responses:
200:
description: Successful response.
content:
'application/json':
schema:
type: array
items:
$ref: '#/components/schemas/Mieter'
404: 404:
description: No Mieter available description: No Mieter available
500: 500:
@ -119,13 +152,16 @@ paths:
parameters: parameters:
- name: id - name: id
in: path in: path
type: integer
required: true required: true
schema:
type: integer
responses: responses:
200: 200:
description: Successful response. description: Successful response.
schema: content:
$ref: '#/definitions/Mieter' 'application/json':
schema:
$ref: '#/components/schemas/Mieter'
404: 404:
description: Mieter not found description: Mieter not found
500: 500:
@ -138,13 +174,16 @@ paths:
parameters: parameters:
- name: id - name: id
in: path in: path
type: integer
required: true required: true
schema:
type: integer
responses: responses:
200: 200:
description: Successful response. description: Successful response.
schema: content:
$ref: '#/definitions/Forderung' 'application/json':
schema:
$ref: '#/components/schemas/Forderung'
404: 404:
description: Forderung not found description: Forderung not found
500: 500:
@ -157,15 +196,18 @@ paths:
parameters: parameters:
- name: mieter_id - name: mieter_id
in: path in: path
type: integer
required: true required: true
schema:
type: integer
responses: responses:
200: 200:
description: Successful response. description: Successful response.
schema: content:
type: array 'application/json':
items: schema:
$ref: '#/definitions/Forderung' type: array
items:
$ref: '#/components/schemas/Forderung'
404: 404:
description: No Forderung available description: No Forderung available
500: 500:
@ -178,13 +220,16 @@ paths:
parameters: parameters:
- name: id - name: id
in: path in: path
type: integer
required: true required: true
schema:
type: integer
responses: responses:
200: 200:
description: Successful response. description: Successful response.
schema: content:
$ref: '#/definitions/Zahlung' 'application/json':
schema:
$ref: '#/components/schemas/Zahlung'
404: 404:
description: Zahlung not found description: Zahlung not found
500: 500:
@ -197,15 +242,18 @@ paths:
parameters: parameters:
- name: mieter_id - name: mieter_id
in: path in: path
type: integer
required: true required: true
schema:
type: integer
responses: responses:
200: 200:
description: Successful response. description: Successful response.
schema: content:
type: array 'application/json':
items: schema:
$ref: '#/definitions/Zahlung' type: array
items:
$ref: '#/components/schemas/Zahlung'
404: 404:
description: No Zahlung available description: No Zahlung available
500: 500:
@ -218,19 +266,23 @@ paths:
parameters: parameters:
- name: mieter_id - name: mieter_id
in: path in: path
type: integer
required: true required: true
schema:
type: integer
- name: year - name: year
in: path in: path
type: integer
required: true required: true
schema:
type: integer
responses: responses:
200: 200:
description: Successful response description: Successful response
schema: content:
type: array 'application/json':
items: schema:
$ref: '#/definitions/ZahlungForderung' type: array
items:
$ref: '#/components/schemas/ZahlungForderung'
404: 404:
description: No ZahlungForderung available description: No ZahlungForderung available
500: 500:
@ -243,17 +295,21 @@ paths:
parameters: parameters:
- name: mieter_id - name: mieter_id
in: path in: path
type: integer
required: true required: true
schema:
type: integer
- name: year - name: year
in: path in: path
type: integer
required: true required: true
schema:
type: integer
responses: responses:
200: 200:
description: Successful response description: Successful response
schema: content:
$ref: '#/definitions/Saldo' 'application/json':
schema:
$ref: '#/components/schemas/Saldo'
404: 404:
description: Neither Forderungen nor Zahlungen available description: Neither Forderungen nor Zahlungen available
500: 500:
@ -263,134 +319,147 @@ paths:
tags: [ "Zahlung" ] tags: [ "Zahlung" ]
operationId: ZahlungenForderungen.put_zahlung operationId: ZahlungenForderungen.put_zahlung
summary: Inserts a new Zahlung summary: Inserts a new Zahlung
parameters: requestBody:
- name: zahlung description: Zahlung
in: body content:
schema: application/json:
$ref: '#/definitions/Zahlung' schema:
$ref: '#/components/schemas/Zahlung'
responses: responses:
202: 202:
description: Zahlung successfully inserted description: Zahlung successfully inserted
500: 500:
description: Some server or database error description: Some server or database error
/hv/forderung/insertAllForMonth:
post:
tags: [ "Forderung" ]
operationId: ZahlungenForderungen.insertAllForMonth
summary: Insert the Forderungen for the insertAllForMonth
responses:
202:
description: Forderungen successfully inserted
500:
description: Some server or database error
definitions:
Objekt: components:
description: Objekt type schemas:
type: object Objekt:
properties: description: Objekt type
id: type: object
type: integer properties:
shortname: id:
type: string type: integer
flaeche: shortname:
type: number type: string
Wohnung: flaeche:
description: Wohnung type type: number
type: object Wohnung:
properties: description: Wohnung type
id: type: object
type: integer properties:
objekt: id:
type: integer type: integer
shortname: objekt:
type: string type: integer
flaeche: shortname:
type: number type: string
objekt_shortname: flaeche:
type: string type: number
Mieter: objekt_shortname:
description: Mieter type type: string
type: object Mieter:
properties: description: Mieter type
id: type: object
type: integer properties:
objekt: id:
type: integer type: integer
wohnung: objekt:
type: integer type: integer
wohnung_shortname: wohnung:
type: string type: integer
objekt_shortname: wohnung_shortname:
type: string type: string
anrede: objekt_shortname:
type: string type: string
vorname: anrede:
type: string type: string
nachname: vorname:
type: string type: string
strasse: nachname:
type: string type: string
plz: strasse:
type: string type: string
ort: plz:
type: string type: string
telefon: ort:
type: string type: string
einzug: telefon:
type: string type: string
auszug: einzug:
type: string type: string
Forderung: auszug:
description: Forderung type type: string
type: object Forderung:
properties: description: Forderung type
id: type: object
type: integer properties:
mieter: id:
type: integer type: integer
datum: mieter:
type: string type: integer
betrag: datum:
type: number type: string
kommentar: betrag:
type: string type: number
ref_wohnung: kommentar:
type: number type: string
Zahlung: ref_wohnung:
description: Zahlung type type: number
type: object Zahlung:
properties: description: Zahlung type
id: type: object
type: integer properties:
mieter: id:
type: integer type: integer
datum_ist: mieter:
type: string type: integer
datum_soll: datum_ist:
type: string type: string
betrag: datum_soll:
type: number type: string
kommentar: betrag:
type: string type: number
ZahlungForderung: kommentar:
description: ZahlungForderung type type: string
type: object ZahlungForderung:
properties: description: ZahlungForderung type
zf_type: type: object
type: string properties:
id: zf_type:
type: integer type: string
datum_soll: id:
type: string type: integer
datum_ist: datum_soll:
type: string type: string
betrag_zahlung: datum_ist:
type: number type: string
betrag_forderung: betrag_zahlung:
type: number type: number
kommentar: betrag_forderung:
type: string type: number
mieter: kommentar:
type: number type: string
Saldo: mieter:
description: Saldo type type: number
type: object Saldo:
properties: description: Saldo type
forderungen: type: object
type: number properties:
zahlungen: forderungen:
type: number type: number
saldo: zahlungen:
type: number type: number
saldo:
type: number