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: added gov overview endpoint #30

Merged
merged 1 commit into from
Jun 3, 2024
Merged

feat: added gov overview endpoint #30

merged 1 commit into from
Jun 3, 2024

Conversation

yevhen-burkovskyi
Copy link
Contributor

No description provided.

Copy link

coderabbitai bot commented Jun 3, 2024

Walkthrough

The update introduces governance-related functionality to the application. This includes new enums, endpoints, services, and controllers for handling governance parameters and proposals. A new GovernanceModule is integrated, with caching and scheduled jobs for governance overview data. The Okp4Service is extended to fetch governance parameters and proposals. This enhances the application by providing structured governance data management and periodic updates.

Changes

File Path Change Summary
src/core/enums/routes.enum.ts Added GOVERNANCE constant to Routes enum.
.../okp4/enums/endpoints.enum.ts Added GOV_PARAMS and GOV_PROPOSALS to Endpoints enum.
.../okp4/enums/gov-type.enum.ts Introduced GovType enum for governance types.
.../okp4/enums/proposal-status.enum.ts Introduced ProposalStatusEnum for proposal statuses.
.../okp4/enums/route-param.enum.ts Added PARAMS_TYPE to RouteParam enum.
.../okp4/okp4.service.ts Added getGovParams and getProposals methods to Okp4Service.
.../okp4/responses/get-proposals.response.ts Introduced GetProposalsResponse type and Proposal interface.
.../okp4/responses/gov-params.response.ts Introduced GovParamsResponse interface.
src/modules/app.module.ts Added GovernanceModule import to AppModule.
.../governance/dto/gov-overview.dto.ts Introduced GovOverviewDto interface for governance overview data.
.../governance/enums/governance-endpoint.enum.ts Introduced GovernanceEndpoint enum.
.../governance/governance.controller.ts Introduced GovernanceController class with overview method.
.../governance/governance.module.ts Defined GovernanceModule and added GovernanceJobs to providers.
.../governance/services/governance.cache.ts Introduced GovernanceCache class for caching governance data.
.../governance/services/governance.jobs.ts Introduced GovernanceJobs class with updateGovOverview method scheduled to run every 5 minutes.
.../governance/services/governance.service.ts Provided GovernanceService for fetching and caching governance overview data.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant User
    participant GovernanceController
    participant GovernanceService
    participant Okp4Service
    participant GovernanceCache

    User->>+GovernanceController: Request Governance Overview
    GovernanceController->>+GovernanceService: Fetch Governance Overview
    GovernanceService->>+GovernanceCache: Get Cached Overview
    alt Cache Miss
        GovernanceCache->>GovernanceService: No Data
        GovernanceService->>+Okp4Service: Fetch Proposals
        Okp4Service-->>-GovernanceService: Proposals Data
        GovernanceService->>+Okp4Service: Fetch Params
        Okp4Service-->>-GovernanceService: Params Data
        GovernanceService->>+GovernanceCache: Cache Overview Data
        GovernanceCache-->>-GovernanceService: Confirmation
    else Cache Hit
        GovernanceCache-->>-GovernanceService: Cached Data
    end
    GovernanceService-->>-GovernanceController: Overview Data
    GovernanceController-->>-User: Return Governance Overview
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 383ce3e and 740c488.

Files selected for processing (16)
  • src/core/enums/routes.enum.ts (1 hunks)
  • src/core/lib/okp4/enums/endpoints.enum.ts (1 hunks)
  • src/core/lib/okp4/enums/gov-type.enum.ts (1 hunks)
  • src/core/lib/okp4/enums/proposal-status.enum.ts (1 hunks)
  • src/core/lib/okp4/enums/route-param.enum.ts (1 hunks)
  • src/core/lib/okp4/okp4.service.ts (2 hunks)
  • src/core/lib/okp4/responses/get-proposals.response.ts (1 hunks)
  • src/core/lib/okp4/responses/gov-params.response.ts (1 hunks)
  • src/modules/app.module.ts (2 hunks)
  • src/modules/governance/dto/gov-overview.dto.ts (1 hunks)
  • src/modules/governance/enums/governance-endpoint.enum.ts (1 hunks)
  • src/modules/governance/governance.controller.ts (1 hunks)
  • src/modules/governance/governance.module.ts (1 hunks)
  • src/modules/governance/services/governance.cache.ts (1 hunks)
  • src/modules/governance/services/governance.jobs.ts (1 hunks)
  • src/modules/governance/services/governance.service.ts (1 hunks)
Files skipped from review due to trivial changes (6)
  • src/core/lib/okp4/enums/gov-type.enum.ts
  • src/core/lib/okp4/enums/proposal-status.enum.ts
  • src/core/lib/okp4/enums/route-param.enum.ts
  • src/modules/app.module.ts
  • src/modules/governance/dto/gov-overview.dto.ts
  • src/modules/governance/enums/governance-endpoint.enum.ts
Additional context used
Biome
src/modules/governance/services/governance.jobs.ts

[error] 2-3: All these imports are only used as types.

src/modules/governance/governance.controller.ts

[error] 1-2: All these imports are only used as types.

src/modules/governance/services/governance.cache.ts

[error] 1-1: All these imports are only used as types.


[error] 2-3: All these imports are only used as types.

src/core/lib/okp4/responses/get-proposals.response.ts

[error] 1-1: All these imports are only used as types.

src/modules/governance/services/governance.service.ts

[error] 34-34: Unexpected any. Specify a different type.


[error] 35-35: Template literals are preferred over string concatenation.


[error] 1-1: All these imports are only used as types.


[error] 1-2: Some named imports are only used as types.


[error] 2-3: All these imports are only used as types.


[error] 3-4: All these imports are only used as types.


[error] 5-6: All these imports are only used as types.

src/core/lib/okp4/okp4.service.ts

[error] 156-156: The computed expression can be simplified without the use of a string literal.


[error] 156-156: The computed expression can be simplified without the use of a string literal.


[error] 156-156: The computed expression can be simplified without the use of a string literal.


[error] 156-156: The computed expression can be simplified without the use of a string literal.


[error] 156-156: The computed expression can be simplified without the use of a string literal.


[error] 164-165: Change to an optional chain.


[error] 171-171: Unexpected any. Specify a different type.


[error] 172-172: Template literals are preferred over string concatenation.


[error] 193-193: Unexpected any. Specify a different type.


[error] 203-203: Unexpected any. Specify a different type.


[error] 2-3: All these imports are only used as types.


[error] 3-4: All these imports are only used as types.


[error] 4-5: All these imports are only used as types.


[error] 7-8: All these imports are only used as types.


[error] 8-9: All these imports are only used as types.


[error] 10-11: All these imports are only used as types.


[error] 11-12: All these imports are only used as types.


[error] 12-13: All these imports are only used as types.


[error] 13-14: All these imports are only used as types.


[error] 15-16: All these imports are only used as types.

Additional comments not posted (7)
src/core/enums/routes.enum.ts (1)

5-5: The addition of the GOVERNANCE route aligns well with the new governance functionalities.

src/modules/governance/services/governance.jobs.ts (1)

1-15: The implementation of GovernanceJobs with a scheduled task to update the governance overview is well done. The use of @Cron for scheduling is appropriate.

Tools
Biome

[error] 2-3: All these imports are only used as types.

src/modules/governance/governance.controller.ts (1)

1-14: The GovernanceController is well-implemented with clear and concise use of decorators for routing and dependency injection.

Tools
Biome

[error] 1-2: All these imports are only used as types.

src/modules/governance/governance.module.ts (1)

1-21: The GovernanceModule is correctly set up with all necessary imports and providers, encapsulating the governance functionalities effectively.

src/core/lib/okp4/enums/endpoints.enum.ts (1)

12-13: The addition of GOV_PARAMS and GOV_PROPOSALS endpoints is appropriate for the enhanced governance functionalities.

src/modules/governance/services/governance.cache.ts (1)

1-30: The implementation of GovernanceCache using Redis for caching governance overview data is well done. The methods are clear and the use of Redis is appropriate for the intended caching functionality.

Tools
Biome

[error] 1-1: All these imports are only used as types.


[error] 2-3: All these imports are only used as types.

src/core/lib/okp4/okp4.service.ts (1)

178-190: Ensure proper error handling in new governance-related methods.

The new methods getGovParams and getProposals should properly handle errors. Consider wrapping these calls in try-catch blocks or ensuring that the getWithErrorHandling method adequately handles all potential errors.

Verification successful

The getWithErrorHandling method in okp4.service.ts uses the errorHandleWrapper method, which includes proper error handling by catching exceptions and throwing a BadRequestException with the error message. Therefore, the new methods getGovParams and getProposals are adequately covered by this error handling mechanism.

  • getWithErrorHandling calls errorHandleWrapper, which has a try-catch block to handle errors.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify error handling in new methods.

# Test: Search for error handling patterns in new methods. Expect: Proper error handling.
rg --type typescript $'try {.*getGovParams.*} catch'
rg --type typescript $'try {.*getProposals.*} catch'

Length of output: 339



Script:

#!/bin/bash
# Description: Verify error handling in new methods.

# Test: Search for error handling patterns in new methods. Expect: Proper error handling.
rg --type typescript 'try \{.*getGovParams.*\} catch'
rg --type typescript 'try \{.*getProposals.*\} catch'

Length of output: 181



Script:

#!/bin/bash
# Description: Verify error handling in new methods.

# Test: Search for error handling patterns in new methods. Expect: Proper error handling.
rg --type ts 'try \{.*getGovParams.*\} catch'
rg --type ts 'try \{.*getProposals.*\} catch'

Length of output: 95



Script:

#!/bin/bash
# Description: Verify error handling in the getWithErrorHandling method.

# Locate the implementation of getWithErrorHandling
rg 'getWithErrorHandling'

# Extract the implementation of getWithErrorHandling
ast-grep --lang typescript --pattern 'getWithErrorHandling($_) { $$$ }'

Length of output: 2309



Script:

#!/bin/bash
# Description: Verify error handling in the getWithErrorHandling method.

# Extract the implementation of getWithErrorHandling from okp4.service.ts
ast-grep --lang typescript --pattern 'private getWithErrorHandling<T>(url: string): Promise<T> { $$$ }'

Length of output: 592



Script:

#!/bin/bash
# Description: Verify error handling in the getWithErrorHandling method.

# Extract the implementation of getWithErrorHandling from okp4.service.ts
ast-grep --lang typescript --pattern 'getWithErrorHandling<T>($_) { $$$ }'

Length of output: 534



Script:

#!/bin/bash
# Description: Verify error handling in the getWithErrorHandling method.

# Extract the implementation of getWithErrorHandling from okp4.service.ts
ast-grep --lang typescript --pattern 'getWithErrorHandling($_) { $$$ }'

Length of output: 528



Script:

#!/bin/bash
# Description: Verify error handling in the getWithErrorHandling method.

# Extract the implementation of getWithErrorHandling from okp4.service.ts
rg -A 20 'private getWithErrorHandling<T>(url: string): Promise<T>' src/core/lib/okp4/okp4.service.ts

Length of output: 103



Script:

#!/bin/bash
# Description: Verify error handling in the getWithErrorHandling method.

# Locate the file containing getWithErrorHandling method
file_path=$(fd okp4.service.ts)

# Extract the implementation of getWithErrorHandling from the located file
cat $file_path | sed -n '/private getWithErrorHandling<T>(url: string): Promise<T>/,/^}/p'

Length of output: 5186

@dbatarin dbatarin merged commit 6400ec3 into main Jun 3, 2024
11 checks passed
@dbatarin dbatarin deleted the feat/gov-overview branch June 3, 2024 10:31
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.

3 participants