2024-06-04 13:12:38 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
import { HttpService } from 'src/app/services/http.service';
|
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';
|
2024-06-10 16:34:43 +01:00
|
|
|
import { APIReturn } from 'src/app/services/decorators/api-validate-schema.decorator';
|
2024-08-08 11:44:41 +01:00
|
|
|
import { MessageOutPutDataDTOSchema, MessageOutPutDTO, MessageOutPutDTOSchema } from '../../dto/message/messageOutputDTO';
|
2024-07-11 10:28:21 +01:00
|
|
|
import { DataSourceReturn } from 'src/app/services/Repositorys/type';
|
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-08-08 11:44:41 +01:00
|
|
|
@APIReturn(MessageOutPutDTOSchema, 'post/Messages')
|
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-08-08 11:44:41 +01:00
|
|
|
@APIReturn(MessageOutPutDTOSchema, 'get/Messages')
|
2024-08-08 09:58:44 +01:00
|
|
|
async getMessagesFromRoom(id: string): DataSourceReturn<MessageOutPutDTO> {
|
2024-06-04 16:21:11 +01:00
|
|
|
return await this.httpService.get(`${this.baseUrl}/Room/${id}/Messages`);
|
2024-06-04 13:12:38 +01:00
|
|
|
}
|
2024-06-05 14:31:26 +01:00
|
|
|
|
2024-06-04 13:12:38 +01:00
|
|
|
}
|