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

31 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-06-04 13:12:38 +01:00
import { Injectable } from '@angular/core';
import { HttpService } from 'src/app/services/http.service';
import { MessageListInputDTO } from '../../dto/message/messageListInputDTO';
2024-06-04 16:21:11 +01:00
import { DataSourceReturn } from '../../../type';
2024-06-05 10:28:38 +01:00
import { MessageInputDTO, MessageInputDTOSchema } from '../../dto/message/messageInputDtO';
import { ValidateSchema } from 'src/app/services/decorators/validate-schema.decorator';
import { MessageOutPutDTO } from '../../dto/message/messageOutputDTO';
2024-06-04 13:12:38 +01:00
@Injectable({
providedIn: 'root'
})
export class MessageRemoteDataSourceService {
private baseUrl = 'https://gdapi-dev.dyndns.info/stage/api/v2/Chat'; // Your base URL
constructor(private httpService: HttpService) {}
2024-06-05 10:28:38 +01:00
@ValidateSchema(MessageInputDTOSchema)
async sendMessage(data: MessageInputDTO) {
return await this.httpService.post<MessageOutPutDTO>(`${this.baseUrl}/Messages`, data);
2024-06-04 13:12:38 +01:00
}
async reactToMessage(id: string, reaction: any) {
return await this.httpService.post<any>(`${this.baseUrl}/Messages/${id}/React`, reaction);
}
2024-06-04 16:21:11 +01:00
async getMessagesFromRoom(id: MessageListInputDTO): DataSourceReturn<MessageListInputDTO> {
return await this.httpService.get(`${this.baseUrl}/Room/${id}/Messages`);
2024-06-04 13:12:38 +01:00
}
}