Dokumentation vervollständigt

This commit is contained in:
Tim Gröger 2019-05-02 18:50:59 +02:00
parent ee3eee6e64
commit d591705835
7 changed files with 179 additions and 17 deletions

View File

@ -8,6 +8,14 @@ baruser = Blueprint("baruser", __name__)
@baruser.route("/bar") @baruser.route("/bar")
def _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) print(request.headers)
token = request.headers.get("Token") token = request.headers.get("Token")
print(token) print(token)
@ -33,6 +41,14 @@ def _bar():
@baruser.route("/baradd", methods=['POST']) @baruser.route("/baradd", methods=['POST'])
def _baradd(): 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") token = request.headers.get("Token")
print(token) print(token)
accToken = verifyAccessToken(token, BAR) accToken = verifyAccessToken(token, BAR)
@ -52,6 +68,14 @@ def _baradd():
@baruser.route("/barGetUsers") @baruser.route("/barGetUsers")
def _getUsers(): 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") token = request.headers.get("Token")
print(token) print(token)
accToken = verifyAccessToken(token, BAR) accToken = verifyAccessToken(token, BAR)
@ -68,6 +92,14 @@ def _getUsers():
@baruser.route("/barGetUser", methods=['POST']) @baruser.route("/barGetUser", methods=['POST'])
def _getUser(): 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") token = request.headers.get("Token")
print(token) print(token)
accToken = verifyAccessToken(token, BAR) accToken = verifyAccessToken(token, BAR)

View File

@ -6,7 +6,7 @@ import hashlib
class AccesTokenController(Thread): class AccesTokenController(Thread):
""" Control all createt AccesToken """ Control all createt AccesToken
This Class create, delete, find and manage AccesToken. This Class create, delete, find and manage AccesToken.
Attributes: Attributes:
@ -18,7 +18,7 @@ class AccesTokenController(Thread):
def __init__(self): def __init__(self):
""" Initialize AccessTokenController """ Initialize AccessTokenController
Initialize Thread and set tokenList empty. Initialize Thread and set tokenList empty.
""" """
print("init AccesTokenControlle") print("init AccesTokenControlle")
@ -28,7 +28,7 @@ class AccesTokenController(Thread):
def findAccesToken(self, token): def findAccesToken(self, token):
""" Find a Token in current AccessTokens """ Find a Token in current AccessTokens
Iterate throw all availables AccesTokens and retrieve one, if they are the same. Iterate throw all availables AccesTokens and retrieve one, if they are the same.
Args: Args:
@ -66,13 +66,13 @@ class AccesTokenController(Thread):
def isSameGroup(self, accToken, group): def isSameGroup(self, accToken, group):
""" Verify group in AccessToken """ Verify group in AccessToken
Verify if the User in the AccesToken has the right group. Verify if the User in the AccesToken has the right group.
Args: Args:
accToken: AccessToken to verify. accToken: AccessToken to verify.
group: Group to verify. group: Group to verify.
Returns: Returns:
A Bool. If the same then True else False A Bool. If the same then True else False
""" """
@ -81,7 +81,7 @@ class AccesTokenController(Thread):
def run(self): def run(self):
""" Starting Controll-Thread """ Starting Controll-Thread
Verify that the AccesToken are not out of date. If one AccessToken out of date it will be deletet from tokenList. Verify that the AccesToken are not out of date. If one AccessToken out of date it will be deletet from tokenList.
""" """
while True: while True:

View File

@ -14,9 +14,8 @@ def _getFinanzer():
Retrieves all User for the groupe 'moneymaster' Retrieves all User for the groupe 'moneymaster'
Returns: Returns:
A JSON-File with Users or an Error. A JSON-File with Users
example: or ERROR 401 Permission Denied.
""" """
token = request.headers.get("Token") token = request.headers.get("Token")
@ -31,6 +30,14 @@ def _getFinanzer():
@finanzer.route("/getFinanzerYears", methods=['POST']) @finanzer.route("/getFinanzerYears", methods=['POST'])
def _getFinanzerYear(): 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) print(request.headers)
token = request.headers.get("Token") token = request.headers.get("Token")
print(token) print(token)
@ -50,6 +57,16 @@ def _getFinanzerYear():
@finanzer.route("/finanzerAddAmount", methods=['POST']) @finanzer.route("/finanzerAddAmount", methods=['POST'])
def _addAmount(): 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) print(request.headers)
token = request.headers.get("Token") token = request.headers.get("Token")
print(token) print(token)
@ -79,6 +96,16 @@ def _addAmount():
@finanzer.route("/finanzerAddCredit", methods=['POST']) @finanzer.route("/finanzerAddCredit", methods=['POST'])
def _addCredit(): 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) print(request.headers)
token = request.headers.get("Token") token = request.headers.get("Token")
print(token) print(token)

View File

@ -2,7 +2,7 @@ from datetime import datetime
class AccessToken(): class AccessToken():
""" Model for an AccessToken """ Model for an AccessToken
Attributes: Attributes:
timestamp: Is a Datetime from current Time. timestamp: Is a Datetime from current Time.
user: Is an User. user: Is an User.
@ -15,7 +15,7 @@ class AccessToken():
def __init__(self, user, token, timestamp=datetime.now()): def __init__(self, user, token, timestamp=datetime.now()):
""" Initialize Class AccessToken """ Initialize Class AccessToken
No more to say. No more to say.
Args: Args:
@ -23,7 +23,7 @@ class AccessToken():
token: Is a String to verify later token: Is a String to verify later
timestamp: Default current time, but can set to an other datetime-Object. timestamp: Default current time, but can set to an other datetime-Object.
""" """
self.user = user self.user = user
self.timestamp = timestamp self.timestamp = timestamp
self.token = token self.token = token
@ -46,4 +46,3 @@ class AccessToken():
def __repr__(self): def __repr__(self):
return "AccessToken({}, {}, {}".format(self.user, self.token, self.timestamp) return "AccessToken({}, {}, {}".format(self.user, self.token, self.timestamp)

View File

@ -12,8 +12,6 @@ class CreditList(db.Model):
last_schulden: Debt or Credit of last Year. last_schulden: Debt or Credit of last Year.
year: Year of all Credits and Debts. year: Year of all Credits and Debts.
user_id: id from the User. user_id: id from the User.
TODO: link to user???
""" """
id = db.Column(db.Integer, primary_key=True) 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) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
def getSchulden(self): 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 jan = self.jan_guthaben - self.jan_schulden
feb = self.feb_guthaben - self.feb_schulden feb = self.feb_guthaben - self.feb_schulden
maer = self.maer_guthaben - self.maer_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 sum = jan + feb + maer + apr + mai + jun + jul + aug + sep + okt + nov + dez - self.last_schulden
return sum 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 retValue = None
if month == 1: if month == 1:
@ -107,7 +128,18 @@ class CreditList(db.Model):
return retValue return retValue
def addAmount(self, amount, month=datetime.now().month): 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: if month == 1:
self.jan_schulden += amount self.jan_schulden += amount
retValue = (self.jan_guthaben, self.jan_schulden) retValue = (self.jan_guthaben, self.jan_schulden)
@ -150,7 +182,18 @@ class CreditList(db.Model):
return retValue return retValue
def addCredit(self, credit, month=datetime.now().month): 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: if month == 1:
self.jan_guthaben += credit self.jan_guthaben += credit
retValue = (self.jan_guthaben, self.jan_schulden) retValue = (self.jan_guthaben, self.jan_schulden)

View File

@ -2,7 +2,7 @@ from geruecht import db
class PriceList(db.Model): class PriceList(db.Model):
""" Database Model for PriceList """ Database Model for PriceList
PriceList has lots of Drinks and safe all Prices (normal, for club, for other clubs, which catagory, etc) PriceList has lots of Drinks and safe all Prices (normal, for club, for other clubs, which catagory, etc)
""" """
id = db.Column(db.Integer, primary_key=True) id = db.Column(db.Integer, primary_key=True)

View File

@ -28,6 +28,18 @@ class User(db.Model):
geruechte = db.relationship('CreditList', backref='user', lazy=True) geruechte = db.relationship('CreditList', backref='user', lazy=True)
def createGeruecht(self, amount=0, year=datetime.now().year): 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)) print('create geruecht for user {} in year {}'.format(self.userID, year))
credit = CreditList(user_id=self.id, last_schulden=amount, year=year) credit = CreditList(user_id=self.id, last_schulden=amount, year=year)
db.session.add(credit) db.session.add(credit)
@ -37,6 +49,17 @@ class User(db.Model):
return credit return credit
def getGeruecht(self, year=datetime.now().year): 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: for geruecht in self.geruechte:
if geruecht.year == year: if geruecht.year == year:
print("find geruecht {} for user {}".format(geruecht, self.id)) print("find geruecht {} for user {}".format(geruecht, self.id))
@ -49,6 +72,19 @@ class User(db.Model):
return geruecht return geruecht
def addAmount(self, amount, year=datetime.now().year, month=datetime.now().month): 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) geruecht = self.getGeruecht(year=year)
retVal = geruecht.addAmount(amount, month=month) retVal = geruecht.addAmount(amount, month=month)
@ -60,6 +96,19 @@ class User(db.Model):
return retVal return retVal
def addCredit(self, credit, year=datetime.now().year, month=datetime.now().month): 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) geruecht = self.getGeruecht(year=year)
retVal = geruecht.addCredit(credit, month=month) retVal = geruecht.addCredit(credit, month=month)
@ -73,6 +122,7 @@ class User(db.Model):
def updateGeruecht(self): def updateGeruecht(self):
""" Update list of geruechte """ 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) self.geruechte.sort(key=self.sortYear)
@ -85,6 +135,17 @@ class User(db.Model):
db.session.commit() db.session.commit()
def sortYear(self, geruecht): 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 return geruecht.year
def toJSON(self): def toJSON(self):