Skip to content

Sanky chart endpoint update#94

Open
yasandu0505 wants to merge 8 commits intoLDFLK:mainfrom
yasandu0505:sanky-chart-endpoint-update
Open

Sanky chart endpoint update#94
yasandu0505 wants to merge 8 commits intoLDFLK:mainfrom
yasandu0505:sanky-chart-endpoint-update

Conversation

@yasandu0505
Copy link
Member

  • Refactored the code
  • Removed unnecessary code snippets
  • used enums when necessary

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors and updates the API endpoints related to organizational data, specifically for generating cabinet flow visualizations. It introduces a new, dedicated endpoint for this functionality, centralizing the complex data processing logic within the OrganisationService. The changes aim to improve code organization, remove deprecated or unused code, and enhance the maintainability of the data retrieval processes.

Highlights

  • New Cabinet Flow Endpoint: Introduced a new POST endpoint /v1/organisation/cabinet-flow/{president_id} to retrieve cabinet flow data for a given president and date range, replacing previous Sankey chart logic.
  • Sankey Chart Logic Refactoring: The core logic for generating Sankey chart data has been refactored and moved into the OrganisationService, including new methods for fetching active ministers and departments.
  • Code Cleanup and Removal of Unused Endpoints: Removed the old /data/orgchart/sankey/{entityId} endpoint and several other commented-out orgchart-related endpoints from payload_incoming_router.py.
  • Type Hinting Improvements: Utilized Sequence type hint for better clarity and type safety in function signatures.
Changelog
  • src/routers/organisation_router.py
    • Imported Sequence for type hinting.
    • Added a new POST endpoint /cabinet-flow/{president_id} to fetch cabinet flow data.
  • src/routers/payload_incoming_router.py
    • Commented out a call to create_parent_categories_and_children_categories_v2.
    • Removed the /data/orgchart/sankey/{entityId} endpoint.
    • Removed several commented-out orgchart-related endpoints.
  • src/services/organisation_service.py
    • Imported Sequence and removed re import.
    • Added get_active_ministers method to fetch ministers active on a given date.
    • Added get_active_departments method to fetch departments for a minister on a given date.
    • Added get_ministers_and_departments method to orchestrate fetching ministers and their departments.
    • Implemented fetch_cabinet_flow method to process dates, gather minister and department data, and construct nodes and links for a Sankey chart.
Activity
  • No specific activity (comments, reviews, approvals) has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the Sankey chart endpoint, moving it to the organisation_router and implementing the service logic in organisation_service, including new asynchronous logic to process data for the cabinet flow. A critical Denial of Service (DoS) vulnerability has been identified in the new endpoint /v1/organisation/cabinet-flow/{president_id}. The code uses unbounded concurrency via asyncio.gather to process multiple dates and ministers, which could be exploited by providing a large list of dates, leading to resource exhaustion and a flood of requests to the internal OpenGIN service. It is highly recommended to implement input validation to limit the number of dates and use a semaphore to control the maximum number of concurrent outgoing requests. Additionally, the review suggests improvements in code style, correctness, and documentation, such as using list comprehensions for conciseness, correcting parameter naming to follow PEP-8, updating docstrings, and addressing a potentially redundant error check.

Copy link
Member

Choose a reason for hiding this comment

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

update the API Contract with this API endpoint

Copy link
Member Author

Choose a reason for hiding this comment

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

sure , will do

Copy link
Member Author

Choose a reason for hiding this comment

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

@ChanukaUOJ , and there is an issue with the organisation api contract , some syntax error ,can you check it ?

Copy link
Member Author

Choose a reason for hiding this comment

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

@ChanukaUOJ check the line no. 756, there is an issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants