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-08 14:58:49 +01:00
|
|
|
import { RoomListOutPutDTO, RoomListOutPutDTOSchema } from '../../dto/room/roomListOutputDTO';
|
2024-06-04 16:21:11 +01:00
|
|
|
import { RoomInputDTO, RoomInputDTOSchema } from '../../dto/room/roomInputDTO';
|
2024-06-10 16:34:43 +01:00
|
|
|
import { RoomOutPutDTO, RoomOutPutDTOSchema } from '../../dto/room/roomOutputDTO';
|
2024-06-04 16:21:11 +01:00
|
|
|
import { AddMemberToRoomInputDTO, AddMemberToRoomInputDTOSchema } from '../../dto/room/addMemberToRoomInputDto';
|
|
|
|
|
import { ValidateSchema } from 'src/app/services/decorators/validate-schema.decorator';
|
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-10 16:34:43 +01:00
|
|
|
import { UserRemoveListInputDTO, UserRemoveListInputDTOSchema } from '../../dto/room/userRemoveListInputDTO';
|
2024-06-12 09:44:28 +01:00
|
|
|
import { RoomUpdateInputDTO, RoomUpdateInputDTOSchema } from '../../dto/room/roomUpdateInputDTO';
|
|
|
|
|
import { RoomUpdateOutputDTO } from '../../dto/room/roomUpdateOutputDTO';
|
2024-07-11 10:28:21 +01:00
|
|
|
import { DataSourceReturn } from 'src/app/services/Repositorys/type';
|
2024-07-22 13:28:52 +01:00
|
|
|
import { SessionStore } from 'src/app/store/session.service';
|
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)
|
2024-06-11 11:46:04 +01:00
|
|
|
@APIReturn(RoomOutPutDTOSchema, 'post/Room')
|
2024-06-04 16:21:11 +01:00
|
|
|
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-08 14:58:49 +01:00
|
|
|
|
2024-06-11 11:46:04 +01:00
|
|
|
@APIReturn(RoomListOutPutDTOSchema, 'get/Room')
|
2024-06-05 11:09:03 +01:00
|
|
|
async getRoomList(): Promise<DataSourceReturn<RoomListOutPutDTO>> {
|
2024-07-22 13:28:52 +01:00
|
|
|
return await this.httpService.get<RoomListOutPutDTO>(`${this.baseUrl}/Room?userId=${SessionStore.user.UserId}`);
|
2024-06-03 13:34:40 +01:00
|
|
|
}
|
|
|
|
|
|
2024-06-07 12:29:53 +01:00
|
|
|
@ValidateSchema(RoomByIdInputDTOSchema)
|
2024-06-11 11:46:04 +01:00
|
|
|
@APIReturn(RoomByIdOutputDTOSchema,'get/Room/${id}')
|
2024-06-07 12:29:53 +01:00
|
|
|
async getRoom(id: RoomByIdInputDTO): DataSourceReturn<RoomByIdOutputDTO> {
|
|
|
|
|
return await this.httpService.get(`${this.baseUrl}/Room/${id}`);
|
2024-06-03 13:34:40 +01:00
|
|
|
}
|
|
|
|
|
|
2024-06-12 09:44:28 +01:00
|
|
|
@ValidateSchema(RoomUpdateInputDTOSchema)
|
2024-06-11 13:48:44 +01:00
|
|
|
//@APIReturn(RoomByIdOutputDTOSchema,'update/Room/${id}')
|
2024-06-12 09:44:28 +01:00
|
|
|
async updateRoom(data: RoomUpdateInputDTO): Promise<DataSourceReturn<RoomUpdateOutputDTO>> {
|
2024-06-11 13:48:44 +01:00
|
|
|
const id = data.roomId
|
|
|
|
|
delete data.roomId
|
|
|
|
|
return await this.httpService.put<any>(`${this.baseUrl}/Room/${id}`, data);
|
2024-06-03 13:34:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async deleteRoom(id: string): Promise<Result<any ,any>> {
|
2024-06-10 16:34:43 +01:00
|
|
|
return await this.httpService.delete<any>(`${this.baseUrl}/Room/${id}`, {});
|
2024-06-03 13:34:40 +01:00
|
|
|
}
|
|
|
|
|
|
2024-06-04 16:21:11 +01:00
|
|
|
@ValidateSchema(AddMemberToRoomInputDTOSchema)
|
|
|
|
|
async addMemberToRoom(data: AddMemberToRoomInputDTO): DataSourceReturn<AddMemberToRoomInputDTO> {
|
2024-06-10 16:34:43 +01:00
|
|
|
return await this.httpService.post<any>(`${this.baseUrl}/Room/${data.id}/Member`, { members:data.members });
|
2024-06-03 13:34:40 +01:00
|
|
|
}
|
|
|
|
|
|
2024-06-10 16:34:43 +01:00
|
|
|
|
|
|
|
|
@ValidateSchema(UserRemoveListInputDTOSchema)
|
|
|
|
|
async removeMemberFromRoom(data: UserRemoveListInputDTO): Promise<Result<any ,any>> {
|
|
|
|
|
return await this.httpService.delete<any>(`${this.baseUrl}/Room/${data.id}/Member`, {members:data.members});
|
2024-06-03 13:34:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|