Files
gameovergne-app/client/src/app/services/platform.service.ts

33 lines
1.1 KiB
TypeScript

import {inject, Injectable} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {Observable} from 'rxjs';
import {Platform} from '../interfaces/platform';
import {CrudService} from './crud.service';
@Injectable({
providedIn: 'root'
})
export class PlatformService implements CrudService<Platform> {
private readonly http = inject(HttpClient);
private readonly BASE_URL = 'http://localhost:3000/api/app/platforms';
getAll(): Observable<Platform[]> {
return this.http.get<Platform[]>(this.BASE_URL, {withCredentials: true});
}
add(item: Platform): Observable<Platform> {
console.log('Adding platform:', item);
return this.http.post<Platform>(this.BASE_URL, item, {withCredentials: true});
}
update(id: string | number, item: Platform): Observable<Platform> {
console.log('Updating platform:', id, item);
return this.http.put<Platform>(`${this.BASE_URL}/${id}`, item, {withCredentials: true});
}
delete(id: string | number): Observable<void> {
console.log('Deleting platform:', id);
return this.http.delete<void>(`${this.BASE_URL}/${id}`, {withCredentials: true});
}
}