diff --git a/src/admin/routes.py b/src/admin/routes.py index b3b655c..c9041d0 100644 --- a/src/admin/routes.py +++ b/src/admin/routes.py @@ -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'] @@ -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'] @@ -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: @@ -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: @@ -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() diff --git a/src/clubs/routes.py b/src/clubs/routes.py index c5c0b2d..ab16645 100644 --- a/src/clubs/routes.py +++ b/src/clubs/routes.py @@ -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'] @@ -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'] @@ -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: @@ -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: @@ -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() @@ -141,6 +165,10 @@ def delete_me(): @bp.route('//', 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: @@ -152,6 +180,10 @@ def get_club_by_id(club_id): @bp.route('//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: @@ -180,6 +212,10 @@ def edit_club(club_id): @bp.route('//', 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 diff --git a/src/fundraisers/routes.py b/src/fundraisers/routes.py index 3788588..0e763a3 100644 --- a/src/fundraisers/routes.py +++ b/src/fundraisers/routes.py @@ -56,6 +56,10 @@ def create_fundraisers(): @bp.route('//', 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: @@ -66,6 +70,10 @@ def get_by_fundraiser_id(fundraiser_id): @bp.route('/club//', 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) @@ -73,6 +81,10 @@ def get_by_club_id(club_id): @bp.route('/', methods=['GET']) def get_all_fundraisers(): + ''' + Gets all fundraisers + ''' + all_fundraisers = [fundraiser.serialize() for fundraiser in Fundraiser.query.all()] return all_fundraisers @@ -81,6 +93,10 @@ def get_all_fundraisers(): @bp.route('//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: @@ -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'] @@ -141,6 +161,10 @@ def add_fundraiser_item(): @bp.route('//', 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 diff --git a/src/main/routes.py b/src/main/routes.py index ccae9c3..c273433 100644 --- a/src/main/routes.py +++ b/src/main/routes.py @@ -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') diff --git a/src/students/routes.py b/src/students/routes.py index 13b57e7..36181a8 100644 --- a/src/students/routes.py +++ b/src/students/routes.py @@ -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'] @@ -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: @@ -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: @@ -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() @@ -134,6 +154,10 @@ def delete_me(): @bp.route('//', 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') @@ -152,6 +176,10 @@ def get_student_by_id(student_id=None, netid=None): @bp.route('//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: @@ -177,6 +205,10 @@ def edit_student_by_id(student_id=None, netid=None): @bp.route('//', 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 diff --git a/src/transactions/routes.py b/src/transactions/routes.py index beac8c4..67c4c75 100644 --- a/src/transactions/routes.py +++ b/src/transactions/routes.py @@ -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']