Skip to content

chore: add services#4

Open
santoshyadavdev wants to merge 1 commit intomainfrom
santoshyadavdev/chore/add-service
Open

chore: add services#4
santoshyadavdev wants to merge 1 commit intomainfrom
santoshyadavdev/chore/add-service

Conversation

@santoshyadavdev
Copy link
Owner

@santoshyadavdev santoshyadavdev commented Mar 5, 2026

Summary by CodeRabbit

  • New Features

    • Added booking count display on the dashboard.
    • Implemented dynamic hotel data loading system.
    • Added functionality to remove rooms from bookings.
  • Tests

    • Added unit tests for hotel data management.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 5, 2026

📝 Walkthrough

Walkthrough

A new PropertyService is introduced to manage hotel data using Angular signals. The service provides a getHotels() method that returns a signal containing hardcoded hotel data. The main app and dashboard components now inject this service via Angular's DI system to access hotel information, replacing previously hardcoded lists. A unit test for the service is also added.

Changes

Cohort / File(s) Summary
New PropertyService
apps/hotelmanagement/src/app/dashboard/property.ts
Introduces PropertyService with injectable signal-based hotels list and getHotels() method returning hardcoded hotel data.
PropertyService Tests
apps/hotelmanagement/src/app/dashboard/property.spec.ts
New unit test file verifying PropertyService instantiation via TestBed.
Component DI Integration
apps/hotelmanagement/src/app/app.ts, apps/hotelmanagement/src/app/dashboard/dashboard.ts
Both components updated to inject PropertyService for hotel data retrieval; dashboard also adds numberOfBookings signal and handleRemoveRooms() method placeholder.

Sequence Diagram

sequenceDiagram
    participant App as App Component
    participant DI as Angular DI
    participant PropertyService
    participant Hotels as Hotels Signal

    App->>DI: inject(PropertyService)
    DI->>PropertyService: Create instance
    PropertyService->>Hotels: Initialize empty signal
    App->>PropertyService: getHotels()
    PropertyService->>Hotels: Populate with hardcoded data
    PropertyService-->>App: Return hotels signal
    App->>Hotels: Subscribe/Read signal
    Hotels-->>App: Display hotel list
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • chore: add template syntax and signals #2: Both PRs modify dashboard.ts's hotelList and signal-based state management, with this PR extracting initialization into a dedicated PropertyService.
  • chore: add input/output #3: Both PRs modify dashboard hotel data flow, with this PR introducing the PropertyService to centralize hotel data management.

Suggested labels

enhancement

Poem

🐰 A service hops forth with hotels in tow,
Signals dance brightly in Angular's glow,
DI wires the paths where dependencies flow,
No hardcoding now—just data's clean show! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'chore: add services' accurately describes the main change: introducing a new PropertyService and integrating it across multiple components.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch santoshyadavdev/chore/add-service

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai bot added the enhancement New feature or request label Mar 5, 2026
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: 1

🧹 Nitpick comments (3)
apps/hotelmanagement/src/app/dashboard/property.spec.ts (1)

13-15: Add a behavior test for getHotels() output.

This currently checks only instantiation. Please also assert the returned hotels shape/count so service behavior is covered.

✅ Suggested test addition
 describe('PropertyService', () => {
@@
   it('should be created', () => {
     expect(service).toBeTruthy();
   });
+
+  it('should return the seeded hotels list', () => {
+    const hotels = service.getHotels()();
+    expect(hotels.length).toBe(3);
+    expect(hotels[0].name).toBe('Hotel California');
+  });
 });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/hotelmanagement/src/app/dashboard/property.spec.ts` around lines 13 -
15, Add a unit test in property.spec.ts that calls the service.getHotels()
method and asserts the returned value shape and count: invoke getHotels() (or
getHotels().subscribe if it returns an Observable) on the existing service
instance, then expect the result to be an array of hotel objects with the
expected length and required properties (e.g., id, name, address). Make the test
use the same setup/DI as the existing "should be created" spec and mock any
dependencies or provide fake data as needed so the assertion verifies both shape
(keys) and count.
apps/hotelmanagement/src/app/dashboard/property.ts (2)

10-12: Remove constructor console logging in service initialization.

Line 11 logs on every service creation and can add noise in production/test output.

🧹 Proposed cleanup
-  constructor() {
-    console.log('PropertyService initialized');
-  }
+  constructor() {}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/hotelmanagement/src/app/dashboard/property.ts` around lines 10 - 12, The
PropertyService constructor currently contains a console.log('PropertyService
initialized') that should be removed to avoid noisy output; edit the constructor
in the PropertyService class (the constructor method shown in the diff) to
delete the console.log call and, if initialization telemetry is required,
replace it with the project's structured logger (e.g., use the shared logger
instance or a debug-level logger) rather than console.log.

8-37: Make getHotels() read-only and side-effect free.

The method currently mutates state on every read (line 16: this.hotels.set()), and returning the writable signal exposes write access that external code could exploit. Initialize the data once and return a readonly signal via asReadonly() to prevent mutations and side effects.

♻️ Proposed refactor
-import { Injectable, signal } from '@angular/core';
+import { Injectable, Signal, signal } from '@angular/core';
 import { IHotel } from './Hotel';
@@
 export class PropertyService {
-  hotels = signal<IHotel[]>([]);
+  private readonly hotels = signal<IHotel[]>([
+    {
+      id: 1,
+      name: 'Hotel California',
+      location: 'Los Angeles',
+      numberOfRooms: 0,
+    },
+    {
+      id: 2,
+      name: 'The Grand Budapest Hotel',
+      location: 'Zubrowka',
+      numberOfRooms: 200,
+    },
+    {
+      id: 3,
+      name: 'The Overlook Hotel',
+      location: 'Colorado',
+      numberOfRooms: 10,
+    },
+  ]);
@@
-  getHotels() {
-    // This method would typically make an HTTP request to fetch hotel data
-    this.hotels.set([
-      {
-        id: 1,
-        name: 'Hotel California',
-        location: 'Los Angeles',
-        numberOfRooms: 0,
-      },
-      {
-        id: 2,
-        name: 'The Grand Budapest Hotel',
-        location: 'Zubrowka',
-        numberOfRooms: 200,
-      },
-      {
-        id: 3,
-        name: 'The Overlook Hotel',
-        location: 'Colorado',
-        numberOfRooms: 10,
-      },
-    ]);
-    return this.hotels;
+  getHotels(): Signal<IHotel[]> {
+    return this.hotels.asReadonly();
   }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/hotelmanagement/src/app/dashboard/property.ts` around lines 8 - 37, The
getHotels method currently mutates the hotels signal on every call and returns a
writable signal; change this by initializing the hotel array only once (either
as the initial value when creating hotels = signal<IHotel[]>([...]) or by
setting it in the constructor) and make getHotels return a readonly view using
this.hotels.asReadonly() (remove the this.hotels.set(...) from getHotels so it
becomes side-effect free and only exposes the readonly signal). Ensure
references to hotels, getHotels, constructor, and asReadonly() are updated
accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@apps/hotelmanagement/src/app/dashboard/dashboard.ts`:
- Line 10: Remove the redundant component-level provider for PropertyService in
the Dashboard component so the component uses the singleton root-provided
instance (providedIn: 'root') instead of creating a local instance;
specifically, delete PropertyService from the Dashboard component's providers
array (the providers: [PropertyService] entry) so both Dashboard and the App use
the same PropertyService and share the hotels signal state.

---

Nitpick comments:
In `@apps/hotelmanagement/src/app/dashboard/property.spec.ts`:
- Around line 13-15: Add a unit test in property.spec.ts that calls the
service.getHotels() method and asserts the returned value shape and count:
invoke getHotels() (or getHotels().subscribe if it returns an Observable) on the
existing service instance, then expect the result to be an array of hotel
objects with the expected length and required properties (e.g., id, name,
address). Make the test use the same setup/DI as the existing "should be
created" spec and mock any dependencies or provide fake data as needed so the
assertion verifies both shape (keys) and count.

In `@apps/hotelmanagement/src/app/dashboard/property.ts`:
- Around line 10-12: The PropertyService constructor currently contains a
console.log('PropertyService initialized') that should be removed to avoid noisy
output; edit the constructor in the PropertyService class (the constructor
method shown in the diff) to delete the console.log call and, if initialization
telemetry is required, replace it with the project's structured logger (e.g.,
use the shared logger instance or a debug-level logger) rather than console.log.
- Around line 8-37: The getHotels method currently mutates the hotels signal on
every call and returns a writable signal; change this by initializing the hotel
array only once (either as the initial value when creating hotels =
signal<IHotel[]>([...]) or by setting it in the constructor) and make getHotels
return a readonly view using this.hotels.asReadonly() (remove the
this.hotels.set(...) from getHotels so it becomes side-effect free and only
exposes the readonly signal). Ensure references to hotels, getHotels,
constructor, and asReadonly() are updated accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: aab25bd9-e863-4f6c-852b-d75ae4fcb54c

📥 Commits

Reviewing files that changed from the base of the PR and between d816dee and 8688e34.

📒 Files selected for processing (4)
  • apps/hotelmanagement/src/app/app.ts
  • apps/hotelmanagement/src/app/dashboard/dashboard.ts
  • apps/hotelmanagement/src/app/dashboard/property.spec.ts
  • apps/hotelmanagement/src/app/dashboard/property.ts

imports: [Hotel],
templateUrl: './dashboard.html',
styleUrl: './dashboard.css',
providers: [PropertyService],
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

find . -type f -name "*.ts" | grep -E "(dashboard|property)" | head -20

Repository: santoshyadavdev/live-stream-coderabbit

Length of output: 831


🏁 Script executed:

cat -n apps/hotelmanagement/src/app/dashboard/dashboard.ts

Repository: santoshyadavdev/live-stream-coderabbit

Length of output: 993


🏁 Script executed:

cat -n apps/hotelmanagement/src/app/dashboard/property.ts

Repository: santoshyadavdev/live-stream-coderabbit

Length of output: 1143


🏁 Script executed:

cat -n apps/hotelmanagement/src/app/app.ts

Repository: santoshyadavdev/live-stream-coderabbit

Length of output: 643


🏁 Script executed:

rg -nP --type ts 'providedIn|PropertyService' apps/hotelmanagement/src/app/

Repository: santoshyadavdev/live-stream-coderabbit

Length of output: 1213


Remove redundant PropertyService provider from Dashboard component.

PropertyService is already provided at root level via providedIn: 'root' (property.ts line 5). Re-providing it at the component level creates a separate instance, causing the hotels signal state to diverge between the App component (root instance) and Dashboard component (local instance). This prevents them from sharing the same data.

🔧 Proposed fix
 `@Component`({
   selector: 'hm-dashboard',
   imports: [Hotel],
   templateUrl: './dashboard.html',
   styleUrl: './dashboard.css',
-  providers: [PropertyService],
 })
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/hotelmanagement/src/app/dashboard/dashboard.ts` at line 10, Remove the
redundant component-level provider for PropertyService in the Dashboard
component so the component uses the singleton root-provided instance
(providedIn: 'root') instead of creating a local instance; specifically, delete
PropertyService from the Dashboard component's providers array (the providers:
[PropertyService] entry) so both Dashboard and the App use the same
PropertyService and share the hotels signal state.

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant