65 lines
2.1 KiB
TypeScript
65 lines
2.1 KiB
TypeScript
import { Observable } from "rxjs";
|
|
import { HttpClient } from "@angular/common/http";
|
|
import { inject, Injectable } from "@angular/core";
|
|
|
|
export interface Message {
|
|
id: number;
|
|
contenu: string;
|
|
date: string;
|
|
authorId: number;
|
|
authorName: string;
|
|
}
|
|
|
|
export interface MemberWithRole {
|
|
userId: number;
|
|
username: string;
|
|
roleId: number | null;
|
|
roleLibelle: string | null;
|
|
}
|
|
|
|
export interface Discussion {
|
|
id: number;
|
|
name: string;
|
|
isGroup: boolean;
|
|
membersCount?: number;
|
|
groupId?: number;
|
|
}
|
|
|
|
@Injectable({ providedIn: 'root' })
|
|
export class discussionsService {
|
|
|
|
private http = inject(HttpClient);
|
|
private apiUrl = 'http://localhost:5250/API';
|
|
|
|
getDiscussions(): Observable<Discussion[]> {
|
|
return this.http.get<Discussion[]>(`${this.apiUrl}/discussions/my`);
|
|
}
|
|
|
|
getMessages(discussionId: string): Observable<Message[]> {
|
|
return this.http.get<Message[]>(`${this.apiUrl}/discussions/${discussionId}/messages`);
|
|
}
|
|
|
|
createPrivateDiscussion(username: string): Observable<Discussion> {
|
|
return this.http.post<Discussion>(`${this.apiUrl}/discussions/private`, { username });
|
|
}
|
|
|
|
createGroupDiscussion(groupName: string, usernames: string[]): Observable<Discussion> {
|
|
return this.http.post<Discussion>(`${this.apiUrl}/discussions/group`, { groupName, usernames });
|
|
}
|
|
|
|
getDiscussionMembers(discussionId: string): Observable<string[]> {
|
|
return this.http.get<string[]>(`${this.apiUrl}/discussions/${discussionId}/members`);
|
|
}
|
|
|
|
getMembersWithRoles(discussionId: string): Observable<MemberWithRole[]> {
|
|
return this.http.get<MemberWithRole[]>(`${this.apiUrl}/discussions/${discussionId}/members/roles`);
|
|
}
|
|
|
|
createRole(libelle: string): Observable<{ id: number, libelle: string }> {
|
|
return this.http.post<{ id: number, libelle: string }>(`${this.apiUrl}/roles`, { libelle });
|
|
}
|
|
|
|
assignRole(groupId: number, userId: number, roleId: number): Observable<void> {
|
|
return this.http.post<void>(`${this.apiUrl}/groups/${groupId}/members/${userId}/role`, { roleId });
|
|
}
|
|
} |