Dokumentation vervollständigt
This commit is contained in:
parent
ee3eee6e64
commit
d591705835
|
@ -8,6 +8,14 @@ baruser = Blueprint("baruser", __name__)
|
|||
|
||||
@baruser.route("/bar")
|
||||
def _bar():
|
||||
""" Main function for Baruser
|
||||
|
||||
Returns JSON-file with all Users, who hast amounts in this month.
|
||||
|
||||
Returns:
|
||||
JSON-File with Users, who has amounts in this month
|
||||
or ERROR 401 Permission Denied
|
||||
"""
|
||||
print(request.headers)
|
||||
token = request.headers.get("Token")
|
||||
print(token)
|
||||
|
@ -33,6 +41,14 @@ def _bar():
|
|||
|
||||
@baruser.route("/baradd", methods=['POST'])
|
||||
def _baradd():
|
||||
""" Function for Baruser to add amount
|
||||
|
||||
This function added to the user with the posted userID the posted amount.
|
||||
|
||||
Returns:
|
||||
JSON-File with userID and the amount
|
||||
or ERROR 401 Permission Denied
|
||||
"""
|
||||
token = request.headers.get("Token")
|
||||
print(token)
|
||||
accToken = verifyAccessToken(token, BAR)
|
||||
|
@ -52,6 +68,14 @@ def _baradd():
|
|||
|
||||
@baruser.route("/barGetUsers")
|
||||
def _getUsers():
|
||||
""" Get Users without amount
|
||||
|
||||
This Function returns all Users, who hasn't an amount in this month.
|
||||
|
||||
Returns:
|
||||
JSON-File with Users
|
||||
or ERROR 401 Permission Denied
|
||||
"""
|
||||
token = request.headers.get("Token")
|
||||
print(token)
|
||||
accToken = verifyAccessToken(token, BAR)
|
||||
|
@ -68,6 +92,14 @@ def _getUsers():
|
|||
|
||||
@baruser.route("/barGetUser", methods=['POST'])
|
||||
def _getUser():
|
||||
""" Get specified User
|
||||
|
||||
This function returns the user with posted userID and them amount and credit.
|
||||
|
||||
Returns:
|
||||
JSON-File with userID, amount and credit
|
||||
or ERROR 401 Permission Denied
|
||||
"""
|
||||
token = request.headers.get("Token")
|
||||
print(token)
|
||||
accToken = verifyAccessToken(token, BAR)
|
||||
|
|
|
@ -14,9 +14,8 @@ def _getFinanzer():
|
|||
Retrieves all User for the groupe 'moneymaster'
|
||||
|
||||
Returns:
|
||||
A JSON-File with Users or an Error.
|
||||
example:
|
||||
|
||||
A JSON-File with Users
|
||||
or ERROR 401 Permission Denied.
|
||||
"""
|
||||
token = request.headers.get("Token")
|
||||
|
||||
|
@ -31,6 +30,14 @@ def _getFinanzer():
|
|||
|
||||
@finanzer.route("/getFinanzerYears", methods=['POST'])
|
||||
def _getFinanzerYear():
|
||||
""" Get all geruechte from User
|
||||
|
||||
This function returns all geruechte from user with posted userID
|
||||
|
||||
Returns:
|
||||
JSON-File with geruechte of special user
|
||||
or ERROR 401 Permission Denied
|
||||
"""
|
||||
print(request.headers)
|
||||
token = request.headers.get("Token")
|
||||
print(token)
|
||||
|
@ -50,6 +57,16 @@ def _getFinanzerYear():
|
|||
|
||||
@finanzer.route("/finanzerAddAmount", methods=['POST'])
|
||||
def _addAmount():
|
||||
""" Add Amount to User
|
||||
|
||||
This Function add an amount to the user with posted userID.
|
||||
If year is not posted the default is the actual Year.
|
||||
If month is not posted the default is the actual Month.
|
||||
|
||||
Returns:
|
||||
JSON-File with geruecht of year
|
||||
or ERROR 401 Permission Denied
|
||||
"""
|
||||
print(request.headers)
|
||||
token = request.headers.get("Token")
|
||||
print(token)
|
||||
|
@ -79,6 +96,16 @@ def _addAmount():
|
|||
|
||||
@finanzer.route("/finanzerAddCredit", methods=['POST'])
|
||||
def _addCredit():
|
||||
""" Add Credit to User
|
||||
|
||||
This Function add an credit to the user with posted userID.
|
||||
If year is not posted the default is the actual Year.
|
||||
If month is not posted the default is the actual Month.
|
||||
|
||||
Returns:
|
||||
JSON-File with geruecht of year
|
||||
or ERROR 401 Permission Denied
|
||||
"""
|
||||
print(request.headers)
|
||||
token = request.headers.get("Token")
|
||||
print(token)
|
||||
|
|
|
@ -46,4 +46,3 @@ class AccessToken():
|
|||
|
||||
def __repr__(self):
|
||||
return "AccessToken({}, {}, {}".format(self.user, self.token, self.timestamp)
|
||||
|
||||
|
|
|
@ -12,8 +12,6 @@ class CreditList(db.Model):
|
|||
last_schulden: Debt or Credit of last Year.
|
||||
year: Year of all Credits and Debts.
|
||||
user_id: id from the User.
|
||||
|
||||
TODO: link to user???
|
||||
"""
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
|
||||
|
@ -60,6 +58,18 @@ class CreditList(db.Model):
|
|||
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
|
||||
|
||||
def getSchulden(self):
|
||||
""" Get Schulden
|
||||
|
||||
This function calculate the total amount of them self.
|
||||
From the Credit of the Month will the Amount of the Month subtract.
|
||||
Finaly all Month will added together.
|
||||
At Last the amount from last year will be subtract.
|
||||
|
||||
If the Return Value is negativ, the User has an Credit, else the User has an amount.
|
||||
|
||||
Returns:
|
||||
double of the calculated amount
|
||||
"""
|
||||
jan = self.jan_guthaben - self.jan_schulden
|
||||
feb = self.feb_guthaben - self.feb_schulden
|
||||
maer = self.maer_guthaben - self.maer_schulden
|
||||
|
@ -76,7 +86,18 @@ class CreditList(db.Model):
|
|||
sum = jan + feb + maer + apr + mai + jun + jul + aug + sep + okt + nov + dez - self.last_schulden
|
||||
return sum
|
||||
|
||||
def getMonth(self, month):
|
||||
def getMonth(self, month=datetime.now().month):
|
||||
""" Get Amount from month
|
||||
|
||||
This function returns the amount and credit of the month.
|
||||
By default is month the actual month
|
||||
|
||||
Args:
|
||||
month: which month you want to get the amount(1-12)
|
||||
|
||||
Returns:
|
||||
double (credit, amount)
|
||||
"""
|
||||
retValue = None
|
||||
|
||||
if month == 1:
|
||||
|
@ -107,7 +128,18 @@ class CreditList(db.Model):
|
|||
return retValue
|
||||
|
||||
def addAmount(self, amount, month=datetime.now().month):
|
||||
""" Add Amount
|
||||
|
||||
This function add an amount to a month and returns the credit and amount of the month.
|
||||
By default is month the actual month.
|
||||
|
||||
Args:
|
||||
amount: the amount which is to add
|
||||
month: in which month to add the amount (1-12)
|
||||
|
||||
Returns:
|
||||
double (credit, amount)
|
||||
"""
|
||||
if month == 1:
|
||||
self.jan_schulden += amount
|
||||
retValue = (self.jan_guthaben, self.jan_schulden)
|
||||
|
@ -150,7 +182,18 @@ class CreditList(db.Model):
|
|||
return retValue
|
||||
|
||||
def addCredit(self, credit, month=datetime.now().month):
|
||||
""" Add Credit
|
||||
|
||||
This function add an credit to a month and returns the credit and amount of the month.
|
||||
By default is month the actual month.
|
||||
|
||||
Args:
|
||||
credit: the credit which is to add
|
||||
month: in which month to add the credit (1-12)
|
||||
|
||||
Returns:
|
||||
double (credit, amount)
|
||||
"""
|
||||
if month == 1:
|
||||
self.jan_guthaben += credit
|
||||
retValue = (self.jan_guthaben, self.jan_schulden)
|
||||
|
|
|
@ -28,6 +28,18 @@ class User(db.Model):
|
|||
geruechte = db.relationship('CreditList', backref='user', lazy=True)
|
||||
|
||||
def createGeruecht(self, amount=0, year=datetime.now().year):
|
||||
""" Create Geruecht
|
||||
|
||||
This function create a geruecht for the user for an year.
|
||||
By default is amount zero and year the actual year.
|
||||
|
||||
Args:
|
||||
amount: is the last_schulden of the geruecht
|
||||
year: is the year of the geruecht
|
||||
|
||||
Returns:
|
||||
the created geruecht
|
||||
"""
|
||||
print('create geruecht for user {} in year {}'.format(self.userID, year))
|
||||
credit = CreditList(user_id=self.id, last_schulden=amount, year=year)
|
||||
db.session.add(credit)
|
||||
|
@ -37,6 +49,17 @@ class User(db.Model):
|
|||
return credit
|
||||
|
||||
def getGeruecht(self, year=datetime.now().year):
|
||||
""" Get Geruecht
|
||||
|
||||
This function returns the geruecht of an year.
|
||||
By default is the year the actual year.
|
||||
|
||||
Args:
|
||||
year: the year of the geruecht
|
||||
|
||||
Returns:
|
||||
the geruecht of the year
|
||||
"""
|
||||
for geruecht in self.geruechte:
|
||||
if geruecht.year == year:
|
||||
print("find geruecht {} for user {}".format(geruecht, self.id))
|
||||
|
@ -49,6 +72,19 @@ class User(db.Model):
|
|||
return geruecht
|
||||
|
||||
def addAmount(self, amount, year=datetime.now().year, month=datetime.now().month):
|
||||
""" Add Amount
|
||||
|
||||
This function add an amount to a geruecht with an spezified year and month to the user.
|
||||
By default the year is the actual year.
|
||||
By default the month is the actual month.
|
||||
|
||||
Args:
|
||||
year: year of the geruecht
|
||||
month: month for the amount
|
||||
|
||||
Returns:
|
||||
double (credit, amount)
|
||||
"""
|
||||
geruecht = self.getGeruecht(year=year)
|
||||
retVal = geruecht.addAmount(amount, month=month)
|
||||
|
||||
|
@ -60,6 +96,19 @@ class User(db.Model):
|
|||
return retVal
|
||||
|
||||
def addCredit(self, credit, year=datetime.now().year, month=datetime.now().month):
|
||||
""" Add Credit
|
||||
|
||||
This function add an credit to a geruecht with an spezified year and month to the user.
|
||||
By default the year is the actual year.
|
||||
By default the month is the actual month.
|
||||
|
||||
Args:
|
||||
year: year of the geruecht
|
||||
month: month for the amount
|
||||
|
||||
Returns:
|
||||
double (credit, amount)
|
||||
"""
|
||||
geruecht = self.getGeruecht(year=year)
|
||||
retVal = geruecht.addCredit(credit, month=month)
|
||||
|
||||
|
@ -73,6 +122,7 @@ class User(db.Model):
|
|||
def updateGeruecht(self):
|
||||
""" Update list of geruechte
|
||||
|
||||
This function iterate through the geruechte, which sorted by year and update the last_schulden of the geruecht.
|
||||
"""
|
||||
self.geruechte.sort(key=self.sortYear)
|
||||
|
||||
|
@ -85,6 +135,17 @@ class User(db.Model):
|
|||
db.session.commit()
|
||||
|
||||
def sortYear(self, geruecht):
|
||||
""" Sort Year
|
||||
|
||||
This function is only an helperfunction to sort the list of geruechte by years.
|
||||
It only returns the year of the geruecht.
|
||||
|
||||
Args:
|
||||
geruecht: geruecht which year you want
|
||||
|
||||
Returns:
|
||||
int year of the geruecht
|
||||
"""
|
||||
return geruecht.year
|
||||
|
||||
def toJSON(self):
|
||||
|
|
Loading…
Reference in New Issue