frontend: Simplify API path construction by removing version from individual endpoints

This commit is contained in:
juancarmore 2025-04-14 11:41:31 +02:00
parent 0e580e6257
commit 446310f935

View File

@ -16,22 +16,22 @@ import { lastValueFrom } from 'rxjs';
providedIn: 'root'
})
export class HttpService {
protected API_PATH_PREFIX = 'meet/api';
protected INTERNAL_API_PATH_PREFIX = 'meet/internal-api';
protected API_V1_VERSION = 'v1';
protected API_PATH_PREFIX = `meet/api/${this.API_V1_VERSION}`;
protected INTERNAL_API_PATH_PREFIX = `meet/internal-api/${this.API_V1_VERSION}`;
constructor(protected http: HttpClient) {}
createRoom(options: MeetRoomOptions): Promise<MeetRoom> {
return this.postRequest(`${this.API_PATH_PREFIX}/${this.API_V1_VERSION}/rooms`, options);
return this.postRequest(`${this.API_PATH_PREFIX}/rooms`, options);
}
deleteRoom(roomId: string): Promise<any> {
return this.deleteRequest(`${this.API_PATH_PREFIX}/${this.API_V1_VERSION}/rooms/${roomId}`);
return this.deleteRequest(`${this.API_PATH_PREFIX}/rooms/${roomId}`);
}
listRooms(fields?: string): Promise<MeetRoom[]> {
let path = `${this.API_PATH_PREFIX}/${this.API_V1_VERSION}/rooms/`;
let path = `${this.API_PATH_PREFIX}/rooms/`;
if (fields) {
path += `?fields=${encodeURIComponent(fields)}`;
}
@ -39,28 +39,20 @@ export class HttpService {
}
getRoom(roomId: string): Promise<MeetRoom> {
let path = `${this.API_PATH_PREFIX}/${this.API_V1_VERSION}/rooms/${roomId}`;
let path = `${this.API_PATH_PREFIX}/rooms/${roomId}`;
return this.getRequest(path);
}
getRoomRoleAndPermissions(roomId: string, secret: string): Promise<MeetRoomRoleAndPermissions> {
return this.getRequest(
`${this.INTERNAL_API_PATH_PREFIX}/${this.API_V1_VERSION}/rooms/${roomId}/roles/${secret}`
);
return this.getRequest(`${this.INTERNAL_API_PATH_PREFIX}/rooms/${roomId}/roles/${secret}`);
}
generateParticipantToken(tokenOptions: TokenOptions): Promise<{ token: string }> {
return this.postRequest(
`${this.INTERNAL_API_PATH_PREFIX}/${this.API_V1_VERSION}/participants/token`,
tokenOptions
);
return this.postRequest(`${this.INTERNAL_API_PATH_PREFIX}/participants/token`, tokenOptions);
}
refreshParticipantToken(tokenOptions: TokenOptions): Promise<{ token: string }> {
return this.postRequest(
`${this.INTERNAL_API_PATH_PREFIX}/${this.API_V1_VERSION}/participants/token/refresh`,
tokenOptions
);
return this.postRequest(`${this.INTERNAL_API_PATH_PREFIX}/participants/token/refresh`, tokenOptions);
}
/**
@ -69,7 +61,7 @@ export class HttpService {
* @returns {Promise<GlobalPreferences>} A promise that resolves to the global preferences.
*/
getSecurityPreferences(): Promise<SecurityPreferencesDTO> {
return this.getRequest(`${this.INTERNAL_API_PATH_PREFIX}/${this.API_V1_VERSION}/preferences/security`);
return this.getRequest(`${this.INTERNAL_API_PATH_PREFIX}/preferences/security`);
}
/**
@ -79,7 +71,7 @@ export class HttpService {
* @returns {Promise<MeetRoomPreferences>} A promise that resolves to the room preferences.
*/
getRoomPreferences(): Promise<MeetRoomPreferences> {
return this.getRequest(`${this.API_PATH_PREFIX}/${this.API_V1_VERSION}/preferences/room`);
return this.getRequest(`${this.API_PATH_PREFIX}/preferences/room`);
}
/**
@ -89,27 +81,27 @@ export class HttpService {
* @returns A promise that resolves when the preferences have been successfully saved.
*/
updateRoomPreferences(roomId: string, preferences: MeetRoomPreferences): Promise<any> {
return this.putRequest(`${this.INTERNAL_API_PATH_PREFIX}/room/${roomId}`, preferences);
return this.putRequest(`${this.INTERNAL_API_PATH_PREFIX}/rooms/${roomId}`, preferences);
}
login(body: { username: string; password: string }): Promise<{ message: string }> {
return this.postRequest(`${this.INTERNAL_API_PATH_PREFIX}/${this.API_V1_VERSION}/auth/login`, body);
return this.postRequest(`${this.INTERNAL_API_PATH_PREFIX}/auth/login`, body);
}
logout(): Promise<{ message: string }> {
return this.postRequest(`${this.INTERNAL_API_PATH_PREFIX}/${this.API_V1_VERSION}/auth/logout`);
return this.postRequest(`${this.INTERNAL_API_PATH_PREFIX}/auth/logout`);
}
refreshToken(): Promise<{ message: string }> {
return this.postRequest(`${this.INTERNAL_API_PATH_PREFIX}/${this.API_V1_VERSION}/auth/refresh`);
return this.postRequest(`${this.INTERNAL_API_PATH_PREFIX}/auth/refresh`);
}
getProfile(): Promise<User> {
return this.getRequest(`${this.INTERNAL_API_PATH_PREFIX}/${this.API_V1_VERSION}/auth/profile`);
return this.getRequest(`${this.INTERNAL_API_PATH_PREFIX}/auth/profile`);
}
getRecordings(continuationToken?: string): Promise<{ recordings: RecordingInfo[]; continuationToken: string }> {
let path = `${this.API_PATH_PREFIX}/${this.API_V1_VERSION}/recordings`;
let path = `${this.API_PATH_PREFIX}/recordings`;
if (continuationToken) {
path += `?continuationToken=${continuationToken}`;
@ -119,17 +111,15 @@ export class HttpService {
}
startRecording(roomId: string): Promise<RecordingInfo> {
return this.postRequest(`${this.INTERNAL_API_PATH_PREFIX}/${this.API_V1_VERSION}/recordings`, { roomId });
return this.postRequest(`${this.INTERNAL_API_PATH_PREFIX}/recordings`, { roomId });
}
stopRecording(recordingId: string): Promise<RecordingInfo> {
return this.postRequest(
`${this.INTERNAL_API_PATH_PREFIX}/${this.API_V1_VERSION}/recordings/${recordingId}/stop`
);
return this.postRequest(`${this.INTERNAL_API_PATH_PREFIX}/recordings/${recordingId}/stop`);
}
deleteRecording(recordingId: string): Promise<RecordingInfo> {
return this.deleteRequest(`${this.API_PATH_PREFIX}/${this.API_V1_VERSION}/recordings/${recordingId}`);
return this.deleteRequest(`${this.API_PATH_PREFIX}/recordings/${recordingId}`);
}
protected getRequest<T>(path: string): Promise<T> {