feat(lootboxes): add lootbox opening feature and images

This commit is contained in:
Jan-Marlon Leibl 2025-04-23 13:17:44 +02:00
commit 8e27c9c7c3
Signed by: jleibl
GPG key ID: 300B2F906DC6F1D5
15 changed files with 536 additions and 327 deletions

View file

@ -0,0 +1,33 @@
import { Injectable, inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, catchError } from 'rxjs';
import { LootBox, Reward } from 'app/model/LootBox';
@Injectable({
providedIn: 'root',
})
export class LootboxService {
private http = inject(HttpClient);
getAllLootBoxes(): Observable<LootBox[]> {
return this.http
.get<LootBox[]>('/backend/lootboxes', { responseType: 'json' })
.pipe(
catchError((error) => {
console.error('Get lootboxes error:', error);
throw error;
})
);
}
purchaseLootBox(lootBoxId: number): Observable<Reward> {
return this.http
.post<Reward>(`/backend/lootboxes/${lootBoxId}`, {}, { responseType: 'json' })
.pipe(
catchError((error) => {
console.error('Purchase lootbox error:', error);
throw error;
})
);
}
}