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")
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)

View File

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

View File

@ -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)

View File

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

View File

@ -2,7 +2,7 @@ from geruecht import db
class PriceList(db.Model):
""" Database Model for PriceList
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)

View File

@ -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):