Skip to content

feat(blog): store banners as static json asset #415

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

Merged
merged 1 commit into from
Mar 26, 2025
Merged

Conversation

DDonochVA
Copy link
Contributor

@DDonochVA DDonochVA commented Mar 26, 2025

Summary by CodeRabbit

  • New Features

    • Introduced banner management functionality with dynamic retrieval and customizable slide display settings.
  • Refactor

    • Streamlined the banner data retrieval process by leveraging a local configuration, enhancing consistency and reliability in banner displays.

Copy link

coderabbitai bot commented Mar 26, 2025

Walkthrough

The changes update the blog route-building process by introducing a new function to fetch banner data and write it to a JSON file. A constant is added to define the banner file path, and error handling is incorporated during fetching and writing operations. A new JSON file is created to store banner configuration details. In addition, the AdBannerService has been modified to retrieve banner data from this local JSON file instead of via an API request, with an updated transformation step for the response.

Changes

File(s) Change Summary
apps/blog/.../build-routes.mjs
apps/blog/.../banners.json
Added banner support: introduced fetchBannersAndWriteToFile to fetch banner data and write it to a JSON file, and added a JSON configuration file for banners.
libs/blog/.../ad-banner.service.ts Modified AdBannerService.getBannerSlider to read banner data from the local JSON file, replacing the API-based approach and adding a response transformation.

Sequence Diagram(s)

sequenceDiagram
  participant Main as Main Function
  participant FetchBanners as fetchBannersAndWriteToFile
  participant API as Banner API
  participant FS as File System
  
  Main->>FetchBanners: Call fetchBannersAndWriteToFile
  FetchBanners->>API: Request banner data
  API-->>FetchBanners: Return banner data
  FetchBanners->>FS: Write data to banners JSON file
  FS-->>FetchBanners: Confirm file write
  FetchBanners-->>Main: Complete operation
Loading
sequenceDiagram
  participant Client as Client
  participant Service as AdBannerService.getBannerSlider
  participant FS as File System
  
  Client->>Service: Request banner slider
  Service->>FS: Read banners.json file
  FS-->>Service: Return banner JSON data
  Service-->>Client: Return extracted slider information
Loading

Possibly related PRs

Poem

Hoppity-hop, I'm a rabbit so spry,
Fetching banners as the hours fly.
JSON files dance, data in tune,
Routes and sliders under the moon.
Code hops along with a joyful sigh!
🐰✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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: 0

🧹 Nitpick comments (1)
libs/blog/ad-banner/data-access/src/lib/infrastructure/ad-banner.service.ts (1)

12-14: Consider adding error handling and validating the relative path.

The implementation has been changed to fetch banner data from a local JSON file instead of an API, which aligns with the new architecture. However:

  1. The relative path ./assets/banners.json may behave differently across deployment environments
  2. There's no error handling for failed HTTP requests

Consider adding error handling with the catchError operator:

import { HttpClient } from '@angular/common/http';
import { inject, Injectable } from '@angular/core';
-import { map } from 'rxjs';
+import { map, catchError } from 'rxjs';
+import { Observable, of } from 'rxjs';

import { Slider } from '@angular-love/blog/contracts/banners';

@Injectable({ providedIn: 'root' })
export class AdBannerService {
  private readonly _http = inject(HttpClient);

  getBannerSlider() {
    return this._http
      .get<{ banners: Slider }>(`./assets/banners.json`)
-      .pipe(map((resp) => resp.banners));
+      .pipe(
+        map((resp) => resp.banners),
+        catchError((error) => {
+          console.error('Failed to load banner data:', error);
+          return of({ slideDisplayTimeMs: 9000, slides: [] });
+        })
+      );
  }
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f26f924 and a241922.

📒 Files selected for processing (3)
  • apps/blog/scripts/build-routes.mjs (3 hunks)
  • apps/blog/src/assets/banners.json (1 hunks)
  • libs/blog/ad-banner/data-access/src/lib/infrastructure/ad-banner.service.ts (1 hunks)
🔇 Additional comments (5)
apps/blog/src/assets/banners.json (1)

1-6: Clean and well-structured JSON file for banner configuration.

The JSON structure is appropriate for storing banner configuration with a slide display time and an empty array for slides that will be populated during the build process.

libs/blog/ad-banner/data-access/src/lib/infrastructure/ad-banner.service.ts (1)

3-3: Good addition of the map operator.

The import of the map operator is necessary for the transformation in the updated implementation.

apps/blog/scripts/build-routes.mjs (3)

10-10: Good use of a constant for the file path.

Using a constant for the banners file path maintains consistency with other file paths in the script.


104-133: Well-implemented function with proper error handling.

The fetchBannersAndWriteToFile function follows the same pattern as the existing code for fetching article and author routes. It includes proper error handling for both fetch and file write operations.

Note that unlike the article and author fetch functions, there's no pagination implemented. This assumes the banner data is small enough to fetch in a single request, which is likely true for banner data.


217-217: Good integration with existing concurrent operations.

The new function is properly integrated into the main function to run concurrently with other fetch operations.

@DDonochVA DDonochVA merged commit 8ae05c0 into main Mar 26, 2025
1 check passed
@DDonochVA DDonochVA deleted the feat/banners-asset branch March 26, 2025 22:06
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.

1 participant