http service tests
This commit is contained in:
@@ -5,6 +5,10 @@ import { AppRoutingModule } from './app-routing-module';
|
|||||||
import { App } from './app';
|
import { App } from './app';
|
||||||
import { PocModelComponent } from './poc-model-component/poc-model-component';
|
import { PocModelComponent } from './poc-model-component/poc-model-component';
|
||||||
import { HomeComponent } from './home-component/home-component';
|
import { HomeComponent } from './home-component/home-component';
|
||||||
|
import { provideHttpClient, withFetch } from '@angular/common/http';
|
||||||
|
import { CommonModule } from '@angular/common';
|
||||||
|
import { FormsModule } from '@angular/forms';
|
||||||
|
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
declarations: [
|
declarations: [
|
||||||
@@ -13,11 +17,16 @@ import { HomeComponent } from './home-component/home-component';
|
|||||||
HomeComponent
|
HomeComponent
|
||||||
],
|
],
|
||||||
imports: [
|
imports: [
|
||||||
|
AppRoutingModule,
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
AppRoutingModule
|
CommonModule,
|
||||||
|
FormsModule
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
provideBrowserGlobalErrorListeners()
|
provideBrowserGlobalErrorListeners(),
|
||||||
|
provideHttpClient(
|
||||||
|
withFetch(),
|
||||||
|
)
|
||||||
],
|
],
|
||||||
bootstrap: [App]
|
bootstrap: [App]
|
||||||
})
|
})
|
||||||
|
|||||||
17
src/app/http.service.ts
Normal file
17
src/app/http.service.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { Kinosaal } from '@infinimotion/model-frontend';
|
||||||
|
import { HttpClient } from "@angular/common/http";
|
||||||
|
import { inject, Injectable } from "@angular/core";
|
||||||
|
import { Observable } from "rxjs";
|
||||||
|
|
||||||
|
@Injectable({providedIn: 'root'})
|
||||||
|
export class HttpService {
|
||||||
|
private http = inject(HttpClient);
|
||||||
|
|
||||||
|
getAllKinosaal(): Observable<Kinosaal> {
|
||||||
|
return this.http.get<Kinosaal>(`https://infinimotion.de/api/kinosaal`);
|
||||||
|
}
|
||||||
|
|
||||||
|
addKinosaal(kinosaal: Omit<Kinosaal, 'id'>): Observable<Kinosaal> {
|
||||||
|
return this.http.post<Kinosaal>(`https://infinimotion.de/api/kinosaal`, kinosaal);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,24 @@
|
|||||||
<p>Diese Komponente später löschen, nur ein Proof Of Concept für die Modellverwendung!</p>
|
<div>
|
||||||
<p>{{ ticket.id }}</p>
|
<h2>Kinosaal Übersicht</h2>
|
||||||
<p>{{ ticket.code }}</p>
|
|
||||||
|
<ul>
|
||||||
|
@for (kinosaal of kinosaele; track kinosaal.id) {
|
||||||
|
<li>
|
||||||
|
{{ kinosaal.id }} - {{ kinosaal.name }}
|
||||||
|
</li>
|
||||||
|
} @empty {
|
||||||
|
<li>
|
||||||
|
Keine Kinosäle vorhanden.
|
||||||
|
</li>
|
||||||
|
}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder="Neuer Kinosaal Name"
|
||||||
|
[(ngModel)]="newKinosaalName"
|
||||||
|
/>
|
||||||
|
<button (click)="addKinosaal()">Hinzufügen</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { Component } from '@angular/core';
|
import { Component, inject, OnInit } from '@angular/core';
|
||||||
import { Eintrittskarte, Kinosaal, Vorstellung } from '@infinimotion/model-frontend';
|
import { Kinosaal } from '@infinimotion/model-frontend';
|
||||||
|
import { HttpService } from '../http.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-poc-model-component',
|
selector: 'app-poc-model-component',
|
||||||
@@ -7,12 +8,34 @@ import { Eintrittskarte, Kinosaal, Vorstellung } from '@infinimotion/model-front
|
|||||||
templateUrl: './poc-model-component.html',
|
templateUrl: './poc-model-component.html',
|
||||||
styleUrl: './poc-model-component.css',
|
styleUrl: './poc-model-component.css',
|
||||||
})
|
})
|
||||||
export class PocModelComponent {
|
|
||||||
ticket: Eintrittskarte = {
|
export class PocModelComponent implements OnInit {
|
||||||
id: 12345,
|
private http = inject(HttpService);
|
||||||
code: 'ABCDEF',
|
|
||||||
show: undefined as any,
|
kinosaele: Kinosaal[] = [];
|
||||||
seat: undefined as any,
|
newKinosaalName = '';
|
||||||
state: undefined as any,
|
|
||||||
};
|
ngOnInit(): void {
|
||||||
|
this.loadKinosaele();
|
||||||
|
}
|
||||||
|
|
||||||
|
loadKinosaele() {
|
||||||
|
this.http.getAllKinosaal().subscribe({
|
||||||
|
next: (data) => (this.kinosaele = Array.isArray(data) ? data : [data]),
|
||||||
|
error: (err) => console.error('Fehler beim Laden der Kinosaele', err),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
addKinosaal() {
|
||||||
|
if (!this.newKinosaalName.trim()) return;
|
||||||
|
|
||||||
|
const kinosaalToAdd: Omit<Kinosaal, 'id'> = { name: this.newKinosaalName };
|
||||||
|
this.http.addKinosaal(kinosaalToAdd).subscribe({
|
||||||
|
next: (added) => {
|
||||||
|
this.kinosaele.push(added);
|
||||||
|
this.newKinosaalName = '';
|
||||||
|
},
|
||||||
|
error: (err) => console.error('Fehler beim Hinzufügen', err),
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user