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: Add Fault Portal API endpoints #109

Merged
merged 3 commits into from
May 19, 2024
Merged

feat: Add Fault Portal API endpoints #109

merged 3 commits into from
May 19, 2024

Conversation

GuyKh
Copy link
Owner

@GuyKh GuyKh commented May 19, 2024

User description

What changes do you are proposing?

Add Fault Portal API endpoints
https://masa-mainportalapi.iec.co.il/api

How did you test these changes?

Closing issues


PR Type

Enhancement


Description

  • Added constants for Fault Portal API URLs in iec_api/const.py.
  • Implemented functions in iec_api/fault_portal_data.py to fetch user profiles and outages from the Fault Portal API.
  • Defined data models for outages and user profiles in iec_api/fault_portal_models/outages.py and iec_api/fault_portal_models/user_profile.py.
  • Integrated these new API endpoints into the IEC client class in iec_api/iec_client.py, providing methods to fetch user profiles and outages.

Changes walkthrough 📝

Relevant files
Enhancement
const.py
Add Fault Portal API URL Constants                                             

iec_api/const.py

  • Added new constants for Fault Portal API URLs.
+5/-0     
fault_portal_data.py
Implement Fault Portal API Data Fetching Functions             

iec_api/fault_portal_data.py

  • Added functions to fetch user profile and outages from Fault Portal
    API.
  • +35/-0   
    outages.py
    Define Outage Models for Fault Portal API                               

    iec_api/fault_portal_models/outages.py

    • Defined data models for outages response from Fault Portal API.
    +26/-0   
    user_profile.py
    Define User Profile Models for Fault Portal API                   

    iec_api/fault_portal_models/user_profile.py

  • Defined data models for user profile response from Fault Portal API.
  • +65/-0   
    iec_client.py
    Integrate Fault Portal API Endpoints into IEC Client         

    iec_api/iec_client.py

    • Integrated Fault Portal API endpoints into the IEC client class.
    +37/-1   

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    @codiumai-pr-agent-pro codiumai-pr-agent-pro bot added the enhancement New feature or request label May 19, 2024
    Copy link

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Description updated to latest commit (542d9ed)

    Copy link

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Review 🔍

    ⏱️ Estimated effort to review [1-5]

    3, because the PR involves multiple files and introduces new functionality with integration into an existing system. The changes include API endpoint integrations, data model definitions, and updates to the client class. Reviewing this PR requires understanding the new API endpoints, checking the data models for correctness, and ensuring that the integration with the existing system is done correctly.

    🧪 Relevant tests

    No

    ⚡ Possible issues

    Possible Bug: The get_outages_by_account function in fault_portal_data.py incorrectly uses GET_USER_PROFILE_FROM_FAULT_PORTAL_URL for fetching outages. It should use GET_OUTAGES_FROM_FAULT_PORTAL_URL instead.

    Data Handling: Ensure that the error handling is robust in scenarios where the API might return unexpected responses or errors.

    🔒 Security concerns

    No

    Copy link

    PR-Agent was enabled for this repository. To continue using it, please link your git user with your CodiumAI identity here.

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Possible bug
    Correct the URL formatting by removing the double slash

    Remove the double slash in the base URL to ensure proper URL formatting.

    iec_api/const.py [27]

    -IEC_API_BASE_URL = "https://iecapi.iec.co.il//api/"
    +IEC_API_BASE_URL = "https://iecapi.iec.co.il/api/"
     
    Suggestion importance[1-10]: 10

    Why: The suggestion correctly identifies a potential bug in the URL formatting which can lead to incorrect URL resolution.

    10
    Use the correct API endpoint for fetching outages

    Correct the URL used in the get_outages_by_account function to use the correct endpoint
    for outages.

    iec_api/fault_portal_data.py [31]

     response = await commons.send_get_request(
    -    session=session, url=GET_USER_PROFILE_FROM_FAULT_PORTAL_URL, headers=headers
    +    session=session, url=GET_OUTAGES_FROM_FAULT_PORTAL_URL.format(account_id=account_id), headers=headers
     )
     
    Suggestion importance[1-10]: 10

    Why: The suggestion correctly identifies a critical bug where the wrong URL is used, potentially leading to incorrect API calls and data retrieval.

    10
    Correct the field alias to match the JSON key from the API response

    Correct the alias for government_id in the UserProfile dataclass to match the expected
    JSON key.

    iec_api/fault_portal_models/user_profile.py [55]

    -government_id: Optional[str] = field(metadata=field_options(alias="government_id"))
    +government_id: Optional[str] = field(metadata=field_options(alias="governmentid"))
     
    Suggestion importance[1-10]: 10

    Why: The suggestion correctly identifies a mismatch in the JSON key alias which is crucial for proper data serialization and deserialization.

    10
    Enhancement
    Correct the syntax for the return type annotation

    Add type hinting for the return type of get_fault_portal_outages_by_account to correctly
    reflect that it returns a list of FaultPortalOutage or None.

    iec_api/iec_client.py [466]

    -) -> (Optional)[List[FaultPortalOutage]]:
    +) -> Optional[List[FaultPortalOutage]]:
     
    Suggestion importance[1-10]: 8

    Why: The suggestion correctly identifies a syntax error in the type hinting which improves the code readability and correctness, though it's less critical compared to the other issues.

    8

    @GuyKh GuyKh merged commit 413853b into main May 19, 2024
    1 check passed
    @GuyKh GuyKh deleted the fault-portal branch May 19, 2024 08:09
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    None yet

    1 participant