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

Feat: POST/GET/PUT program and list of programs #114

Merged

Conversation

mtreacy002
Copy link
Member

Description

Added create, gt and update programs using the following endpoints:

  1. POST /organizations/{organization_id}/programs/program
    • to create program on the ogranization where the logged-in user is the representative. If they are not the representative, this action is not permitted.
  2. GET /organizations/{organization_id}/programs
    • to get list of programs under the organization specified in the parameter organization_id.
      The purpose of this endpoint is so on the frontend, when user go to Organizations > 'Organization-Portfolo`, they can see the list of programs that organization have. Any user can retrieve this list.
  3. GET /organizations/{organization_id}/programs/{program_id}
  • to get the detail of a specific program that a specific organization has.
    The purpose of this endpoint is so that logged-in user can view the details on a specific program after selecting it from the list of programs from API endpoint number 2 above.
  1. PUT /organizations/{organization_id}/programs/{program_id}
    • to update the detail of a specific program that matches the parameters organization_id and program_id.

Fixes #113

Type of Change:

  • Code

Code/Quality Assurance Only

  • New feature (non-breaking change which adds functionality pre-approved by mentors)

How Has This Been Tested?

Note: The screenshots below are selected from random data

  • logged in as a user who represents an organization
  • test create PUT /organizations/{organization_id}/programs/{program_id} using POST /organizations/{organization_id}/programs/program endpoint. Upon succesful process, see code 201 and message below

Screen Shot 2020-08-19 at 8 40 06 pm

  • test GET /organizations/{organization_id}/programs. on successful response see below:

Screen Shot 2020-08-19 at 8 44 29 pm

  • test update by sending the PUT /organizations/{organization_id}/programs/{program_id} with the correct organization_id and program_id . Upon successful update, get message

Screen Shot 2020-08-19 at 6 37 00 pm

Checklist:

  • My PR follows the style guidelines of this project
  • I have performed a self-review of my own code or materials
  • I have commented my code or provided relevant documentation, particularly in hard-to-understand areas

Code/Quality Assurance Only

  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@mtreacy002
Copy link
Member Author

mtreacy002 commented Aug 19, 2020

Update @anitab-org/bridgeintech-maintainers . I've completed the POST/GET/PUT program functionalities. Note that atm I only GET endpoint for Programs list using organizations/{organization_id}/programs path as at frontend this is one of my target feature (viewing Programs list under specific organization) (at least for the remaining of GSoC). The next one i need to do is Send Application functionality for user to apply to a program.
Later, perhaps post gsoc, we can work on another route to view list of programs, such as:

  • GET /users/{user_id}/programs - for list of programs where user whose ID is passed as parameters is involved in (either as mentor or mentee)

NOTE I will write the test cases for these PR endpoints on a separate PR as this PR already pretty big.

Please review when you have time. Thanks

@mtreacy002 mtreacy002 requested review from ramitsawhney27 and a team August 19, 2020 11:16
@mtreacy002 mtreacy002 self-assigned this Aug 19, 2020
@mtreacy002 mtreacy002 added Category: Coding Changes to code base or refactored code that doesn't fix a bug. Program: GSOC Related to work completed during the Google Summer of Code Program. labels Aug 19, 2020
return user.message, user.status_code

programs = ProgramModel.get_all_programs_by_organization(organization_id)
list_of_programs = []

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not declare list of programs after “if not programs:”
Also, lines 69-70 can just be a list comprehension

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Changed now


def update(program, data, success_message, status_code):
target_candidate_data = {}
try:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think some info should be given if it is a bad request, such as which field(s) is malformed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ramitsawhney27 , I do it this way coz for the fields that required specific format, the validation already done specific to each fields in the preceding code (inside app/api/resources/organizations.py) line 105
Screen Shot 2020-08-20 at 8 46 41 am

as for the TypeError e done here, will specify which fields other than those catch in the above that is malformed. Let me know if you have another alternative. Thanks

if not is_phone_valid(mobile):
return messages.PHONE_OR_MOBILE_IS_NOT_IN_NUMBER_FORMAT
except ValueError as e:
return e

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is e being returned? Can you add a comment to the code to explain this to future readers?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Refactored email, phone and mobile to LBYL instead of EAFP as the LBYL makes more sense in this situation and use less lines of codes

@mtreacy002 mtreacy002 force-pushed the feat-get-put-program-and-tests branch from e37ad31 to d10a27a Compare August 19, 2020 23:41
@mtreacy002
Copy link
Member Author

Update @anitab-org/bridgeintech-maintainers, I've pushed the changes requested by @ramitsawhney27 . Can you please check again? Thanks

programs = ProgramModel.get_all_programs_by_organization(organization_id)
if not programs:
return messages.NO_PROGRAM_FOUND, HTTPStatus.NOT_FOUND
list_of_programs = []

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 68-70 (even 71) can be condensed into 1 line using list comprehension. Could you please do that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, @ramitsawhney27 . It surely looks better now. Thanks heaps for the tips. 😉

@mtreacy002 mtreacy002 force-pushed the feat-get-put-program-and-tests branch from d10a27a to 661f41d Compare August 20, 2020 02:08
ramitsawhney27
ramitsawhney27 previously approved these changes Aug 20, 2020
Refactor validations

refactor list_of_programs to use list comprehension

Remove is_organization_rep being returned upon login
@mtreacy002
Copy link
Member Author

Update @ramitsawhney27 and @anitab-org/bridgeintech-maintainers . I've removed the is_organization_rep from being returned when the user login as per @meenakshi-dhanani advice here. Can you please re-review this PR? Thanks

@mtreacy002 mtreacy002 requested review from ramitsawhney27 and a team August 23, 2020 04:21
@meenakshi-dhanani
Copy link

Paired with @mtreacy002 to test this! LGTM!

@meenakshi-dhanani meenakshi-dhanani merged commit 160bc61 into anitab-org:develop Aug 23, 2020
Copy link

@foongminwong foongminwong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future reference,
This is a test case for PUT /organization:

{
  "representative_department": "momo",
  "name": "moasdea",
  "email": "maomo@test.com",
  "about": "moamo",
  "address": "123 test street",
  "website": "string",
  "timezone": "America/New_York",
  "phone": "123-445-232",
  "status": "Publish"
}

This is a test case for POST /organizations/{organization_id}/programs/program:

{
  "program_name": "Enhance soft skill program",
  "start_date": "2020-08-25 00:00",
  "end_date": "2020-09-22 11:11",
  "description": "come join us ",
  "target_skills": [
    "Public Speaking"
  ],
  "target_candidate_gender": "Not Applicable",
  "target_candidate_age": "Not Applicable",
  "target_candidate_ethnicity": "Not Applicable",
  "target_candidate_sexual_orientation": "Not Applicable",
  "target_candidate_religion": "Not Applicable",
  "target_candidate_physical_ability": "Not Applicable",
  "target_candidate_mental_ability": "Not Applicable",
  "target_candidate_socio_economic": "Not Applicable",
  "target_candidate_highest_education": "Not Applicable",
  "target_candidate_years_of_experience": "Not Applicable",
  "target_candidate_other": "",
  "payment_currency": "USD",
  "payment_amount": 0,
  "contact_type": "Face-to-face",
  "zone": "Global",
  "student_responsibility": [
    "string"
  ],
  "mentor_responsibility": [
    "string"
  ],
  "organization_responsibility": [
    "string"
  ],
  "student_requirements": [
    "string"
  ],
  "mentor_requirements": [
    "string"
  ],
  "resources_provided": [
    "string"
  ],
  "contact_name": "nicole",
  "contact_department": "momo department",
  "program_address": "123 test street",
  "contact_phone": "123-456-333",
  "contact_mobile": "123-333-333",
  "contact_email": "1sdas@df.com",
  "program_website": "https://123web.com",
  "irc_channel": "momo123",
  "tags": [
    "career"
  ],
  "status": "Open"
}

@mtreacy002 mtreacy002 deleted the feat-get-put-program-and-tests branch August 30, 2020 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Coding Changes to code base or refactored code that doesn't fix a bug. Program: GSOC Related to work completed during the Google Summer of Code Program.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feat: POST/GET/PUT for Programs API endpoints
4 participants