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

Rundown api #1129

Merged
merged 2 commits into from
Jul 11, 2024
Merged

Rundown api #1129

merged 2 commits into from
Jul 11, 2024

Conversation

cpvalente
Copy link
Owner

This PR exposes the list of changes in the refetch message.
This means that consumers can know which events are affected by a change

In addition, we also add a few endpoints for granular rundown getting

  • paginated query params for rundown
  • getEventById

@cpvalente cpvalente requested a review from jwetzell July 10, 2024 11:24
Copy link
Contributor

coderabbitai bot commented Jul 10, 2024

Walkthrough

The recent changes introduce pagination to the rundown retrieval process, add new endpoint functions for retrieving rundown data by ID and paginated data, enhance validation mechanisms, and include new tests. Significant modifications in the RundownService and RuntimeService improve event handling and notification processes.

Changes

File Path Change Summary
rundown.controller.ts Added pagination and new endpoint functions for rundown retrieval. Changed rundownGetAll function signature.
rundown.router.ts Updated routing logic to include new functions for rundown data by ID and pagination.
rundown.validation.ts Enhanced validations to include query parameters for pagination.
RundownService.ts Modified notifyChanges to conditionally pass an array to sendRefetch based on options.timer type.
__tests__/rundownUtils.test.ts Introduced tests for getPaginated function, covering various scenarios.
RuntimeService.ts Enhanced event handling logic with isOntimeEvent function.

Sequence Diagram(s)

New Rundown Retrieval Flow

sequenceDiagram
    participant Client
    participant Router
    participant Controller
    participant Service

    Client->>Router: Request rundown data (paginated)
    Router->>Controller: Forward request
    Controller->>Service: Fetch paginated rundown data
    Service->>Controller: Return paginated data
    Controller->>Router: Send response
    Router->>Client: Return paginated rundown data

    Client->>Router: Request rundown data by ID
    Router->>Controller: Forward request
    Controller->>Service: Fetch rundown data by ID
    Service->>Controller: Return specific rundown data
    Controller->>Router: Send response
    Router->>Client: Return rundown data by ID
Loading

Updated Validation Flow

sequenceDiagram
    participant Client
    participant Router
    participant Validation
    participant Controller

    Client->>Router: Request with query parameters
    Router->>Validation: Validate query parameters
    Validation->>Router: Validation result
    Router->>Controller: Forward request
    Controller->>Router: Process request
    Router->>Client: Send response
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
Contributor

@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: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e90e948 and 33e1d28.

Files ignored due to path filters (2)
  • packages/types/src/api/ontime-controller/BackendResponse.type.ts is excluded by none and included by none
  • packages/types/src/index.ts is excluded by none and included by none
Files selected for processing (7)
  • apps/server/src/api-data/rundown/rundown.controller.ts (2 hunks)
  • apps/server/src/api-data/rundown/rundown.router.ts (3 hunks)
  • apps/server/src/api-data/rundown/rundown.validation.ts (2 hunks)
  • apps/server/src/services/rundown-service/RundownService.ts (1 hunks)
  • apps/server/src/services/rundown-service/tests/rundownUtils.test.ts (1 hunks)
  • apps/server/src/services/rundown-service/rundownUtils.ts (3 hunks)
  • apps/server/src/services/runtime-service/RuntimeService.ts (5 hunks)
Files skipped from review due to trivial changes (1)
  • apps/server/src/services/rundown-service/RundownService.ts
Additional comments not posted (15)
apps/server/src/services/rundown-service/__tests__/rundownUtils.test.ts (3)

13-20: LGTM! Correctly tests pagination logic.

The test case accurately verifies the pagination logic by checking the length and total of the paginated rundown.


22-29: LGTM! Correctly handles overflows.

The test case accurately verifies that the pagination function handles overflows by setting a limit greater than the total number of items and checking the length and total of the paginated rundown.


31-38: LGTM! Correctly handles out-of-range offsets.

The test case accurately verifies that the pagination function handles out-of-range offsets by setting an offset greater than the total number of items and checking the length and total of the paginated rundown.

apps/server/src/api-data/rundown/rundown.router.ts (3)

30-30: LGTM! Correctly maps to the new function with validation.

The route / is correctly mapped to rundownGetPaginated and includes the necessary validation for query parameters.


31-31: LGTM! Correctly maps to the new function with validation.

The route /:eventId is correctly mapped to rundownGetById and includes the necessary validation for the eventId parameter.


8-10: LGTM! Correct function imports.

The import changes align with the updated routes and function signatures, correctly importing the new functions and removing the obsolete one.

apps/server/src/api-data/rundown/rundown.validation.ts (1)

79-88: LGTM! Well-defined validation rules.

The validation rules for the offset and limit query parameters are well-defined and include error handling.

apps/server/src/services/rundown-service/rundownUtils.ts (2)

56-58: LGTM! Correctly updated return type.

The function getEventWithId has been updated to return OntimeRundownEntry instead of OntimeEvent, aligning with the new type requirements.


125-135: LGTM! Efficient pagination logic.

The getPaginated function correctly returns paginated rundown data using the provided offset and limit, efficiently handling pagination.

apps/server/src/api-data/rundown/rundown.controller.ts (3)

29-44: LGTM!

The rundownGetById function is correctly implemented with proper error handling.


46-72: LGTM!

The rundownGetPaginated function is correctly implemented with proper error handling and query parameter parsing.


1-1: LGTM!

The function signature change for rundownGetAll aligns with the new functionality of returning paginated data.

apps/server/src/services/runtime-service/RuntimeService.ts (3)

229-231: LGTM!

The usage of isOntimeEvent in the maybeUpdate function ensures type safety and prevents potential runtime errors.


279-281: LGTM!

The usage of isOntimeEvent in the startById function ensures that only valid events are started, preventing potential runtime errors.


330-332: LGTM!

The usage of isOntimeEvent in the loadById function ensures that only valid events are loaded, preventing potential runtime errors.

Copy link
Contributor

@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: 0

Outside diff range, codebase verification and nitpick comments (1)
apps/server/src/api-data/rundown/rundown.validation.ts (1)

79-88: LGTM! Consider adding a comment for clarity.

The validation logic for offset and limit query parameters looks good. Consider adding a brief comment explaining the purpose of this validation array.

+// Validates optional numeric query parameters 'offset' and 'limit' for pagination
export const rundownGetPaginatedQueryParams = [
  query('offset').isNumeric().optional(),
  query('limit').isNumeric().optional(),

  (req: Request, res: Response, next: NextFunction) => {
    const errors = validationResult(req);
    if (!errors.isEmpty()) return res.status(422).json({ errors: errors.array() });
    next();
  },
];
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 33e1d28 and 295f5ef.

Files ignored due to path filters (2)
  • packages/types/src/api/ontime-controller/BackendResponse.type.ts is excluded by none and included by none
  • packages/types/src/index.ts is excluded by none and included by none
Files selected for processing (6)
  • apps/server/src/api-data/rundown/rundown.controller.ts (2 hunks)
  • apps/server/src/api-data/rundown/rundown.router.ts (3 hunks)
  • apps/server/src/api-data/rundown/rundown.validation.ts (2 hunks)
  • apps/server/src/services/rundown-service/tests/rundownUtils.test.ts (1 hunks)
  • apps/server/src/services/rundown-service/rundownUtils.ts (3 hunks)
  • apps/server/src/services/runtime-service/RuntimeService.ts (5 hunks)
Files skipped from review as they are similar to previous changes (5)
  • apps/server/src/api-data/rundown/rundown.controller.ts
  • apps/server/src/api-data/rundown/rundown.router.ts
  • apps/server/src/services/rundown-service/tests/rundownUtils.test.ts
  • apps/server/src/services/rundown-service/rundownUtils.ts
  • apps/server/src/services/runtime-service/RuntimeService.ts

@cpvalente cpvalente requested a review from alex-Arc July 10, 2024 21:02
Copy link
Collaborator

@jwetzell jwetzell left a comment

Choose a reason for hiding this comment

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

I tested the pagination/limit stuff and then fetching by id and everything seemed to behave as expected and return the correct data

@cpvalente cpvalente merged commit 917b182 into master Jul 11, 2024
3 checks passed
@cpvalente cpvalente deleted the rundowna-api branch July 11, 2024 09:03
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.

None yet

2 participants