-
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: PUT and GET organization and tests #103
Feat: PUT and GET organization and tests #103
Conversation
Update @anitab-org/bridgeintech-maintainers . This PR is still a WIP. At the moment it addresses GET /organization with responses 403 Forbidden when the user either did not declare that they represent an organization or they haven't created an additional information instance to state whether or not they represents an organisation. |
@ramitsawhney27 . Can you please check this PR and give me feedback whether or not my approach on this GET /organization make sense. Thanks |
@ramitsawhney27, I specifically want to note that I send an HTTP request to GET /user to backend within the logic of GET /organization since to get the organization that the logged-in user represents, I need to pass the user_id as parameter in the database query. |
84e9236
to
753a1a2
Compare
Update @anitab-org/bridgeintech-maintainers . I've completed the GET and PUT API endpoints of this PR. I still need to do the test cases though. Will force push it once I'm done. @ramitsawhney27 , can you please open an issue for this functionalities (GET and PUT /organizations) so I can link this PR to it. Thanks |
This is fine |
753a1a2
to
147a472
Compare
Update @anitab-org/bridgeintech-maintainers . This PR is now completed. Please review when you have time. Thanks |
app/api/dao/organization.py
Outdated
The OrganizationModel class represented by the user whose ID was searched. | ||
""" | ||
|
||
rep_additional_info = UserExtensionModel.find_by_user_id(rep_id) |
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.
Maya it's a good thing to not use abbreviations. It gets really difficult when you're code is worked on by more people. Try not using abbreviations anywhere, could be representative_id
.
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.
ok, will change it.
app/api/dao/organization.py
Outdated
} | ||
except AttributeError as e: | ||
logging.fatal(f"{e}") | ||
return messages.IS_ORGANIZATION_REP_NOT_DECLARED, HTTPStatus.FORBIDDEN |
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.
what does it mean? IS_ORGANIZATION_REP_NOT_DECLARED? can we name this better?
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.
https://www.codingblocks.net/podcast/clean-code-writing-meaningful-names/ - whenever you're free, Uncle Bob's clean code posts/podcasts are available. They should explain how important it is to have meaningful names
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.
what does it mean? IS_ORGANIZATION_REP_NOT_DECLARED? can we name this better?
This means the user either has not declared whether or not they are an organization representative or has not yet created an additional_info and declare they are a representative. Tbh I can't think of any other name that is more suitable to be the title for this message. Do you have a suggestion @meenakshi-dhanani ?
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.
NO_REPRESENTATIVE_FOR_ORGANIZATION?
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.
Ok, will change it.
147a472
to
8a22fcf
Compare
representative_additional_info = UserExtensionModel.find_by_user_id(representative_id) | ||
try: | ||
if representative_additional_info.is_organization_rep: | ||
result = OrganizationModel.find_by_representative(representative_id) |
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 this be EAFP/try-catch based? Makes more sense to me intuitively
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.
ok, will try and change it now.
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'm not sure how to use EAFP to check if the value of is_organization_rep is true, which is my intention here. Can you please advise?
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.
I meant for line 30-44. We can do:
try:
return {}
except ...:
return messages. OR...
Not a compulsory thing, if you're unclear or disagree, we can skip this for now
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.
I see. Done. I've changed it to EAFP now 😁
website = data["website"] | ||
timezone_value = data["timezone"] | ||
timezone = Timezone(timezone_value).name | ||
except KeyError as e: |
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.
+1 for try-except
8a22fcf
to
81fc1bb
Compare
81fc1bb
to
dff7193
Compare
Update @ramitsawhney27 and @anitab-org/bridgeintech-maintainers. I've pushed a minor change to GET /organization so that it returns result if first try is successful. This way it's less code as well (remove unnecessary check on user_id). |
dff7193
to
9f72020
Compare
Update @anitab-org/bridgeintech-maintainers . I need to refactor Organization dao get response model so that it returns representative name as well as ID to make it meaningful, in particular later since this will be used for viewing Organizations list on UI. So, please do not merge this PR for now. |
9f72020
to
95f2745
Compare
Update @ramitsawhney27 and @anitab-org/bridgeintech-maintainers .I've pushed the latest change which refactored OrganizationDAO get organization response model to include representative name. I've also modified the tests accordingly. Please re-review when you have time. |
Another thing, so I'm doing the GET now and it says-Internal Server Error when I hit get,
|
@meenakshi-dhanani . I don't get the same error as you did. I've got the expected 403 GET /organization not sent. |
It's because I gave OrganizationStatus as single. It breaks. |
and the timezone too. The code breaks, can we handle these as BAD REQUEST? |
Mmmm.... have you tried to pull my latest code? I did make the push a couple of times. The reason I asked is because I didn't get the same error for PUT. |
Ok, will fix the error catching of Timezone and Status enum too |
59d0489
to
22207a8
Compare
Update @meenakshi-dhanani and @anitab-org/bridgeintech-maintainers . I've just pushed the latest change that addresses Meena's feedback on error handling and setting user cookie upon login. |
22207a8
to
1b4801f
Compare
Update @meenakshi-dhanani and @anitab-org/bridgeintech-maintainers . I've refactored all test cases to align with the main code changes. This PR is now completed. Can you please check it out when you have time? Thanks |
e892166
to
983c053
Compare
It's still breaking for invalid status, can you check? |
@meenakshi-dhanani . Did you pull on my last change <commit 983c053>? Also can you show me screenshot of what's breaking? It's not clear which invalid status you're talking about. |
Added create and update functionalities Add tests for get, create and update organization Fix rep_id abbreviation Use EAFP to check if organization exist Fix bug UnboundlocalError if user_id remove unnecessary reeturn line Refactor get organization response model and tests fix rep_id and response message Refactor rep_ syntax, cookie user retrieval on login, error handling 400 for invalid input fields Refactor test cases Fix update organization test cases Remove the note on API details on the need to do GET/user/personal_details first Fix invalid status response
983c053
to
2dc6166
Compare
@meenakshi-dhanani and @anitab-org/bridgeintech-maintainers . I've fixed the invalid status response and pushed the change. Can you check? |
Looks good. I checked the status, email, timezone and validations. Approving |
@ramitsawhney27 you would need to re-approve. |
Description
Create PUT and GET /organization API endpoints
Fixes #105
Type of Change:
Code/Quality Assurance Only
How Has This Been Tested?
is_organization_rep
is Trueuser_id
through GET /organization. see error 403 Forbidden and error messageOrganization does not exist
.is_organization_rep
isFalse
or has not created an additional_info.is_organization_rep
valueChecklist:
Code/Quality Assurance Only
Additional Info
This is still a work in progress