diff --git a/apps/angular/projection/src/app/component/city-card/city-card.component.ts b/apps/angular/projection/src/app/component/city-card/city-card.component.ts index 30c8f88ec..714040f85 100644 --- a/apps/angular/projection/src/app/component/city-card/city-card.component.ts +++ b/apps/angular/projection/src/app/component/city-card/city-card.component.ts @@ -1,13 +1,35 @@ import { Component, OnInit } from '@angular/core'; +import { CityStore } from '../../data-access/city.store'; +import { FakeHttpService } from '../../data-access/fake-http.service'; +import { CardType } from '../../model/card.model'; +import { City } from '../../model/city.model'; +import { CardComponent } from '../../ui/card/card.component'; @Component({ selector: 'app-city-card', - template: 'TODO City', + template: ` + + `, standalone: true, - imports: [], + imports: [CardComponent], }) export class CityCardComponent implements OnInit { - constructor() {} + cities: City[] = []; + image = 'city.png'; + cardType = CardType.CITY; - ngOnInit(): void {} + constructor( + private http: FakeHttpService, + private store: CityStore, + ) {} + + ngOnInit(): void { + this.http.fetchCities$.subscribe((s) => this.store.addAll(s)); + + this.store.cities$.subscribe((s) => (this.cities = s)); + } } diff --git a/apps/angular/projection/src/app/component/student-card/student-card.component.ts b/apps/angular/projection/src/app/component/student-card/student-card.component.ts index 441cda189..5b97d8ad6 100644 --- a/apps/angular/projection/src/app/component/student-card/student-card.component.ts +++ b/apps/angular/projection/src/app/component/student-card/student-card.component.ts @@ -11,6 +11,7 @@ import { CardComponent } from '../../ui/card/card.component'; `, standalone: true, @@ -26,6 +27,7 @@ import { CardComponent } from '../../ui/card/card.component'; export class StudentCardComponent implements OnInit { students: Student[] = []; cardType = CardType.STUDENT; + image = 'student.webp'; constructor( private http: FakeHttpService, diff --git a/apps/angular/projection/src/app/component/teacher-card/teacher-card.component.ts b/apps/angular/projection/src/app/component/teacher-card/teacher-card.component.ts index 995cb7c2f..bc5699866 100644 --- a/apps/angular/projection/src/app/component/teacher-card/teacher-card.component.ts +++ b/apps/angular/projection/src/app/component/teacher-card/teacher-card.component.ts @@ -11,6 +11,7 @@ import { CardComponent } from '../../ui/card/card.component'; `, styles: [ @@ -26,6 +27,7 @@ import { CardComponent } from '../../ui/card/card.component'; export class TeacherCardComponent implements OnInit { teachers: Teacher[] = []; cardType = CardType.TEACHER; + image = 'teacher.png'; constructor( private http: FakeHttpService, diff --git a/apps/angular/projection/src/app/model/card.model.ts b/apps/angular/projection/src/app/model/card.model.ts index 740cd2ae4..0a1533782 100644 --- a/apps/angular/projection/src/app/model/card.model.ts +++ b/apps/angular/projection/src/app/model/card.model.ts @@ -3,3 +3,11 @@ export enum CardType { STUDENT, CITY, } + +export interface CardModel { + name: string; + firstName: string; + lastName: string; + subject: string; + id: number; +} diff --git a/apps/angular/projection/src/app/services/card.service.ts b/apps/angular/projection/src/app/services/card.service.ts new file mode 100644 index 000000000..0f7b6aad2 --- /dev/null +++ b/apps/angular/projection/src/app/services/card.service.ts @@ -0,0 +1,31 @@ +import { Injectable } from '@angular/core'; +import { CityStore } from '../data-access/city.store'; +import { + randomCity, + randStudent, + randTeacher, +} from '../data-access/fake-http.service'; +import { StudentStore } from '../data-access/student.store'; +import { TeacherStore } from '../data-access/teacher.store'; +import { CardType } from '../model/card.model'; + +@Injectable({ + providedIn: 'root', +}) +export class CardService { + constructor( + private teacherStore: TeacherStore, + private studentStore: StudentStore, + private cityStore: CityStore, + ) {} + + addOne(type: CardType) { + if (type === CardType.TEACHER) { + this.teacherStore.addOne(randTeacher()); + } else if (type === CardType.STUDENT) { + this.studentStore.addOne(randStudent()); + } else if (type === CardType.CITY) { + this.cityStore.addOne(randomCity()); + } + } +} diff --git a/apps/angular/projection/src/app/ui/card/card.component.ts b/apps/angular/projection/src/app/ui/card/card.component.ts index f06c9ae00..a68f64a2f 100644 --- a/apps/angular/projection/src/app/ui/card/card.component.ts +++ b/apps/angular/projection/src/app/ui/card/card.component.ts @@ -1,9 +1,7 @@ -import { NgFor, NgIf } from '@angular/common'; +import { CommonModule } from '@angular/common'; import { Component, Input } from '@angular/core'; -import { randStudent, randTeacher } from '../../data-access/fake-http.service'; -import { StudentStore } from '../../data-access/student.store'; -import { TeacherStore } from '../../data-access/teacher.store'; import { CardType } from '../../model/card.model'; +import { CardService } from '../../services/card.service'; import { ListItemComponent } from '../list-item/list-item.component'; @Component({ @@ -12,50 +10,39 @@ import { ListItemComponent } from '../list-item/list-item.component';
- - + + -
- -
+
+ +
- + +
+ +
`, standalone: true, - imports: [NgIf, NgFor, ListItemComponent], + imports: [CommonModule, ListItemComponent], }) export class CardComponent { - @Input() list: any[] | null = null; + @Input() list!: any[]; @Input() type!: CardType; @Input() customClass = ''; + @Input() image: string = ''; - CardType = CardType; - - constructor( - private teacherStore: TeacherStore, - private studentStore: StudentStore, - ) {} + constructor(private cardService: CardService) {} addNewItem() { - if (this.type === CardType.TEACHER) { - this.teacherStore.addOne(randTeacher()); - } else if (this.type === CardType.STUDENT) { - this.studentStore.addOne(randStudent()); - } + this.cardService.addOne(this.type); } } diff --git a/apps/angular/projection/src/app/ui/list-item/list-item.component.ts b/apps/angular/projection/src/app/ui/list-item/list-item.component.ts index c0f9cff7f..e6a77dfcb 100644 --- a/apps/angular/projection/src/app/ui/list-item/list-item.component.ts +++ b/apps/angular/projection/src/app/ui/list-item/list-item.component.ts @@ -1,4 +1,5 @@ import { Component, Input } from '@angular/core'; +import { CityStore } from '../../data-access/city.store'; import { StudentStore } from '../../data-access/student.store'; import { TeacherStore } from '../../data-access/teacher.store'; import { CardType } from '../../model/card.model'; @@ -23,6 +24,7 @@ export class ListItemComponent { constructor( private teacherStore: TeacherStore, private studentStore: StudentStore, + private cityStore: CityStore, ) {} delete(id: number) { @@ -30,6 +32,8 @@ export class ListItemComponent { this.teacherStore.deleteOne(id); } else if (this.type === CardType.STUDENT) { this.studentStore.deleteOne(id); + } else if (this.type === CardType.CITY) { + this.cityStore.deleteOne(id); } } }