fix: Merge branch 'feat/NCS-69' of git.janis-eccarius.de:NowChess/NowChess-Frontend into feat/NCS-69
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { Challenge, DeclineChallengeRequest, ListChallengesResponse, SendChallengeRequest } from '../models/challenge.models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class ChallengeService {
|
||||
private readonly http = inject(HttpClient);
|
||||
private readonly challengeBaseUrl = '/api/challenge';
|
||||
|
||||
sendChallenge(username: string, request: SendChallengeRequest): Observable<Challenge> {
|
||||
return this.http.post<Challenge>(
|
||||
`${this.challengeBaseUrl}/${username}`,
|
||||
request
|
||||
);
|
||||
}
|
||||
|
||||
listChallenges(): Observable<ListChallengesResponse> {
|
||||
return this.http.get<ListChallengesResponse>(
|
||||
`${this.challengeBaseUrl}`
|
||||
);
|
||||
}
|
||||
|
||||
getChallenge(challengeId: string): Observable<Challenge> {
|
||||
return this.http.get<Challenge>(
|
||||
`${this.challengeBaseUrl}/${challengeId}`
|
||||
);
|
||||
}
|
||||
|
||||
acceptChallenge(challengeId: string): Observable<Challenge> {
|
||||
return this.http.post<Challenge>(
|
||||
`${this.challengeBaseUrl}/${challengeId}/accept`,
|
||||
{}
|
||||
);
|
||||
}
|
||||
|
||||
declineChallenge(challengeId: string, request?: DeclineChallengeRequest): Observable<void> {
|
||||
return this.http.post<void>(
|
||||
`${this.challengeBaseUrl}/${challengeId}/decline`,
|
||||
request || {}
|
||||
);
|
||||
}
|
||||
|
||||
cancelChallenge(challengeId: string): Observable<void> {
|
||||
return this.http.post<void>(
|
||||
`${this.challengeBaseUrl}/${challengeId}/cancel`,
|
||||
{}
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user