Skip to content

Commit 20fb35e

Browse files
committed
Changed birthdate format.
1 parent ebd28c9 commit 20fb35e

File tree

3 files changed

+122
-32
lines changed

3 files changed

+122
-32
lines changed

PyMatcha.postman_collection.json

Lines changed: 74 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,6 +1314,56 @@
13141314
{
13151315
"name": "Complete profile",
13161316
"item": [
1317+
{
1318+
"name": "Complete profile wrong birthdatre format",
1319+
"event": [
1320+
{
1321+
"listen": "test",
1322+
"script": {
1323+
"id": "19ef2fae-c501-48d2-ab5c-c3fd1bad5603",
1324+
"exec": [
1325+
"var response = JSON.parse(responseBody);",
1326+
"",
1327+
"",
1328+
"pm.test(\"Status code is 400\", function () {",
1329+
" pm.response.to.have.status(400);",
1330+
"});",
1331+
"",
1332+
"tests[\"JSON return code is 400\"] = response.code == 400",
1333+
"",
1334+
"tests[\"success is true\"] = response.success == false",
1335+
"tests[\"Message is correct\"] = response.error.message == \"Birthdate format must be %d/%m/%Y (day/month/year)\"",
1336+
"tests[\"Error type is Bad Request\"] = response.error.type == \"BadRequestError\""
1337+
],
1338+
"type": "text/javascript"
1339+
}
1340+
}
1341+
],
1342+
"request": {
1343+
"method": "POST",
1344+
"header": [],
1345+
"body": {
1346+
"mode": "raw",
1347+
"raw": "{\n\t\"orientation\": \"{{user_orientation}}\",\n\t\"bio\": \"{{user_bio}}\",\n\t\"tags\": [\n\t\t\"bot\",\n\t\t\"robot\",\n\t\t\"postman\",\n\t\t\"sex\",\n\t\t\"friends\",\n\t\t\"drink\",\n\t\t\"smoke\"\n\t\t],\n\t\"gender\": \"{{user_gender}}\",\n\t\"birthdate\": \"06 04 1998\"\n}",
1348+
"options": {
1349+
"raw": {
1350+
"language": "json"
1351+
}
1352+
}
1353+
},
1354+
"url": {
1355+
"raw": "{{host}}/profile/complete",
1356+
"host": [
1357+
"{{host}}"
1358+
],
1359+
"path": [
1360+
"profile",
1361+
"complete"
1362+
]
1363+
}
1364+
},
1365+
"response": []
1366+
},
13171367
{
13181368
"name": "Complete profile bio too short",
13191369
"event": [
@@ -1344,7 +1394,7 @@
13441394
"header": [],
13451395
"body": {
13461396
"mode": "raw",
1347-
"raw": "{\n\t\"orientation\": \"{{user_orientation}}\",\n\t\"bio\": \"Bonjour\",\n\t\"tags\": [\n\t\t\"bot\",\n\t\t\"robot\",\n\t\t\"postman\",\n\t\t\"sex\",\n\t\t\"friends\",\n\t\t\"drink\",\n\t\t\"smoke\"\n\t\t],\n\t\"gender\": \"{{user_gender}}\",\n\t\"birthdate\": {{user_birthdate}}\n}",
1397+
"raw": "{\n\t\"orientation\": \"{{user_orientation}}\",\n\t\"bio\": \"Bonjour\",\n\t\"tags\": [\n\t\t\"bot\",\n\t\t\"robot\",\n\t\t\"postman\",\n\t\t\"sex\",\n\t\t\"friends\",\n\t\t\"drink\",\n\t\t\"smoke\"\n\t\t],\n\t\"gender\": \"{{user_gender}}\",\n\t\"birthdate\": \"{{user_birthdate}}\"\n}",
13481398
"options": {
13491399
"raw": {
13501400
"language": "json"
@@ -1394,7 +1444,7 @@
13941444
"header": [],
13951445
"body": {
13961446
"mode": "raw",
1397-
"raw": "{\n\t\"orientation\": \"{{user_orientation}}\",\n\t\"bio\": \"{{user_bio}}\",\n\t\"tags\": [\n\t\t\"bot\",\n\t\t\"robot\"\n\t\t],\n\t\"gender\": \"{{user_gender}}\",\n\t\"birthdate\": {{user_birthdate}}\n}",
1447+
"raw": "{\n\t\"orientation\": \"{{user_orientation}}\",\n\t\"bio\": \"{{user_bio}}\",\n\t\"tags\": [\n\t\t\"bot\",\n\t\t\"robot\"\n\t\t],\n\t\"gender\": \"{{user_gender}}\",\n\t\"birthdate\": \"{{user_birthdate}}\"\n}",
13981448
"options": {
13991449
"raw": {
14001450
"language": "json"
@@ -1444,7 +1494,7 @@
14441494
"header": [],
14451495
"body": {
14461496
"mode": "raw",
1447-
"raw": "{\n\t\"orientation\": \"{{user_orientation}}\",\n\t\"bio\": \"{{user_bio}}\",\n\t\"tags\": [\n\t\t\"bot\",\n\t\t\"robot\",\n\t\t\"postman\",\n\t\t\"sex\",\n\t\t\"friends\",\n\t\t\"drink\",\n\t\t\"smoke\",\n\t\t\"smoke\"\n\t\t],\n\t\"gender\": \"{{user_gender}}\",\n\t\"birthdate\": {{user_birthdate}}\n}",
1497+
"raw": "{\n\t\"orientation\": \"{{user_orientation}}\",\n\t\"bio\": \"{{user_bio}}\",\n\t\"tags\": [\n\t\t\"bot\",\n\t\t\"robot\",\n\t\t\"postman\",\n\t\t\"sex\",\n\t\t\"friends\",\n\t\t\"drink\",\n\t\t\"smoke\",\n\t\t\"smoke\"\n\t\t],\n\t\"gender\": \"{{user_gender}}\",\n\t\"birthdate\": \"{{user_birthdate}}\"\n}",
14481498
"options": {
14491499
"raw": {
14501500
"language": "json"
@@ -1494,7 +1544,7 @@
14941544
"header": [],
14951545
"body": {
14961546
"mode": "raw",
1497-
"raw": "{\n\t\"orientation\": \"{{user_orientation}}\",\n\t\"bio\": \"{{user_bio}}\",\n\t\"tags\": [\n\t\t\"bot\",\n\t\t\"robot\",\n\t\t\"postman\",\n\t\t\"sex\",\n\t\t\"friends\",\n\t\t\"drink\",\n\t\t\"smoke\"\n\t\t],\n\t\"gender\": \"{{user_gender}}\",\n\t\"birthdate\": 1591307841\n}",
1547+
"raw": "{\n\t\"orientation\": \"{{user_orientation}}\",\n\t\"bio\": \"{{user_bio}}\",\n\t\"tags\": [\n\t\t\"bot\",\n\t\t\"robot\",\n\t\t\"postman\",\n\t\t\"sex\",\n\t\t\"friends\",\n\t\t\"drink\",\n\t\t\"smoke\"\n\t\t],\n\t\"gender\": \"{{user_gender}}\",\n\t\"birthdate\": \"06/04/2020\"\n}",
14981548
"options": {
14991549
"raw": {
15001550
"language": "json"
@@ -1543,7 +1593,7 @@
15431593
"header": [],
15441594
"body": {
15451595
"mode": "raw",
1546-
"raw": "{\n\t\"orientation\": \"{{user_orientation}}\",\n\t\"bio\": \"{{user_bio}}\",\n\t\"tags\": [\n\t\t\"bot\",\n\t\t\"robot\",\n\t\t\"postman\",\n\t\t\"sex\",\n\t\t\"friends\",\n\t\t\"drink\",\n\t\t\"smoke\"\n\t\t],\n\t\"gender\": \"{{user_gender}}\",\n\t\"birthdate\": {{user_birthdate}}\n}",
1596+
"raw": "{\n\t\"orientation\": \"{{user_orientation}}\",\n\t\"bio\": \"{{user_bio}}\",\n\t\"tags\": [\n\t\t\"bot\",\n\t\t\"robot\",\n\t\t\"postman\",\n\t\t\"sex\",\n\t\t\"friends\",\n\t\t\"drink\",\n\t\t\"smoke\"\n\t\t],\n\t\"gender\": \"{{user_gender}}\",\n\t\"birthdate\": \"{{user_birthdate}}\"\n}",
15471597
"options": {
15481598
"raw": {
15491599
"language": "json"
@@ -3796,109 +3846,109 @@
37963846
],
37973847
"variable": [
37983848
{
3799-
"id": "3243df34-1e09-46d9-a5c9-14fa1d377ae7",
3849+
"id": "6099b8b2-2e73-44f4-9f74-78e9089dfdff",
38003850
"key": "host",
38013851
"value": "http://127.0.0.1:5000",
38023852
"type": "string"
38033853
},
38043854
{
3805-
"id": "d3fb7ee6-f649-40ba-a1a1-8a54222a905e",
3855+
"id": "714206c8-2107-4eff-8ae8-ebf5e2015f94",
38063856
"key": "user_id",
38073857
"value": "",
38083858
"type": "string"
38093859
},
38103860
{
3811-
"id": "be455f8c-7337-45b5-9fee-f3061099daff",
3861+
"id": "4e75b103-8383-47ee-bef0-4425f7ff99c5",
38123862
"key": "user_email",
38133863
"value": "foo@example.org",
38143864
"type": "string"
38153865
},
38163866
{
3817-
"id": "b5f9e01b-6131-482e-bf54-1590c9dbb641",
3867+
"id": "665e0304-daa9-4c01-b859-780889d2ff5f",
38183868
"key": "user_username",
38193869
"value": "foo",
38203870
"type": "string"
38213871
},
38223872
{
3823-
"id": "d5a1009c-95b7-42e2-be5d-cd44bf0d0ef0",
3873+
"id": "cf9665a1-0e7e-430d-8011-a3b352043b6e",
38243874
"key": "user_password",
38253875
"value": "admin",
38263876
"type": "string"
38273877
},
38283878
{
3829-
"id": "d1a08ea9-b55b-4d6e-91e4-96cbc1226547",
3879+
"id": "93c59f99-458f-4e39-a7e7-87a6e1f6f377",
38303880
"key": "user_firstname",
38313881
"value": "Foo",
38323882
"type": "string"
38333883
},
38343884
{
3835-
"id": "c16309d5-3eda-42e7-971e-5bc5f8e48d6e",
3885+
"id": "f2ae4172-b5ec-4640-b4af-f8be4853ec49",
38363886
"key": "user_lastname",
38373887
"value": "Bar",
38383888
"type": "string"
38393889
},
38403890
{
3841-
"id": "28ef92a9-c27d-4c24-a416-99e28aa806ec",
3891+
"id": "d936adc6-51e9-48ca-b5d7-8a3a54a73650",
38423892
"key": "debug_token",
38433893
"value": "xX69jules69Xx",
38443894
"type": "string"
38453895
},
38463896
{
3847-
"id": "ccf1a59e-3223-40e4-a185-65a21abea20c",
3897+
"id": "186a863a-cc6e-4187-b636-ff1b7df31d14",
38483898
"key": "user_access_token",
38493899
"value": "",
38503900
"type": "string"
38513901
},
38523902
{
3853-
"id": "3d4b8b6d-a8d7-44fc-b5b3-425ac33d3b27",
3903+
"id": "f3e535fc-76c9-49eb-92c1-a4c5ff3c5307",
38543904
"key": "user_refresh_token",
38553905
"value": "",
38563906
"type": "string"
38573907
},
38583908
{
3859-
"id": "1bc11bd8-fe77-4801-8c81-90794c1b95d2",
3909+
"id": "70529b93-f36f-4a24-88de-b1842f0b61e9",
38603910
"key": "expired_token",
38613911
"value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1OTAyNDIyNjQsIm5iZiI6MTU5MDI0MjI2NCwianRpIjoiNTM0ZGI5NzQtOWE4Ni00MGViLWE1NDEtMDg3N2ZmNzQ3NDVhIiwiZXhwIjoxNTkwMjQyMzI0LCJpZGVudGl0eSI6eyJpZCI6NTEyLCJlbWFpbCI6ImZvb0BleGFtcGxlLm9yZyIsInVzZXJuYW1lIjoiYmFyIiwiaXNfb25saW5lIjp0cnVlLCJkYXRlX2xhc3RzZWVuIjoiU2F0LCAyMyBNYXkgMjAyMCAxMzo1Nzo0NCBHTVQifSwiZnJlc2giOnRydWUsInR5cGUiOiJhY2Nlc3MifQ.NTp2P0WNkXDwzuzrcNIQdeAfizQ57HQgkzBLSvY1yHU",
38623912
"type": "string"
38633913
},
38643914
{
3865-
"id": "e7c96071-c62d-41bd-99a3-143ee886048e",
3915+
"id": "9c08e3a8-2605-45cd-b367-da94e7b1befc",
38663916
"key": "user_orientation",
38673917
"value": "heterosexual",
38683918
"type": "string"
38693919
},
38703920
{
3871-
"id": "8c04f548-8d00-42d5-8524-925da29c837c",
3921+
"id": "e495090b-8ca2-4fe3-97fc-2e6ac3ab1a7b",
38723922
"key": "user_bio",
38733923
"value": "Lorem Ipsum is the single greatest threat. We are not - we are not keeping up with other websites. Lorem Ipsum best not make any more threats to your website. It will be met with fire and fury like the world has never seen. Does everybody know that pig named Lorem Ipsum? An ‘extremely credible source’ has called my office and told me that Barack Obama’s placeholder text is a fraud.",
38743924
"type": "string"
38753925
},
38763926
{
3877-
"id": "ac4953fd-ab5e-4d3c-94c9-9241d176709d",
3927+
"id": "6e78fb84-ee65-416d-96bf-82141d494e19",
38783928
"key": "user_gender",
38793929
"value": "male",
38803930
"type": "string"
38813931
},
38823932
{
3883-
"id": "6cde30ee-9f1d-48a5-9f64-85831089f86e",
3933+
"id": "ae88bd6a-68ef-43ec-9cfa-04aba929cfcc",
38843934
"key": "user_birthdate",
3885-
"value": "891871428",
3935+
"value": "06/04/1998",
38863936
"type": "string"
38873937
},
38883938
{
3889-
"id": "6da6191a-5954-4e89-9a50-6e4772e34276",
3939+
"id": "083094e4-16bf-4eb9-bf9e-ecb37ebf747f",
38903940
"key": "user_lat",
38913941
"value": "44.8404",
38923942
"type": "string"
38933943
},
38943944
{
3895-
"id": "b6764588-2618-433c-b462-9907784b47a0",
3945+
"id": "ae94618b-31bb-4c07-9c87-f7d81bc32eef",
38963946
"key": "user_lng",
38973947
"value": "-0.5805",
38983948
"type": "string"
38993949
},
39003950
{
3901-
"id": "1db8f131-cc74-4e34-8611-7b0379838411",
3951+
"id": "89b0ed54-50e0-4924-b6cc-ac61756173ec",
39023952
"key": "user_ip",
39033953
"value": "77.205.46.181",
39043954
"type": "string"

backend/PyMatcha/routes/api/profile.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@
4343

4444
profile_bp = Blueprint("profile", __name__)
4545

46-
REQUIRED_PARAMS_COMPLETE_PROFILE = {"gender": str, "birthdate": int, "orientation": str, "bio": str, "tags": list}
46+
REQUIRED_PARAMS_COMPLETE_PROFILE = {"gender": str, "birthdate": str, "orientation": str, "bio": str, "tags": list}
4747
REQUIRED_PARAMS_EDIT_PROFILE = {
4848
"first_name": str,
4949
"last_name": str,
5050
"username": str,
5151
"bio": str,
5252
"gender": str,
5353
"orientation": str,
54-
"birthdate": int,
54+
"birthdate": str,
5555
"tags": list,
5656
}
5757

@@ -71,6 +71,11 @@ def complete_profile():
7171
gender = data["gender"]
7272
birthdate = data["birthdate"]
7373

74+
try:
75+
birthdate = datetime.datetime.strptime(birthdate, "%d/%m/%Y").date()
76+
except ValueError:
77+
raise BadRequestError("Birthdate format must be %d/%m/%Y (day/month/year)", "Try again")
78+
7479
if len(bio) <= 50:
7580
raise BadRequestError("Bio is too short", "Try again")
7681

@@ -80,8 +85,10 @@ def complete_profile():
8085
if len(tags) != len(set(tags)):
8186
raise BadRequestError("Duplicate tags", "Try again")
8287

83-
minimum_age = 364.25 * 24 * 60 * 60 * 18
84-
if datetime.datetime.utcnow().timestamp() - birthdate < minimum_age:
88+
today = datetime.datetime.utcnow()
89+
90+
age = today.year - birthdate.year - ((today.month, today.day) < (birthdate.month, birthdate.day))
91+
if age < 18:
8592
raise BadRequestError("You must be 18 years old or older", "Try again later")
8693

8794
for tag in tags:
@@ -91,7 +98,7 @@ def complete_profile():
9198
current_user.bio = bio
9299
current_user.is_profile_completed = True
93100
current_user.gender = gender
94-
current_user.birthdate = datetime.date.fromtimestamp(int(birthdate))
101+
current_user.birthdate = birthdate
95102
current_user.save()
96103
return Success("Profile completed !")
97104

frontend/package-lock.json

Lines changed: 36 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)