mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
add chat repository
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { RoomRemoteDataSourceService } from './room-remote-data-source.service';
|
||||
|
||||
describe('RoomRemoteDataSourceService', () => {
|
||||
let service: RoomRemoteDataSourceService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(RoomRemoteDataSourceService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,56 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ok, err, Result } from 'neverthrow';
|
||||
import { HttpService } from 'src/app/services/http.service';
|
||||
import { RoomListOutPutDTO } from '../dto/roomOutputDTO';
|
||||
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class RoomRemoteDataSourceService {
|
||||
|
||||
private baseUrl = 'https://gdapi-dev.dyndns.info/stage/api/v2'; // Your base URL
|
||||
|
||||
constructor(private httpService: HttpService) {}
|
||||
|
||||
async sendMessage(message: any): Promise<Result<any ,any>> {
|
||||
return await this.httpService.post<any>(`${this.baseUrl}/Messages`, message);
|
||||
}
|
||||
|
||||
async reactToMessage(id: string, reaction: any): Promise<Result<any ,any>> {
|
||||
return await this.httpService.post<any>(`${this.baseUrl}/Messages/${id}/React`, reaction);
|
||||
}
|
||||
|
||||
async createRoom(room: any): Promise<Result<any ,any>> {
|
||||
return await this.httpService.post<any>(`${this.baseUrl}/Room`, room);
|
||||
}
|
||||
|
||||
|
||||
async getRoomList(): Promise<Result<RoomListOutPutDTO ,any>> {
|
||||
return await this.httpService.get<any>(`${this.baseUrl}/Room`);
|
||||
}
|
||||
|
||||
async getRoom(id: string): Promise<Result<any ,any>> {
|
||||
return await this.httpService.get<any>(`${this.baseUrl}/Room/${id}`);
|
||||
}
|
||||
|
||||
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}`);
|
||||
}
|
||||
|
||||
async addMemberToRoom(id: string, member: any): Promise<Result<any ,any>> {
|
||||
return await this.httpService.post<any>(`${this.baseUrl}/Room/${id}/Member`, member);
|
||||
}
|
||||
|
||||
async removeMemberFromRoom(id: string, member: any): Promise<Result<any ,any>> {
|
||||
return await this.httpService.delete<any>(`${this.baseUrl}/Room/${id}/Member`);
|
||||
}
|
||||
|
||||
async getMessagesFromRoom(id: string): Promise<Result<any ,any>> {
|
||||
return await this.httpService.get<any>(`${this.baseUrl}/Room/${id}/Messages`);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { z } from "zod";
|
||||
|
||||
const CreatedBySchema = z.object({
|
||||
wxUserId: z.number(),
|
||||
wxFullName: z.string(),
|
||||
wxeMail: z.string().email(),
|
||||
userPhoto: z.string()
|
||||
});
|
||||
|
||||
const RoomListOutPutDTOSchema = z.object({
|
||||
id: z.string(),
|
||||
roomName: z.string(),
|
||||
createdBy: CreatedBySchema,
|
||||
createdAt: z.string().datetime(),
|
||||
expirationDate: z.string().datetime(),
|
||||
roomType: z.number()
|
||||
});
|
||||
|
||||
|
||||
|
||||
export type RoomListOutPutDTO = z.infer<typeof RoomListOutPutDTOSchema>
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class MessageRepositoryService {
|
||||
|
||||
constructor(
|
||||
) { }
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { RoomRemoteDataSourceService } from '../data-source/room-remote-data-source.service'
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class RoomRepositoryService {
|
||||
|
||||
constructor(
|
||||
private roomRemoteDataSourceService: RoomRemoteDataSourceService
|
||||
) { }
|
||||
|
||||
list() {
|
||||
this.roomRemoteDataSourceService.getRoomList()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class UserRepositoryService {
|
||||
|
||||
constructor() { }
|
||||
}
|
||||
Reference in New Issue
Block a user