-
Notifications
You must be signed in to change notification settings - Fork 8
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
Conversation
WalkthroughThe 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 Changes
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
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
Possibly related PRs
Poem
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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:
- The relative path
./assets/banners.json
may behave differently across deployment environments- 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
📒 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.
Summary by CodeRabbit
New Features
Refactor