From 5136b3b5225409daf537e020c393dec654c900d4 Mon Sep 17 00:00:00 2001 From: Aniol0012 Date: Thu, 12 Dec 2024 16:57:41 +0100 Subject: [PATCH 1/4] feat: add room list component --- .../room/room-list/room-list.component.css | 0 .../room/room-list/room-list.component.html | 0 .../room-list/room-list.component.spec.ts | 23 +++++++++++++++++++ src/app/room/room-list/room-list.component.ts | 12 ++++++++++ 4 files changed, 35 insertions(+) create mode 100644 src/app/room/room-list/room-list.component.css create mode 100644 src/app/room/room-list/room-list.component.html create mode 100644 src/app/room/room-list/room-list.component.spec.ts create mode 100644 src/app/room/room-list/room-list.component.ts diff --git a/src/app/room/room-list/room-list.component.css b/src/app/room/room-list/room-list.component.css new file mode 100644 index 0000000..e69de29 diff --git a/src/app/room/room-list/room-list.component.html b/src/app/room/room-list/room-list.component.html new file mode 100644 index 0000000..e69de29 diff --git a/src/app/room/room-list/room-list.component.spec.ts b/src/app/room/room-list/room-list.component.spec.ts new file mode 100644 index 0000000..d0cd221 --- /dev/null +++ b/src/app/room/room-list/room-list.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { RoomListComponent } from './room-list.component'; + +describe('RoomListComponent', () => { + let component: RoomListComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [RoomListComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(RoomListComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/room/room-list/room-list.component.ts b/src/app/room/room-list/room-list.component.ts new file mode 100644 index 0000000..6c848b3 --- /dev/null +++ b/src/app/room/room-list/room-list.component.ts @@ -0,0 +1,12 @@ +import { Component } from '@angular/core'; + +@Component({ + selector: 'app-room-list', + standalone: true, + imports: [], + templateUrl: './room-list.component.html', + styleUrl: './room-list.component.css' +}) +export class RoomListComponent { + +} From 61f3c90914cd659c401e533257e1e639e02ac250 Mon Sep 17 00:00:00 2001 From: Aniol0012 Date: Thu, 12 Dec 2024 17:24:28 +0100 Subject: [PATCH 2/4] feat: add room service --- src/app/room/room.service.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/app/room/room.service.ts diff --git a/src/app/room/room.service.ts b/src/app/room/room.service.ts new file mode 100644 index 0000000..5ada992 --- /dev/null +++ b/src/app/room/room.service.ts @@ -0,0 +1,26 @@ +import { Injectable } from "@angular/core"; +import { Observable } from "rxjs"; +import { HateoasResourceOperation, ResourceCollection } from "@lagoshny/ngx-hateoas-client"; +import { Room } from "./room"; +import { Apartment } from "./../apartment/apartment"; +import { User } from "../login-basic/user"; + +@Injectable({ providedIn: "root" }) +export class RoomService extends HateoasResourceOperation { + + constructor() { + super(Room); + } + + public findById(roomId: string): Observable { + return this.getResource(roomId); + } + + public findByApartment(apartment: Apartment): Observable> { + return this.searchCollection("findByApart", { params: { apartment: apartment } }); + } + + public findByOwner(owner: User): Observable> { + return this.searchCollection("findByOwner", { params: { owner: owner } }); + } +} From 909419ddbcbf6038407a64c512f768577167bc2f Mon Sep 17 00:00:00 2001 From: Aniol0012 Date: Thu, 12 Dec 2024 17:25:35 +0100 Subject: [PATCH 3/4] feat: add room list component logic --- src/app/app-routing.module.ts | 13 ++++---- .../room/room-list/room-list.component.html | 16 ++++++++++ src/app/room/room-list/room-list.component.ts | 32 ++++++++++++++++--- 3 files changed, 51 insertions(+), 10 deletions(-) diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index dd5f235..92c1ed8 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -8,12 +8,12 @@ import { UserDetailComponent } from './user/user-detail/user-detail.component'; import { UserRegisterComponent } from './user/user-register/user-register.component'; import { UserEditComponent } from './user/user-edit/user-edit.component'; import { UserDeleteComponent } from './user/user-delete/user-delete.component'; -import {ApartmentListComponent} from './apartment/apartment-list/apartment-list.component'; -import {ApartmentCreateComponent} from './apartment/apartment-create/apartment-create.component'; -import {ApartmentUpdateComponent} from './apartment/apartment-update/apartment-update.component'; -import {ApartmentDeleteComponent} from './apartment/apartment-delete/apartment-delete.component'; -import {VisitStatusComponent} from './visit/visit-status/visit-status.component'; - +import { ApartmentListComponent } from './apartment/apartment-list/apartment-list.component'; +import { ApartmentCreateComponent } from './apartment/apartment-create/apartment-create.component'; +import { ApartmentUpdateComponent } from './apartment/apartment-update/apartment-update.component'; +import { ApartmentDeleteComponent } from './apartment/apartment-delete/apartment-delete.component'; +import { VisitStatusComponent } from './visit/visit-status/visit-status.component'; +import { RoomListComponent } from './room/room-list/room-list.component'; const routes: Routes = [ { path: 'users/create', component: UserRegisterComponent}, @@ -27,6 +27,7 @@ const routes: Routes = [ { path: 'apartment/:id/update', component: ApartmentUpdateComponent}, { path: 'apartment/:id/delete', component: ApartmentDeleteComponent}, { path: 'visit/:id/status', component: VisitStatusComponent}, + { path: 'rooms', component: RoomListComponent}, { path: '404', component: NotFoundComponent}, { path: '', redirectTo: 'about', pathMatch: 'full'}, ]; diff --git a/src/app/room/room-list/room-list.component.html b/src/app/room/room-list/room-list.component.html index e69de29..0893abb 100644 --- a/src/app/room/room-list/room-list.component.html +++ b/src/app/room/room-list/room-list.component.html @@ -0,0 +1,16 @@ +
+

List of Rooms

+ +
+
+
Room {{ i + 1 }}
+

Surface: {{ room.surface }} m²

+ Occupied + Available +
+
+ + +
diff --git a/src/app/room/room-list/room-list.component.ts b/src/app/room/room-list/room-list.component.ts index 6c848b3..02e4370 100644 --- a/src/app/room/room-list/room-list.component.ts +++ b/src/app/room/room-list/room-list.component.ts @@ -1,12 +1,36 @@ -import { Component } from '@angular/core'; +import { Component, Input, OnInit } from '@angular/core'; +import { RoomService } from '../room.service'; +import { Room } from '../room'; +import { Apartment } from '../../apartment/apartment'; +import { CommonModule } from '@angular/common'; @Component({ selector: 'app-room-list', standalone: true, - imports: [], + imports: [CommonModule], templateUrl: './room-list.component.html', - styleUrl: './room-list.component.css' + styleUrls: ['./room-list.component.css'] }) -export class RoomListComponent { +export class RoomListComponent implements OnInit { + @Input() apartment!: Apartment; + // Max number of rooms to show, set to -1 to show all + @Input() maxRooms: number = 10; + rooms: Room[] = []; + constructor(private roomService: RoomService) {} + + ngOnInit(): void { + if (this.apartment) { + this.roomService.findByApartment(this.apartment).subscribe({ + next: (collection) => { + if (this.maxRooms === -1) { + this.rooms = collection.resources; + } else { + this.rooms = collection.resources.slice(0, this.maxRooms); + } + }, + error: (err) => console.error('Error fetching rooms:', err), + }); + } + } } From 0850acdb0279ea4dfa12df247b0cd33325f7402c Mon Sep 17 00:00:00 2001 From: Aniol0012 Date: Thu, 12 Dec 2024 17:25:54 +0100 Subject: [PATCH 4/4] feat: add room list on apartment creation --- .../apartment/apartment-create/apartment-create.component.html | 1 + .../apartment/apartment-create/apartment-create.component.ts | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/app/apartment/apartment-create/apartment-create.component.html b/src/app/apartment/apartment-create/apartment-create.component.html index 0f0dfe1..bcb0587 100644 --- a/src/app/apartment/apartment-create/apartment-create.component.html +++ b/src/app/apartment/apartment-create/apartment-create.component.html @@ -44,6 +44,7 @@

Create Apartment

+ diff --git a/src/app/apartment/apartment-create/apartment-create.component.ts b/src/app/apartment/apartment-create/apartment-create.component.ts index b8be4e4..3e60772 100644 --- a/src/app/apartment/apartment-create/apartment-create.component.ts +++ b/src/app/apartment/apartment-create/apartment-create.component.ts @@ -8,11 +8,12 @@ import { ErrorMessageService } from '../../error-handler/error-message.service'; import { CommonModule } from '@angular/common'; import { ApartmentService } from '../apartment.service'; import { ApartmentDetails } from '../apartment-details'; +import { RoomListComponent } from '../../room/room-list/room-list.component'; @Component({ selector: 'app-apartment-create', standalone: true, - imports: [FormsModule, CommonModule], + imports: [FormsModule, CommonModule, RoomListComponent], templateUrl: './apartment-create.component.html', styleUrls: ['./apartment-create.component.css'] })