Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get -> Post, also changed registration error order #89

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions source/backend/call_api_examples.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -37,7 +37,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 3,
"metadata": {},
"outputs": [
{
Expand All @@ -48,7 +48,7 @@
"{\n",
" \"message\": \"Togekiss logged in successfully.\"\n",
"}\n",
"<RequestsCookieJar[<Cookie session=.eJwlzjsOwjAMANC7ZGbIz3Hcc7BXdmxDxYDU0An17lRiefP7htV3m8-wfPbDbmHdNCwheRKu0TJkvnTvmRScmUttLUoGbVw0qZReB4sOQkPEZpl7Q4BCCRhYxTtmcncSGZQIpREMMEct0FOP5nUo4SgNYx85cgSrFK7IMW3_b-7vh722OcP5A2ymMv0.ZtDneA.tW2hxua77GLVohpI5IKt7Kg3xcw for 127.0.0.1/>]>\n"
"<RequestsCookieJar[<Cookie session=.eJwlzjsOwjAMANC7ZGbIz3Hcc7BXdmxDxYDU0An17lRiefP7htV3m8-wfPbDbmHdNCwheRKu0TJkvnTvmRScmUttLUoGbVw0qZReB4sOQkPEZpl7Q4BCCRhYxTtmcncSGZQIpREMMEct0FOP5nUo4SgNYx85cgSrFK7IMW3_b-7vh722OcP5A2ymMv0.ZuCRNg.R9A-1mf5JwGc-xCcgLQcsYJSKoc for 127.0.0.1/>]>\n"
]
}
],
Expand Down Expand Up @@ -813,7 +813,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### month_cat_exp (GET): Gets user spending per category for current month\n",
"### month_cat_exp (POST): Gets user spending per category for current month\n",
"\n",
"**Parameters:** \n",
"\n",
Expand Down Expand Up @@ -846,7 +846,7 @@
"source": [
"# url = 'http://127.0.0.1:5000/api/month_cat_exp'\n",
"url = 'https://receiptplus.pythonanywhere.com/api/month_cat_exp'\n",
"response = requests.get(url, json= {'date': '2024-07-07'}, cookies = session_cookie)\n",
"response = requests.post(url, json= {'date': '2024-07-07'}, cookies = session_cookie)\n",
"print('Response code: ' + str(response.status_code))\n",
"print(json.dumps(response.json(), indent=4))"
]
Expand All @@ -855,7 +855,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### month_exp (GET): Gets the days the user spent money on and the amount spent on those days for the current month\n",
"### month_exp (POST): Gets the days the user spent money on and the amount spent on those days for the current month\n",
"\n",
"**Parameters:**\n",
"\n",
Expand Down Expand Up @@ -888,7 +888,7 @@
"source": [
"url = 'https://receiptplus.pythonanywhere.com/api/month_exp'\n",
"# url = 'http://127.0.0.1:5000/api/month_exp'\n",
"response = requests.get(url, json= {'date': '2024-07-07'}, cookies = session_cookie)\n",
"response = requests.post(url, json= {'date': '2024-07-07'}, cookies = session_cookie)\n",
"print('Response code: ' + str(response.status_code))\n",
"print(json.dumps(response.json(), indent=4))"
]
Expand Down
4 changes: 2 additions & 2 deletions source/backend/resource/resource_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# '2024-3-15':5,
# '2024-3-27':0 (in this case, the user spent no money on the current date)
# }
@summary_bp.route('/month_exp', methods=['GET'])
@summary_bp.route('/month_exp', methods=['POST'])
@login_required
def month_exp():
db = current_app.db
Expand All @@ -44,7 +44,7 @@ def month_exp():
# 'restaurants':50,
# 'gas':50
# }
@summary_bp.route('/month_cat_exp', methods=['GET'])
@summary_bp.route('/month_cat_exp', methods=['POST'])
@login_required
def month_cat_exp():
db = current_app.db
Expand Down
11 changes: 9 additions & 2 deletions source/backend/resource/resource_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,20 @@ def register():
raise InvalidDateFormat()
users_ref = db.collection('Users')
docs = users_ref.stream()
user_id_already_exists = False
user_email_already_exists = False
for doc in docs:
existing_user_id = doc.id
existing_email = doc.get('email')
if user_id == existing_user_id:
raise UserAlreadyExistsError()
user_id_already_exists = True
break # break out early because user_id exists is priority error
if email == existing_email:
raise EmailAlreadyExistsError()
user_email_already_exists = True
if user_id_already_exists:
raise UserAlreadyExistsError()
if user_email_already_exists:
raise EmailAlreadyExistsError()
passwordHash = sha256_crypt.hash(password)
# use set to create new document with specified data (overwrites existing documents)
db.collection('Users').document(user_id).set({
Expand Down
Loading