Files
doneit-web/src/app/services/Repositorys/chat/data-source/room-remote-data-source.service.ts
T

57 lines
2.1 KiB
TypeScript
Raw Normal View History

2024-06-03 13:34:40 +01:00
import { Injectable } from '@angular/core';
import { ok, err, Result } from 'neverthrow';
import { HttpService } from 'src/app/services/http.service';
2024-06-04 09:31:37 +01:00
import { RoomListOutPutDTO } from '../dto/roomListOutputDTO';
import { RoomListInputDTO } from '../dto/roomInputDTO';
import { RoomOutPutDTO } from '../dto/roomOutputDTO';
2024-06-03 13:34:40 +01:00
@Injectable({
providedIn: 'root'
})
export class RoomRemoteDataSourceService {
2024-06-04 09:31:37 +01:00
private baseUrl = 'https://gdapi-dev.dyndns.info/stage/api/v2/Chat'; // Your base URL
2024-06-03 13:34:40 +01:00
constructor(private httpService: HttpService) {}
async sendMessage(message: any): Promise<Result<any ,any>> {
return await this.httpService.post<any>(`${this.baseUrl}/Messages`, message);
}
async reactToMessage(id: string, reaction: any): Promise<Result<any ,any>> {
return await this.httpService.post<any>(`${this.baseUrl}/Messages/${id}/React`, reaction);
}
2024-06-04 09:31:37 +01:00
async createRoom(data: RoomListInputDTO): Promise<Result<RoomOutPutDTO ,any>> {
return await this.httpService.post<any>(`${this.baseUrl}/Room`, data);
2024-06-03 13:34:40 +01:00
}
async getRoomList(): Promise<Result<RoomListOutPutDTO ,any>> {
return await this.httpService.get<any>(`${this.baseUrl}/Room`);
}
async getRoom(id: string): Promise<Result<any ,any>> {
return await this.httpService.get<any>(`${this.baseUrl}/Room/${id}`);
}
async updateRoom(id: string, room: any): Promise<Result<any ,any>> {
return await this.httpService.put<any>(`${this.baseUrl}/Room/${id}`, room);
}
async deleteRoom(id: string): Promise<Result<any ,any>> {
return await this.httpService.delete<any>(`${this.baseUrl}/Room/${id}`);
}
async addMemberToRoom(id: string, member: any): Promise<Result<any ,any>> {
return await this.httpService.post<any>(`${this.baseUrl}/Room/${id}/Member`, member);
}
async removeMemberFromRoom(id: string, member: any): Promise<Result<any ,any>> {
return await this.httpService.delete<any>(`${this.baseUrl}/Room/${id}/Member`);
}
async getMessagesFromRoom(id: string): Promise<Result<any ,any>> {
return await this.httpService.get<any>(`${this.baseUrl}/Room/${id}/Messages`);
}
}