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

34 lines
1.4 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';
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';
import { MessageOutPutDTO, MessageOutPutDTOSchema } from '../../dto/message/messageOutputDTO';
2024-06-05 15:35:38 +01:00
import { MessageListOutput } from '../../dto/message/messageListOutputDTO';
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-06-11 11:46:04 +01:00
@APIReturn(MessageOutPutDTOSchema, 'get/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-06-05 15:35:38 +01:00
async getMessagesFromRoom(id: string): DataSourceReturn<MessageListOutput> {
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
}