mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
create room
This commit is contained in:
+3
-3
@@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
|
||||
import { HttpService } from 'src/app/services/http.service';
|
||||
import { MessageOutPutDTO } from '../../dto/message/messageOutputDTO';
|
||||
import { MessageListInputDTO } from '../../dto/message/messageListInputDTO';
|
||||
import { DataSourceReturn } from '../../../type';
|
||||
|
||||
|
||||
@Injectable({
|
||||
@@ -13,7 +14,6 @@ export class MessageRemoteDataSourceService {
|
||||
|
||||
constructor(private httpService: HttpService) {}
|
||||
|
||||
|
||||
async sendMessage(message: any) {
|
||||
return await this.httpService.post<any>(`${this.baseUrl}/Messages`, message);
|
||||
}
|
||||
@@ -22,7 +22,7 @@ export class MessageRemoteDataSourceService {
|
||||
return await this.httpService.post<any>(`${this.baseUrl}/Messages/${id}/React`, reaction);
|
||||
}
|
||||
|
||||
async getMessagesFromRoom(id: MessageListInputDTO) {
|
||||
return await this.httpService.get<MessageOutPutDTO>(`${this.baseUrl}/Room/${id}/Messages`);
|
||||
async getMessagesFromRoom(id: MessageListInputDTO): DataSourceReturn<MessageListInputDTO> {
|
||||
return await this.httpService.get(`${this.baseUrl}/Room/${id}/Messages`);
|
||||
}
|
||||
}
|
||||
|
||||
+12
-18
@@ -1,10 +1,12 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { ok, err, Result } from 'neverthrow';
|
||||
import { Result } from 'neverthrow';
|
||||
import { HttpService } from 'src/app/services/http.service';
|
||||
import { RoomListOutPutDTO } from '../dto/roomListOutputDTO';
|
||||
import { RoomListInputDTO } from '../dto/roomInputDTO';
|
||||
import { RoomOutPutDTO } from '../dto/roomOutputDTO';
|
||||
import { AddMemberToRoomInputDTO } from '../dto/addMemberToRoomInputDto';
|
||||
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';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -15,16 +17,10 @@ export class RoomRemoteDataSourceService {
|
||||
|
||||
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(data: RoomListInputDTO): Promise<Result<RoomOutPutDTO ,any>> {
|
||||
return await this.httpService.post<any>(`${this.baseUrl}/Room`, data);
|
||||
@ValidateSchema(RoomInputDTOSchema)
|
||||
async createRoom(data: RoomInputDTO): DataSourceReturn<RoomOutPutDTO> {
|
||||
return await this.httpService.post<RoomOutPutDTO>(`${this.baseUrl}/Room`, data);
|
||||
}
|
||||
|
||||
async getRoomList(): Promise<Result<RoomListOutPutDTO ,any>> {
|
||||
@@ -43,7 +39,8 @@ export class RoomRemoteDataSourceService {
|
||||
return await this.httpService.delete<any>(`${this.baseUrl}/Room/${id}`);
|
||||
}
|
||||
|
||||
async addMemberToRoom(data: AddMemberToRoomInputDTO) {
|
||||
@ValidateSchema(AddMemberToRoomInputDTOSchema)
|
||||
async addMemberToRoom(data: AddMemberToRoomInputDTO): DataSourceReturn<AddMemberToRoomInputDTO> {
|
||||
return await this.httpService.post<any>(`${this.baseUrl}/Room/${data.id}/Member`, data.member);
|
||||
}
|
||||
|
||||
@@ -51,7 +48,4 @@ export class RoomRemoteDataSourceService {
|
||||
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,94 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { AddMemberToRoomInputDTO } from '../../dto/room/addMemberToRoomInputDto';
|
||||
import { RoomListOutPutDTO } from '../../dto/room/roomListOutputDTO';
|
||||
import { Dexie, EntityTable, liveQuery } from 'Dexie';
|
||||
import { err, ok } from 'neverthrow';
|
||||
import { Observable } from 'rxjs';
|
||||
import { RoomOutPutDTO } from '../../dto/room/roomOutputDTO';
|
||||
import { z } from 'zod';
|
||||
|
||||
|
||||
|
||||
const tableSchema = z.object({
|
||||
id: z.string(),
|
||||
roomName: z.string(),
|
||||
createdBy: z.any(),
|
||||
createdAt: z.any(),
|
||||
expirationDate: z.any(),
|
||||
roomType: z.any()
|
||||
})
|
||||
export type Table = z.infer<typeof tableSchema>
|
||||
|
||||
// Database declaration (move this to its own module also)
|
||||
export const roomDataSource = new Dexie('FriendDatabase') as Dexie & {
|
||||
room: EntityTable<Table, 'id'>;
|
||||
};
|
||||
|
||||
roomDataSource.version(1).stores({
|
||||
room: '++id, createdBy, roomName, roomType, expirationDate'
|
||||
});
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class RoomLocalDataSourceService {
|
||||
|
||||
private baseUrl = 'https://gdapi-dev.dyndns.info/stage/api/v2/Chat'; // Your base URL
|
||||
|
||||
constructor() {}
|
||||
|
||||
|
||||
async createRoom(data: RoomOutPutDTO) {
|
||||
|
||||
const roomData = {
|
||||
createdBy: {
|
||||
wxUserId: 0,
|
||||
wxFullName: "",
|
||||
wxeMail: "",
|
||||
userPhoto: ""
|
||||
},
|
||||
roomName: data.data.roomName,
|
||||
id: data.data.id,
|
||||
roomType: 21,
|
||||
expirationDate: '',
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await roomDataSource.room.add(roomData)
|
||||
return ok(result)
|
||||
} catch (e) {
|
||||
return err(false)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async getRoomList() {
|
||||
|
||||
}
|
||||
|
||||
async getRoom(id: string){
|
||||
|
||||
}
|
||||
|
||||
async updateRoom(id: string, room: any) {
|
||||
|
||||
}
|
||||
|
||||
async deleteRoom(id: string){
|
||||
|
||||
}
|
||||
|
||||
async addMemberToRoom(data: AddMemberToRoomInputDTO) {
|
||||
|
||||
}
|
||||
|
||||
async removeMemberFromRoom(id: string, member: any){
|
||||
|
||||
}
|
||||
|
||||
getItemsLive(): Observable<RoomListOutPutDTO[]> {
|
||||
return liveQuery(() => roomDataSource.room.toArray()) as any;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import { z } from "zod"
|
||||
|
||||
const MessageListInputDTOSchema = z.object({
|
||||
roomId: z.string(),
|
||||
});
|
||||
|
||||
export type MessageListInputDTO = z.infer<typeof MessageListInputDTOSchema>
|
||||
@@ -0,0 +1,20 @@
|
||||
import { z } from "zod"
|
||||
|
||||
const MessageOutPutDTOSchema = z.object({
|
||||
id: z.string(),
|
||||
sender: z.object({
|
||||
wxUserId: z.number(),
|
||||
wxFullName: z.string(),
|
||||
wxeMail: z.string().email(),
|
||||
userPhoto: z.string()
|
||||
}),
|
||||
message: z.string().datetime(),
|
||||
messageType: z.string().datetime(),
|
||||
sentAt: z.number(),
|
||||
deliverAt: z.any(),
|
||||
canEdit: z.any(),
|
||||
oneShot: z.any(),
|
||||
requireUnlock: z.any()
|
||||
});
|
||||
|
||||
export type MessageOutPutDTO = z.infer<typeof MessageOutPutDTOSchema>
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const RoomListInputDTOSchema = z.object({
|
||||
export const RoomInputDTOSchema = z.object({
|
||||
roomName: z.string(),
|
||||
createdBy: z.number(),
|
||||
roomType: z.number(),
|
||||
@@ -8,4 +8,4 @@ export const RoomListInputDTOSchema = z.object({
|
||||
});
|
||||
|
||||
|
||||
export type RoomListInputDTO = z.infer<typeof RoomListInputDTOSchema>
|
||||
export type RoomInputDTO = z.infer<typeof RoomInputDTOSchema>
|
||||
+3
-2
@@ -7,7 +7,7 @@ const CreatedBySchema = z.object({
|
||||
userPhoto: z.string()
|
||||
});
|
||||
|
||||
const RoomListOutPutDTOSchema = z.object({
|
||||
const RoomListItemOutPutDTOSchema = z.object({
|
||||
id: z.string(),
|
||||
roomName: z.string(),
|
||||
createdBy: CreatedBySchema,
|
||||
@@ -15,7 +15,8 @@ const RoomListOutPutDTOSchema = z.object({
|
||||
expirationDate: z.string().datetime(),
|
||||
roomType: z.number()
|
||||
});
|
||||
export type RoomListItemOutPutDTO = z.infer<typeof RoomListItemOutPutDTOSchema>
|
||||
|
||||
|
||||
|
||||
const RoomListOutPutDTOSchema = z.array(RoomListItemOutPutDTOSchema);
|
||||
export type RoomListOutPutDTO = z.infer<typeof RoomListOutPutDTOSchema>
|
||||
+8
-1
@@ -3,7 +3,14 @@ import { z } from "zod";
|
||||
const RoomOutPutDTOSchema = z.object({
|
||||
success: z.string(),
|
||||
message: z.string(),
|
||||
data: z.any()
|
||||
data: z.object({
|
||||
id: z.string(),
|
||||
roomName: z.string(),
|
||||
createdBy: z.any(),
|
||||
createdAt: z.date(),
|
||||
expirationDate: z.date(),
|
||||
roomType: z.any()
|
||||
})
|
||||
});
|
||||
|
||||
export type RoomOutPutDTO = z.infer<typeof RoomOutPutDTOSchema>
|
||||
@@ -1,4 +1,7 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { MessageRemoteDataSourceService } from '../data-source/message/message-remote-data-source.service';
|
||||
import { MessageLiveDataSourceService } from '../data-source/message/message-live-data-source.service';
|
||||
import { MessageListInputDTO } from '../dto/message/messageListInputDTO';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -6,5 +9,17 @@ import { Injectable } from '@angular/core';
|
||||
export class MessageRepositoryService {
|
||||
|
||||
constructor(
|
||||
) { }
|
||||
private messageRemoteDataSourceService: MessageRemoteDataSourceService,
|
||||
private messageLiveDataSourceService: MessageLiveDataSourceService
|
||||
) {}
|
||||
|
||||
async sendMessage() {
|
||||
// const result = this.messageRemoteDataSourceService.sendMessage()
|
||||
}
|
||||
|
||||
async getMessagesFromRoom(data: MessageListInputDTO) {
|
||||
const result = await this.messageRemoteDataSourceService.getMessagesFromRoom(data)
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { RoomRemoteDataSourceService } from '../data-source/room-remote-data-source.service'
|
||||
import { RoomListInputDTO, RoomListInputDTOSchema } from '../dto/roomInputDTO';
|
||||
import { IRepositoryReturn } from '../../type';
|
||||
import { ValidateSchema } from 'src/app/services/decorators/validate-schema.decorator';
|
||||
import { addRoom, RoomRemoteDataSourceState } from '../data-source/room-memory-data-source';
|
||||
import { RoomRemoteDataSourceService } from '../data-source/room/room-remote-data-source.service'
|
||||
import { RoomInputDTO } from '../dto/room/roomInputDTO';;
|
||||
import { addRoom, RoomRemoteDataSourceState } from '../data-source/room/room-memory-data-source';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { AddMemberToRoomInputDTO, AddMemberToRoomInputDTOSchema } from '../dto/addMemberToRoomInputDto';
|
||||
import { RoomOutPutDTO } from '../dto/roomOutputDTO';
|
||||
import { AddMemberToRoomInputDTO } from '../dto/room/addMemberToRoomInputDto';
|
||||
import { RoomLocalDataSourceService } from '../data-source/room/rooom-local-data-source.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -15,15 +13,19 @@ export class RoomRepositoryService {
|
||||
|
||||
constructor(
|
||||
private roomRemoteDataSourceService: RoomRemoteDataSourceService,
|
||||
private roomMemoryDataSourceService: Store<RoomRemoteDataSourceState>
|
||||
private roomMemoryDataSourceService: Store<RoomRemoteDataSourceState>,
|
||||
private roomLocalDataSourceService: RoomLocalDataSourceService
|
||||
) { }
|
||||
|
||||
list() {
|
||||
this.roomRemoteDataSourceService.getRoomList()
|
||||
async list() {
|
||||
const result = await this.roomRemoteDataSourceService.getRoomList()
|
||||
return result
|
||||
}
|
||||
|
||||
@ValidateSchema(RoomListInputDTOSchema)
|
||||
async create(data: RoomListInputDTO): IRepositoryReturn<RoomOutPutDTO> {
|
||||
async create(data: RoomInputDTO) {
|
||||
|
||||
this.list()
|
||||
|
||||
const result = await this.roomRemoteDataSourceService.createRoom(data)
|
||||
|
||||
if(result.isOk()) {
|
||||
@@ -32,15 +34,21 @@ export class RoomRepositoryService {
|
||||
timestamp: 0,
|
||||
roomName: data.roomName
|
||||
}))
|
||||
|
||||
this.roomLocalDataSourceService.createRoom(result.value)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
@ValidateSchema(AddMemberToRoomInputDTOSchema)
|
||||
async addMemberToRoom(data: AddMemberToRoomInputDTO): IRepositoryReturn<AddMemberToRoomInputDTO> {
|
||||
|
||||
async addMemberToRoom(data: AddMemberToRoomInputDTO) {
|
||||
const result = await this.roomRemoteDataSourceService.addMemberToRoom(data)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
getItemsLive() {
|
||||
return this.roomLocalDataSourceService.getItemsLive()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class UserRepositoryService {
|
||||
|
||||
constructor() { }
|
||||
}
|
||||
@@ -2,4 +2,4 @@ import { HttpErrorResponse } from "@angular/common/http";
|
||||
import { Result } from "neverthrow";
|
||||
import { ZodError } from "zod";
|
||||
|
||||
export type IRepositoryReturn<T> = Promise<Result<any, HttpErrorResponse | ZodError>>
|
||||
export type DataSourceReturn<T> = Promise<Result<T, HttpErrorResponse | ZodError>>
|
||||
|
||||
Reference in New Issue
Block a user