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

Planning: Higher level API endpoints and CRUD functions #15

Closed
mtreacy002 opened this issue May 11, 2020 · 20 comments
Closed

Planning: Higher level API endpoints and CRUD functions #15

mtreacy002 opened this issue May 11, 2020 · 20 comments
Labels
Program: GSOC Related to work completed during the Google Summer of Code Program.

Comments

@mtreacy002
Copy link
Member

As per proposal:

Higher Level API (CRUD operations)

Screen Shot 2020-05-11 at 3.06.53 pm.png
Screen Shot 2020-05-11 at 3.07.30 pm.png
Screen Shot 2020-05-11 at 3.08.12 pm.png
Screen Shot 2020-05-11 at 3.08.45 pm.png
Screen Shot 2020-05-11 at 3.10.46 pm.png
Screen Shot 2020-05-11 at 3.11.13 pm.png

REST API endpoints examples

POST /user/personal_background
=> this will add personal background information to the user profile.
GET, PUT, DELETE /user/personal_background/{user_id}
=> this will get/update/delete personal background information of the user which id is specified.
GET /users/find_by_physical_ability/{physical_ability}
=> this will get a list of all users which have the physical ability match the type specified in the ‘physical_ability’ passed as parameter.
GET /users/find_by_criteria/{criteria}
=> this will get a list of users that met the specific search criteria set in ‘criteria’ parameter which is a map of key-value (or dictionary). This way we don’t need to write an extensive list of GETs to filter users by each of their attributes (such as GET /users/find_by_physical_ability).
POST /company
=> this will create a company.
GET, PUT, DELETE /company/{company_id}
=> this will get/update/delete the details of the company which id is specified.
GET /companies
=> this will get the list of all companies.
GET /companies/{company_id}
=> this will get the company which id is specified.
GET /companies/find_by_country/{country}
=> this will get a list of companies in the specified country.
GET /companies/find_by_criteria/{criteria}
=> this will get a list of companies that met the specific search criteria set in ‘criteria’ parameter which is a map of key-value (or dictionary).
POST /program
=> this will create a program.
GET/PUT/DELETE /program/{program_id}
=> this will get/update/delete the details of the program with the specified id.
GET /programs
=> this will get the list of all programs.
GET /programs/{program_id}
=> this will get the program which id is specified.
GET /programs/find_by_contact_type/{contact_type}
=> this will get a list of programs that have contact_type specified by the parameter.
GET /programs/find_by_criteria/{criteria}
=> this will get a list of programs that met the specific search criteria set in ‘criteria’ parameter which is a map of key-value (~ dictionary).
POST /mentorship_relation/send_request
=> this will create a mentoring relation request as well as send email notification to recipient about MR request
GET, DELETE /mentorship_relation/{mentorship_relation_id}
=> this will get/delete the mentorship_relation with the specified id.
GET /mentorship_relations
=> this will get the list of all MRs.
PUT /mentorship_relations/{mentorship_relation_id}
/accept
=> this will allow the Company/Mentor/Mentee to accept an MR request.
PUT /mentorship_relations/{mentorship_relation_id}
/reject
=> this will allow the Company/Mentor/Mentee to reject an MR request.
PUT /mentorship_relations/{mentorship_relation_id}
/cancel
=> this will allow the Company/Mentor/Mentee to cancel an MR request.
GET / mentorship_relations/current
=> this will get the list of current MR regardless of their ‘state’ for the logged in user.
GET / mentorship_relations/find_by_criteria/{criteria}
=> this will get the list of MRs based on the ‘criteria’ passed on as the parameter.

@mtreacy002 mtreacy002 added the Program: GSOC Related to work completed during the Google Summer of Code Program. label May 11, 2020
@mtreacy002 mtreacy002 added this to the Backend Overview milestone May 12, 2020
@mtreacy002
Copy link
Member Author

mtreacy002 commented May 15, 2020

Hi @anitab-org/bridgeintech-maintainers, below is the screenshot of what I have in mind for API endpoints and their related CRUD operations in relation to Users API service. Please give me feedback to whether or not this makes sense to you all.

Screen Shot 2020-05-16 at 7 02 00 am

Screen Shot 2020-05-16 at 7 02 14 am

Link to file

Note: I haven't decided on the API endpoints for Home and Dashboard yet because it'll come after I get more picture on the whole API endpoints

@ramitsawhney27
Copy link

For the initial few endpoints, as you start implementing them, you should be documenting the error codes. For example: 400 bad request - and when would you return this?

@mtreacy002
Copy link
Member Author

Update:
Hi @anitab-org/bridgeintech-maintainers. Here's the updated API endpoints and error handlings related to Users service

Screen Shot 2020-05-29 at 10 36 25 am

Screen Shot 2020-05-29 at 10 38 02 am

Screen Shot 2020-05-29 at 10 38 55 am

Screen Shot 2020-05-29 at 10 39 20 am

Screen Shot 2020-05-29 at 10 39 49 am

@ramitsawhney27
Copy link

These look good. What if there is an internal server error?

@mtreacy002
Copy link
Member Author

I'm thinking to mask it with response 500 but display the error message as it would catch by the HTTPError exception. As mentioned in the below

Screen Shot 2020-05-29 at 8 01 14 pm

Would this be Ok, @ramitsawhney27? If you agree to this, I would add error code 500 on it as well with unspecified message (coz it'll be whatever returned by the response)

@mtreacy002
Copy link
Member Author

Update:
I've added error response 500 in all API requests because of the possibilities of internal error can happen anywhere in the request.
Below just an example of what I've added.

Screen Shot 2020-05-29 at 8 24 43 pm

@meenakshi-dhanani
Copy link

Hey Maya,
Everything looks good. Just a question to think about the login api. So if there's any issue with authentication it makes sense to return a 401. Find explanation in the RFC here.

And in case the credentials a wrong, if you send back a 404, it might give a tip to the malicious users, to try combinations. A 401 should work for any invalid credentials.

@mtreacy002
Copy link
Member Author

Hi @meenakshi-dhanani. That also makes sense to me, tbh (although I'm not sure about the 404 giving more tip to malicious user more than 401 does, 😃). However, in terms of error code, as BIT is using MS API service for this one (login), I don't know if it's a good idea to change the error code from 404 (given by the MS API) to 401 on BIT UI to client. Shouldn't BIT only passing whatever value is returned by MS API?
@ramitsawhney27 and @isabelcosta, is there any reason to use 404 instead of 401 on MS API on this matter? Is BIT allowed to change this?

@meenakshi-dhanani
Copy link

meenakshi-dhanani commented May 30, 2020 via email

@mtreacy002
Copy link
Member Author

Update:
Here's the API endpoints and errors handling for Organizations service

Screen Shot 2020-05-30 at 4 15 53 pm

Screen Shot 2020-05-30 at 4 16 12 pm

Screen Shot 2020-05-30 at 4 16 43 pm

Screen Shot 2020-05-30 at 4 22 14 pm

@mtreacy002
Copy link
Member Author

Update:

So, Here're the latest version for API endpoints

User service

Screen Shot 2020-05-31 at 12 43 26 am

Screen Shot 2020-05-31 at 12 44 42 am

Screen Shot 2020-05-31 at 12 45 07 am

Screen Shot 2020-05-31 at 12 45 31 am

Screen Shot 2020-05-31 at 12 46 01 am

Screen Shot 2020-05-31 at 12 47 26 am

Screen Shot 2020-05-31 at 12 47 41 am

@mtreacy002
Copy link
Member Author

Update:

Organizations service

Screen Shot 2020-05-31 at 12 48 08 am
Screen Shot 2020-05-31 at 12 50 00 am
Screen Shot 2020-05-31 at 12 50 55 am
Screen Shot 2020-05-31 at 12 51 29 am

@mtreacy002
Copy link
Member Author

Update:

Programs service

Screen Shot 2020-05-31 at 12 51 52 am
Screen Shot 2020-05-31 at 12 52 45 am
Screen Shot 2020-05-31 at 12 53 09 am

@mtreacy002
Copy link
Member Author

Update:
API endpoints for Mentorship_Relations service

Screen Shot 2020-05-31 at 8 47 43 pm

Screen Shot 2020-05-31 at 8 49 04 pm

Screen Shot 2020-05-31 at 8 49 25 pm

Screen Shot 2020-05-31 at 8 50 06 pm

Screen Shot 2020-05-31 at 8 50 37 pm

Screen Shot 2020-05-31 at 8 51 10 pm

Screen Shot 2020-05-31 at 8 51 39 pm

Screen Shot 2020-05-31 at 8 52 12 pm

Screen Shot 2020-05-31 at 8 52 37 pm

Screen Shot 2020-05-31 at 8 53 08 pm

Screen Shot 2020-05-31 at 8 53 31 pm

Screen Shot 2020-05-31 at 8 53 54 pm

Screen Shot 2020-05-31 at 8 54 16 pm

Screen Shot 2020-05-31 at 8 54 42 pm

@ramitsawhney27
Copy link

Hi @mtreacy002, your error codes and specs look great. Thank you for the great work with them. One small suggestion, could we use "201-Created", rather than "200-OK" as the error code if something new is created? This is as per our previous discussions in weekly meetings.

@mtreacy002
Copy link
Member Author

mtreacy002 commented Jun 2, 2020

Sorry, haven't updated the docs yet, but have actually applied your suggestion in the code base for User Registration (PR#26).
Screen Shot 2020-06-03 at 9 15 17 am

Will change the docs now... 😉

@mtreacy002
Copy link
Member Author

mtreacy002 commented Jun 3, 2020

Hi @anitab-org/bridgeintech-maintainers. I have updated the docs for the REST API Endpoints and errors handling here. Also, I highlighted 18 error codes that I think would require changes to be done on Mentorship System backend side. This is because if we change it on MS backend, it only needs to change the word selection on HTTPStatus itself whereas if we want to keep MS as it is and mask the codes on BIT side, we would need to write extra lines of codes (e.g. if condition and even sometimes doing for loop) for each of the error points.
Please let me know what you think.

@meenakshi-dhanani
Copy link

Ideally, if MS has the logic of the API, then MS error codes need to be appropriate. Let's open issues on MS, if we can pick them up because this affects BIT too, let's do that. If we don't fix MS, there will be some unnecessary code on BIT, which might have to be removed once MS is fixed, so let's fix the source(because we can). Create them as issues on MS I say, if we can let's help someone who picks it up or let's pick it up. (Don't be blocked by it though)

@mtreacy002
Copy link
Member Author

mtreacy002 commented Jun 3, 2020

I agree with @meenakshi-dhanani .
@ramitsawhney27, @isabelcosta and @foongminwong. would you be ok if I open the issues on MS backend to fix the misrepresented http error codes?
Note that the 18 highlighted error codes that need to be replaced must be represented in separate issue (individually), or at least per function (e.g. user register function) so not to block the BIT development coz the changes can be done gradually.

@mtreacy002
Copy link
Member Author

Update @anitab-org/bridgeintech-maintainers . Closing this as discussion on API endpoints will be ongoing on BridgeInTech Proposal Review doc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Program: GSOC Related to work completed during the Google Summer of Code Program.
Projects
None yet
Development

No branches or pull requests

3 participants