All checks were successful
CI / Backend tests (push) Successful in 30s
CI / Frontend lint (push) Successful in 33s
CI / Frontend build (push) Successful in 25s
CI / Frontend unit tests (push) Successful in 1m6s
CI / Playwright e2e (push) Successful in 1m43s
Docker / build-and-push (push) Successful in 2m30s
35 lines
1 KiB
TypeScript
35 lines
1 KiB
TypeScript
import { Injectable, inject } from '@angular/core';
|
|
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
|
import { firstValueFrom } from 'rxjs';
|
|
import { TreeDto } from '../models';
|
|
|
|
@Injectable({ providedIn: 'root' })
|
|
export class ApiService {
|
|
private readonly http = inject(HttpClient);
|
|
|
|
health(): Promise<{ status: string }> {
|
|
return firstValueFrom(this.http.get<{ status: string }>('api/v1/health'));
|
|
}
|
|
|
|
register(token: string): Promise<{ user_id: string }> {
|
|
return firstValueFrom(
|
|
this.http.post<{ user_id: string }>('api/v1/register', { token }),
|
|
);
|
|
}
|
|
|
|
getData(token: string): Promise<TreeDto> {
|
|
return firstValueFrom(
|
|
this.http.get<TreeDto>('api/v1/data', { headers: this.authHeaders(token) }),
|
|
);
|
|
}
|
|
|
|
async putData(token: string, tree: TreeDto): Promise<void> {
|
|
await firstValueFrom(
|
|
this.http.put('api/v1/data', tree, { headers: this.authHeaders(token) }),
|
|
);
|
|
}
|
|
|
|
private authHeaders(token: string): HttpHeaders {
|
|
return new HttpHeaders({ Authorization: `Bearer ${token}` });
|
|
}
|
|
}
|