-
Notifications
You must be signed in to change notification settings - Fork 80
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
Feat: Issue#76 POST and GET /user/additional_info api endpoints #77
Feat: Issue#76 POST and GET /user/additional_info api endpoints #77
Conversation
Update @anitab-org/bridgeintech-maintainers. I've just completed POST and GET /user/additional_info. I have no option but to put this 2 together as to have successful GET example, the additional information of the user must be created first. I put notes on how to test the functionality in this PR description above. |
app/api/dao/user_extension.py
Outdated
timezone = data["timezone"] | ||
|
||
additional_info_data = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep this as a default dict instead of initializing with empty strings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. now default dict {}
app/api/dao/user_extension.py
Outdated
if existing_additional_info: | ||
return messages.ADDITIONAL_INFORMATION_OF_USER_ALREADY_EXIST, HTTPStatus.CONFLICT | ||
user_extension = UserExtensionModel(user_id, timezone) | ||
if "is_organization_rep" in data: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use try except KeyError rather than if else to initialize dict elements
https://www.google.com/amp/s/www.geeksforgeeks.org/try-except-vs-if-in-python/amp/
EAFP principle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it. Thanks for the tips. Learned something new here. 😁. Changed to try-except.
app/api/request_api_utils.py
Outdated
logging.fatal(f"{response_message}") | ||
return response_message, response_code | ||
|
||
return () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this return an empty tuple?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reemoved. now simply ends, not returning anything if valid
app/api/resources/users.py
Outdated
is_wrong_token = validate_token(token) | ||
|
||
if not is_wrong_token: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line spacing seems off
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Fixed now 👍
a227411
to
ced7814
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ramitsawhney27 . I've just made the requested changes. Please re-review. Thanks for the feedback.
app/api/resources/users.py
Outdated
is_wrong_token = validate_token(token) | ||
|
||
if not is_wrong_token: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Fixed now 👍
app/api/request_api_utils.py
Outdated
logging.fatal(f"{response_message}") | ||
return response_message, response_code | ||
|
||
return () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reemoved. now simply ends, not returning anything if valid
app/api/dao/user_extension.py
Outdated
if existing_additional_info: | ||
return messages.ADDITIONAL_INFORMATION_OF_USER_ALREADY_EXIST, HTTPStatus.CONFLICT | ||
user_extension = UserExtensionModel(user_id, timezone) | ||
if "is_organization_rep" in data: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it. Thanks for the tips. Learned something new here. 😁. Changed to try-except.
app/api/dao/user_extension.py
Outdated
timezone = data["timezone"] | ||
|
||
additional_info_data = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. now default dict {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved
@@ -2,7 +2,7 @@ | |||
from sqlalchemy.dialects.postgresql import JSONB | |||
from app.database.sqlalchemy_extension import db | |||
from app.utils.bitschema_utils import Timezone | |||
|
|||
# from app.database.models.ms_schema.user import UserModel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hehehe.... sorry... will remove it. 😊
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done.
ced7814
to
6aae1d9
Compare
@ramitsawhney27 I've removed the comment and pushed force again. Can you pls re-approved? Thanks. |
Hey @mtreacy002 , are you able to resolve the conflicting files? I'm having some problem testing this PR (might be caused by those conflicting files hmm) let me know if you have any questions |
6aae1d9
to
b4dfee5
Compare
@foongminwong , Done. Those merge conflict happens coz of the new merge to develop. It'll happen often in this dev since I carry across codes from PR to next ones. So, I have to fix it when the previous PR finally merge. But not to worry, it's an easy fix. |
This PR is tested locally and failed. Error: @mtreacy002 hmm I followed your steps by running Question:
|
@foongminwong . Just curious. Which MS backend server did you run for this test? Do you use the same server that was used in PR #74 ? From 74 onwards we should use that ms-bitschema-backend-server or ms-backend-server from my fork repo as MS backend server. I worked on this PR running ms-bitschema-backend-server but actually prefer to start using ms-backend-server since this is the one I pushed yesterday to merge with MS develop branch. |
To answer your questions:
Yes, it does.
I have never encountered this issue before... 🤔 |
Another thing, @foongminwong . Your MS and BIT servers both are connected to the same db, right? bit_schema db? |
@foongminwong . I spotted from your gif that you still have the userr details with This means you need to drop all tables that you currently have on bit_schema database and recreate them by running the app again |
Not only updating the database, you should also pull the latest code for ms-bitschema-backend-server (or better, ms-backend-server) from my fork repo coz both the user schema and the api response body for user model has changed since that PR#74. Again, I recommend to use the ms-backend-server for this as this is the one I'm planning to maintain moving forward. |
@patch("requests.get") | ||
@patch("requests.post") | ||
def test_api_get_user_details_with_correct_token(self, mock_login, mock_get_user): | ||
success_message = {"access_token": "this is fake token", "access_expiry": 1601478236} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a comment about that access_expiry? Is that past? future, what is the date represented there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done, @isabelcosta . Now also with changed commit message as we discussed in the meeting before 😉
b4dfee5
to
7432e4a
Compare
f3d5c78
to
b210624
Compare
Update @anitab-org/bridgeintech-maintainers . I've added app reviews pipeline to BIT Heroku for your convenience. This way if you want you can test the features of proposed PR without having to run the server locally. When I have time (I'm not promising this will be asap since you can always pull my PR and run the servers locally). If I do make the push on the open PR currently being reviewed, I'll let you know. Here's this PR Heroku test PR: @meenakshi-dhanani and @anitab-org/bridgeintech-maintainers team, if you want to test frontend features using the matching heroku backend PR, you can do this by adding the Heroku test PR link above to the config file yourself. @isabelcosta , I think with Heroku free account, there is a limit to how many app we can put to the PR review pipeline. Bcoz when I tried to create this Review app PR before, it complained saying I have reach my limit of Heroku apps so I deleted the old heroku bridge-in-tech-bit-test server (the one connected to elephantsql, not heroku psql) to give way to this heroku test pr. Just so you are aware this might also apply to MS heroku pipeline. |
PS: It'll be ready soon. I'll need to adjust something. Will ping you when I'm done |
Add comment for human readable dates on access_expiry Allow timezone enum take from and return value to user Add check to make sure user_id is retrieved Add http error response 403 on post request Improve 403 error message to remove ambiguity Add other on some enum class
b210624
to
41b015d
Compare
Ok, now it's ready... Go ahead and test it out 😉. Just added myself as first user who'll be the admin by default 😁 |
Note @anitab-org/bridgeintech-maintainers . I've refactored enum type to add others in some of enum types, so if you testing locally, drop all existing tables and its types (under bitschema > Types directory) and run the app again to recreate the db. |
PS: The heroku servers might nor work as expected. I'm sttill figuring things out, it still best to use local servers imo |
Update. It's too hard to try make the Review app work for PRs ( have to set another db and another ms backend server, plus have to do this for every open PR). So, I leave it aside for now. Theere is a develop branch already running on Heroku for both BIT and MS-for-BIT if you want to try out the merged PR. But for open/under review PRs, unfortunately, you just have to run local servers to test PRs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes made in this PR were tested locally. Following are the results:
-
Code review - Done
-
All possible responses were tested as below (tap/zoom in to see clearer gifs):
- Additional comments:
- hey @mtreacy002 , when I'm trying to do
POST /user/additional_info
, got a500 Internal Server Error
which showsValueError: 'CENTRAL_STANDARD_TIME' is not a valid Timezone
. Did you encounter this error before?
{
"is_organization_rep": true,
"timezone": "CENTRAL_STANDARD_TIME",
"phone": "608-608-6008",
"mobile": "",
"personal_website": "http://habibo.com"
}
- OS Version: Windows 10
@foongminwong . Sorry, I forgot to change the steps to tests on the description of this PR (now I've changed it). Based on mentors suggestions on the last BIT weekly meeting, I strictly limited enum logic to backend. This means frontend user (or backend swagger ui) can straight select the enum value instead of enum name. so in your case, you can change the Timezone input to "UTC-06:00/Central Standard Time" for central standard time. This will be the same case on enums in personal background PRs |
Ok @mtreacy002 , just changed it to: {
"is_organization_rep": true,
"timezone": "UTC-06:00/Central Standard Time",
"phone": "608-608-6008",
"mobile": "",
"personal_website": "http://habibo.com"
} hmm I got a following error:
I wonder why |
@foongminwong . May I ask which MS server you're running with this? If possible, can we meet on hangout so we can troubleshoot this together? PS: Can you please also add as part as point 4 on your comment above which MS branch you're running the server from? Thanks |
Yes, I'm running on |
Are you available to go quickly now or is it too late at your time? |
Just curious, have you dropped and recreate the db as I previously suggested? |
BTW, are you already back in Malaysia or still at US timezone @foongminwong ? |
yes, just sent you an invite, i'm still in US, packing 😂 |
I haven't receive the invite? Where did you send it to? email or Zulip? |
sent invitation on Google Hangouts, also shared the link on Zulip |
@mtreacy002 helped fixed the error in my local environment!! 🙌 Problems found + Fixes:
Commands:
To-do:
|
Update @ramitsawhney27 , currently there's a bug in the existing code (opened issue #94 to report this). Do you want me to deal with it in this PR or as separate issue (since this PR been hold up for a while now). Also should I fix the bug using this PR code base or the latest open PR code base (PR #86 ) PUT/personal_background because fixing it with the first PR on the queue means having to rebase from the next PR up to the latest one on the queue which means removing all the approvals from mentors on the PR (while we're on that topic, can you please re-review and re-approved this PR, as the latest force pushed removed your previous approval 😁). Whereas tackling it from the last PR on the queue (PR #86) will have no effect to the one before that) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work @mtreacy002 👏
Description
Add POST and GET user/additional_info endpoints to create and get additional information of a user.
Fixes #76
Type of Change:
Code/Quality Assurance Only
How Has This Been Tested?
Steps to test functionalities:
For GET
user_id
can be reetrieved and saved as cookie.go to POST /user/additional_info to create additional information. Provide token and data in the relevant fields.
NOTE
if the response is successful, you should see the following
To confirm, go to GET /user//additional_information. Provide token in the specified area. The following is an example of successful request:
Checklist:
Code/Quality Assurance Only