2024-06-03 13:34:40 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
2024-06-04 16:21:11 +01:00
|
|
|
import { Result } from 'neverthrow';
|
2024-06-03 13:34:40 +01:00
|
|
|
import { HttpService } from 'src/app/services/http.service';
|
2024-06-04 16:21:11 +01:00
|
|
|
import { RoomListOutPutDTO } from '../../dto/room/roomListOutputDTO';
|
|
|
|
|
import { RoomInputDTO, RoomInputDTOSchema } from '../../dto/room/roomInputDTO';
|
|
|
|
|
import { RoomOutPutDTO } from '../../dto/room/roomOutputDTO';
|
|
|
|
|
import { AddMemberToRoomInputDTO, AddMemberToRoomInputDTOSchema } from '../../dto/room/addMemberToRoomInputDto';
|
|
|
|
|
import { ValidateSchema } from 'src/app/services/decorators/validate-schema.decorator';
|
|
|
|
|
import { DataSourceReturn } from '../../../type';
|
2024-06-07 12:29:53 +01:00
|
|
|
import { RoomByIdInputDTO, RoomByIdInputDTOSchema } from '../../dto/room/roomByIdInputDTO';
|
|
|
|
|
import { RoomByIdOutputDTO, RoomByIdOutputDTOSchema } from '../../dto/room/roomByIdOutputDTO';
|
|
|
|
|
import { APIReturn } from 'src/app/services/decorators/api-validate-schema.decorator';
|
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) {}
|
|
|
|
|
|
|
|
|
|
|
2024-06-04 16:21:11 +01:00
|
|
|
@ValidateSchema(RoomInputDTOSchema)
|
|
|
|
|
async createRoom(data: RoomInputDTO): DataSourceReturn<RoomOutPutDTO> {
|
|
|
|
|
return await this.httpService.post<RoomOutPutDTO>(`${this.baseUrl}/Room`, data);
|
2024-06-03 13:34:40 +01:00
|
|
|
}
|
|
|
|
|
|
2024-06-05 11:09:03 +01:00
|
|
|
async getRoomList(): Promise<DataSourceReturn<RoomListOutPutDTO>> {
|
|
|
|
|
return await this.httpService.get<RoomListOutPutDTO>(`${this.baseUrl}/Room`);
|
2024-06-03 13:34:40 +01:00
|
|
|
}
|
|
|
|
|
|
2024-06-07 12:29:53 +01:00
|
|
|
@ValidateSchema(RoomByIdInputDTOSchema)
|
|
|
|
|
@APIReturn(RoomByIdOutputDTOSchema)
|
|
|
|
|
async getRoom(id: RoomByIdInputDTO): DataSourceReturn<RoomByIdOutputDTO> {
|
|
|
|
|
return await this.httpService.get(`${this.baseUrl}/Room/${id}`);
|
2024-06-03 13:34:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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}`);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-04 16:21:11 +01:00
|
|
|
@ValidateSchema(AddMemberToRoomInputDTOSchema)
|
|
|
|
|
async addMemberToRoom(data: AddMemberToRoomInputDTO): DataSourceReturn<AddMemberToRoomInputDTO> {
|
2024-06-04 09:58:04 +01:00
|
|
|
return await this.httpService.post<any>(`${this.baseUrl}/Room/${data.id}/Member`, data.member);
|
2024-06-03 13:34:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async removeMemberFromRoom(id: string, member: any): Promise<Result<any ,any>> {
|
|
|
|
|
return await this.httpService.delete<any>(`${this.baseUrl}/Room/${id}/Member`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|