import { Injectable } from '@angular/core'; import { Result } from 'neverthrow'; import { HttpService } from 'src/app/services/http.service'; import { RoomListOutPutDTO, RoomListOutPutDTOSchema } from '../../dto/room/roomListOutputDTO'; import { RoomInputDTO, RoomInputDTOSchema } from '../../dto/room/roomInputDTO'; import { RoomOutPutDTO, RoomOutPutDTOSchema } 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'; 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'; import { UserRemoveListInputDTO, UserRemoveListInputDTOSchema } from '../../dto/room/userRemoveListInputDTO'; @Injectable({ providedIn: 'root' }) export class RoomRemoteDataSourceService { private baseUrl = 'https://gdapi-dev.dyndns.info/stage/api/v2/Chat'; // Your base URL constructor(private httpService: HttpService) {} @ValidateSchema(RoomInputDTOSchema) @APIReturn(RoomOutPutDTOSchema) async createRoom(data: RoomInputDTO): DataSourceReturn { return await this.httpService.post(`${this.baseUrl}/Room`, data); } @APIReturn(RoomListOutPutDTOSchema) async getRoomList(): Promise> { return await this.httpService.get(`${this.baseUrl}/Room`); } @ValidateSchema(RoomByIdInputDTOSchema) @APIReturn(RoomByIdOutputDTOSchema) async getRoom(id: RoomByIdInputDTO): DataSourceReturn { return await this.httpService.get(`${this.baseUrl}/Room/${id}`); } async updateRoom(id: string, room: any): Promise> { return await this.httpService.put(`${this.baseUrl}/Room/${id}`, room); } async deleteRoom(id: string): Promise> { return await this.httpService.delete(`${this.baseUrl}/Room/${id}`, {}); } @ValidateSchema(AddMemberToRoomInputDTOSchema) async addMemberToRoom(data: AddMemberToRoomInputDTO): DataSourceReturn { return await this.httpService.post(`${this.baseUrl}/Room/${data.id}/Member`, { members:data.members }); } @ValidateSchema(UserRemoveListInputDTOSchema) async removeMemberFromRoom(data: UserRemoveListInputDTO): Promise> { return await this.httpService.delete(`${this.baseUrl}/Room/${data.id}/Member`, {members:data.members}); } }