From 446310f9355348746fa1961873ba2ba62af3d1e8 Mon Sep 17 00:00:00 2001 From: juancarmore Date: Mon, 14 Apr 2025 11:41:31 +0200 Subject: [PATCH] frontend: Simplify API path construction by removing version from individual endpoints --- .../src/lib/services/http/http.service.ts | 50 ++++++++----------- 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/frontend/projects/shared-meet-components/src/lib/services/http/http.service.ts b/frontend/projects/shared-meet-components/src/lib/services/http/http.service.ts index e312826..7a44050 100644 --- a/frontend/projects/shared-meet-components/src/lib/services/http/http.service.ts +++ b/frontend/projects/shared-meet-components/src/lib/services/http/http.service.ts @@ -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 { - 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 { - 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 { - 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 { - 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 { - 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} A promise that resolves to the global preferences. */ getSecurityPreferences(): Promise { - 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} A promise that resolves to the room preferences. */ getRoomPreferences(): Promise { - 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 { - 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 { - 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 { - 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 { - 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 { - return this.deleteRequest(`${this.API_PATH_PREFIX}/${this.API_V1_VERSION}/recordings/${recordingId}`); + return this.deleteRequest(`${this.API_PATH_PREFIX}/recordings/${recordingId}`); } protected getRequest(path: string): Promise {