Skip to content

Commit

Permalink
added commentation to all the routes
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenyuser authored Dec 2, 2023
1 parent 30d76c6 commit 83dea42
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/admin/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

@bp.route('/signup/', methods=['POST'])
def create_admin():
'''
Creates an admin user
'''

try:
json_data = json.loads(request.data)
name = json_data['name']
Expand Down Expand Up @@ -43,6 +47,10 @@ def create_admin():

@bp.route('/signin/', methods=['POST'])
def signin_admin():
'''
Signs in an admin user
'''

try:
json_data = json.loads(request.data)
email = json_data['email']
Expand All @@ -68,6 +76,10 @@ def signin_admin():
@bp.route('/signout/', methods=['POST'])
@role_required('admin')
def signout_admin():
'''
Signs out an admin user
'''

if logout_user():
return success_message("Log out success. ")
else:
Expand All @@ -77,12 +89,20 @@ def signout_admin():
@bp.route('/my/', methods=['GET'])
@role_required('admin')
def get_me():
'''
Returns the current user
'''

return success_message(current_user.serialize())


@bp.route('/my/edit/', methods=['PUT'])
@role_required('admin')
def edit_me():
'''
Edits the current user
'''

try:
json_data = json.loads(request.data)
except json.decoder.JSONDecodeError as e:
Expand All @@ -106,6 +126,10 @@ def edit_me():
@bp.route('/my/', methods=['DELETE'])
@role_required('admin')
def delete_me():
'''
Deletes the current user
'''

try:
db.session.delete(current_user)
db.session.commit()
Expand Down
36 changes: 36 additions & 0 deletions src/clubs/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ def check_login():

@bp.route('/signup/', methods=['POST'])
def create_club():
'''
Creates a club
'''

try:
json_data = json.loads(request.data)
name = json_data['name']
Expand Down Expand Up @@ -66,6 +70,10 @@ def create_club():

@bp.route('/signin/', methods=['POST'])
def signin_club():
'''
Signs into a club
'''

try:
json_data = json.loads(request.data)
email = json_data['email']
Expand All @@ -91,6 +99,10 @@ def signin_club():
@bp.route('/signout/', methods=['POST'])
@role_required('club')
def signout_club():
'''
Signs out of a club
'''

if logout_user():
return success_message("Log out success. ")
else:
Expand All @@ -100,12 +112,20 @@ def signout_club():
@bp.route('/my/', methods=['GET'])
@role_required('club')
def get_me():
'''
Returns the club user
'''

return success_message(current_user.serialize())


@bp.route('/my/edit/', methods=['PUT'])
@role_required('club')
def edit_me():
'''
Edits the club user
'''

try:
json_data = json.loads(request.data)
except json.decoder.JSONDecodeError as e:
Expand All @@ -129,6 +149,10 @@ def edit_me():
@bp.route('/my/', methods=['DELETE'])
@role_required('club')
def delete_me():
'''
Deletes the club user
'''

try:
db.session.delete(current_user)
db.session.commit()
Expand All @@ -141,6 +165,10 @@ def delete_me():
@bp.route('/<club_id>/', methods=['GET'])
@role_required('admin')
def get_club_by_id(club_id):
'''
Gets a club by its id
'''

target = Club.query.filter_by(id=club_id).first()

if target is None:
Expand All @@ -152,6 +180,10 @@ def get_club_by_id(club_id):
@bp.route('/<club_id>/edit/', methods=['PUT'])
@role_required('admin')
def edit_club(club_id):
'''
Edits the club by its id
'''

try:
json_data = json.loads(request.data)
except json.decoder.JSONDecodeError as e:
Expand Down Expand Up @@ -180,6 +212,10 @@ def edit_club(club_id):
@bp.route('/<club_id>/', methods=['DELETE'])
@role_required('admin')
def delete_by_club_id(club_id):
'''
Deletes the club by its id
'''

club = get_club_by_id(club_id=club_id)

# If and only if the return is tuple, the error was prompted in the getting function
Expand Down
24 changes: 24 additions & 0 deletions src/fundraisers/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ def create_fundraisers():

@bp.route('/<fundraiser_id>/', methods=['GET'])
def get_by_fundraiser_id(fundraiser_id):
'''
Gets a fundraiser by id
'''

fundraiser = Fundraiser.query.filter_by(id=fundraiser_id).first()

if fundraiser is None:
Expand All @@ -66,13 +70,21 @@ def get_by_fundraiser_id(fundraiser_id):

@bp.route('/club/<club_id>/', methods=['GET'])
def get_by_club_id(club_id):
'''
Gets fundraisers by a club by its id
'''

fundraisers_by_club = [fundraiser.serialize() for fundraiser in Fundraiser.query.filter_by(club_id=club_id)]

return success_message(fundraisers_by_club)


@bp.route('/', methods=['GET'])
def get_all_fundraisers():
'''
Gets all fundraisers
'''

all_fundraisers = [fundraiser.serialize() for fundraiser in Fundraiser.query.all()]

return all_fundraisers
Expand All @@ -81,6 +93,10 @@ def get_all_fundraisers():
@bp.route('/<fundraiser_id>/edit/', methods=['PUT'])
@role_required('club')
def edit_fundraiser(fundraiser_id):
'''
Edits fundraiser by id
'''

try:
json_data = json.loads(request.data)
except json.decoder.JSONDecodeError as e:
Expand Down Expand Up @@ -109,6 +125,10 @@ def edit_fundraiser(fundraiser_id):
@bp.route('/add_item/', methods=['POST'])
@role_required('club')
def add_fundraiser_item():
'''
Adds fundraiser item
'''

try:
json_data = json.loads(request.data)
name = json_data['name']
Expand Down Expand Up @@ -141,6 +161,10 @@ def add_fundraiser_item():
@bp.route('/<fundraiser_id>/', methods=['DELETE'])
@role_required('club')
def delete_fundraiser_by_id(fundraiser_id):
'''
Deletes fundraiser by its id
'''

fundraiser = get_by_fundraiser_id(fundraiser_id=fundraiser_id)

# If and only if the return is tuple, the error was prompted in the getting function
Expand Down
4 changes: 4 additions & 0 deletions src/main/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@

@bp.route('/', methods=['GET'])
def index():
'''
The index page
'''

return success_message('CURaise Backend. Please go to https://github.com/CURaise/CURaise-backend for more guidance')
32 changes: 32 additions & 0 deletions src/students/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ def create_student():

@bp.route('/signin/', methods=['POST'])
def signin_student():
'''
Signs in a student
'''

try:
json_data = json.loads(request.data)
email = json_data['email']
Expand All @@ -83,6 +87,10 @@ def signin_student():
@bp.route('/signout/', methods=['POST'])
@role_required('student')
def signout_student():
'''
Signs out a student
'''

if logout_user():
return success_message("Log out success. ")
else:
Expand All @@ -92,12 +100,20 @@ def signout_student():
@bp.route('/my/', methods=['GET'])
@role_required('student')
def get_me():
'''
Returns the student user
'''

return success_message(current_user.serialize(exclude_venmo_username=True, simplified=True))


@bp.route('/my/edit/', methods=['PUT'])
@role_required('student')
def edit_me():
'''
Edits the student user document
'''

try:
json_data = json.loads(request.data)
except json.decoder.JSONDecodeError as e:
Expand All @@ -121,6 +137,10 @@ def edit_me():
@bp.route('/my/', methods=['DELETE'])
@role_required('student')
def delete_me():
'''
Deletes the student user
'''

try:
db.session.delete(current_user)
db.session.commit()
Expand All @@ -134,6 +154,10 @@ def delete_me():
@bp.route('/<student_id>/', methods=['GET'])
@role_required('admin')
def get_student_by_id(student_id=None, netid=None):
'''
Gets a student by its id
'''

if (student_id is None and netid is None) or (student_id is not None and netid is not None):
return failure_message(FAIL_MSG.POST_FORM.ERROR + 'student_id and netid should not be all supplied or none '
'applied')
Expand All @@ -152,6 +176,10 @@ def get_student_by_id(student_id=None, netid=None):
@bp.route('/<student_id>/edit', methods=['PUT'])
@role_required('admin')
def edit_student_by_id(student_id=None, netid=None):
'''
Edits a student by its id
'''

try:
json_data = json.loads(request.data)
except json.decoder.JSONDecodeError as e:
Expand All @@ -177,6 +205,10 @@ def edit_student_by_id(student_id=None, netid=None):
@bp.route('/<student_id>/', methods=['DELETE'])
@role_required('admin')
def delete_student_by_id(student_id=None, netid=None):
'''
Deletes a student by its id
'''

student = get_student_by_id(student_id=student_id, netid=netid)

# If and only if the return is tuple, the error was prompted in the getting function
Expand Down
4 changes: 4 additions & 0 deletions src/transactions/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ def create_qrcode(transaction_db_id):

@bp.route('/create/', methods=['POST'])
def create_transaction():
'''
Creates a transaction
'''

try:
json_data = json.loads(request.data)
transaction_id = json_data['transaction_id']
Expand Down

0 comments on commit 83dea42

Please sign in to comment.