mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 21:06:06 +00:00
reorganizde file path
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { create } from 'domain';
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
import { RoomRemoteDataSourceService } from '../../../data/repository/room/room-remote-repository.service';
|
||||
import { RoomSocketRepositoryService } from '../../../data/repository/room/room-socket-repository.service';
|
||||
import { captureAndReraiseAsync } from 'src/app/services/decorators/captureAndReraiseAsync';
|
||||
import { RoomInputDTO } from '../../../data/dto/room/roomInputDTO';
|
||||
import { RoomLocalRepository } from '../../../data/repository/room/room-local-repository.service';
|
||||
import { TracingType, XTracerAsync } from 'src/app/services/monitoring/opentelemetry/tracer';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class CreateRoomUseCaseService {
|
||||
|
||||
constructor(
|
||||
private roomRemoteDataSourceService: RoomRemoteDataSourceService,
|
||||
private roomLocalDataSourceService: RoomLocalRepository,
|
||||
private RoomSocketRepositoryService: RoomSocketRepositoryService
|
||||
) { }
|
||||
|
||||
|
||||
@XTracerAsync({name:'room-create-use-case.service', module:'chat', bugPrint: true, waitNThrow: 5000})
|
||||
async execute(data: RoomInputDTO, tracing?: TracingType) {
|
||||
|
||||
const result = await this.RoomSocketRepositoryService.CreateGroup(data)
|
||||
// const result = await this.roomRemoteDataSourceService.createRoom(data)
|
||||
|
||||
if(result.isOk()) {
|
||||
|
||||
console.log(result.value)
|
||||
if(!result?.value?.createdBy) {
|
||||
|
||||
let dataObject;
|
||||
|
||||
result.value.createdBy = {
|
||||
wxeMail: SessionStore.user.Email,
|
||||
wxFullName: SessionStore.user.FullName,
|
||||
wxUserId: SessionStore.user.UserId,
|
||||
}
|
||||
dataObject = result.value
|
||||
}
|
||||
|
||||
const localResult = await this.roomLocalDataSourceService.insert(result.value)
|
||||
return localResult.map(e => result.value)
|
||||
} else {
|
||||
tracing.hasError("socket close");
|
||||
console.log(result.error)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { captureAndReraiseAsync } from 'src/app/services/decorators/captureAndReraiseAsync';
|
||||
import { isHttpResponse } from 'src/app/services/http.service';
|
||||
import { RoomByIdInputDTO } from '../../../data/dto/room/roomByIdInputDTO';
|
||||
import { RoomRemoteDataSourceService } from '../../../data/repository/room/room-remote-repository.service';
|
||||
import { RoomLocalRepository } from '../../../data/repository/room/room-local-repository.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class DeleteRoomUseCaseService {
|
||||
|
||||
constructor(
|
||||
private roomRemoteDataSourceService: RoomRemoteDataSourceService,
|
||||
// private roomMemoryDataSourceService: Store<RoomRemoteDataSourceState>,
|
||||
private roomLocalDataSourceService: RoomLocalRepository,
|
||||
) { }
|
||||
|
||||
|
||||
@captureAndReraiseAsync('RoomRepositoryService/deleteRoomById')
|
||||
async execute(id: RoomByIdInputDTO) {
|
||||
const result = await this.roomRemoteDataSourceService.deleteRoom(id)
|
||||
|
||||
if(result.isOk()) {
|
||||
|
||||
const result = await this.roomLocalDataSourceService.delete(id)
|
||||
// this.messageLiveDataSourceService.sendMessage({
|
||||
// type: 'createRoom',
|
||||
// payload: {a: '5'}
|
||||
// })
|
||||
|
||||
return result
|
||||
} else if (isHttpResponse(result.error)) {
|
||||
if(result.error.status == 404) {
|
||||
await this.roomLocalDataSourceService.delete(id)
|
||||
}
|
||||
// this.httpErrorHandle.httpStatusHandle(result.error)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { id } from 'date-fns/locale';
|
||||
import { isHttpResponse } from 'src/app/services/http.service';
|
||||
import { roomListDetermineChanges } from '../../../data/async/list/rooms/roomListChangeDetector';
|
||||
import { roomMemberListDetermineChanges } from '../../../data/async/list/rooms/roomMembersChangeDetector';
|
||||
import { RoomRemoteDataSourceService } from '../../../data/repository/room/room-remote-repository.service';
|
||||
import { RoomLocalRepository } from '../../../data/repository/room/room-local-repository.service';
|
||||
import { MemberListLocalRepository } from '../../../data/repository/member/member-list-local-repository.service';
|
||||
import { MemberListMapper } from '../../mapper/memberLIstMapper';
|
||||
import { captureAndReraiseAsync } from 'src/app/services/decorators/captureAndReraiseAsync';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class GetRoomByIdUseCaseService {
|
||||
|
||||
constructor(
|
||||
private roomRemoteDataSourceService: RoomRemoteDataSourceService,
|
||||
// private roomMemoryDataSourceService: Store<RoomRemoteDataSourceState>,
|
||||
private roomLocalDataSourceService: RoomLocalRepository,
|
||||
private MemberListLocalRepository: MemberListLocalRepository
|
||||
) { }
|
||||
|
||||
@captureAndReraiseAsync('RoomRepositoryService/getRoomById')
|
||||
async execute(id: string) {
|
||||
const result = await this.roomRemoteDataSourceService.getRoom(id)
|
||||
|
||||
if(result.isOk()) {
|
||||
|
||||
const localListRoom = await this.roomLocalDataSourceService.findAll()
|
||||
if(localListRoom.isOk()) {
|
||||
const object = {
|
||||
chatRoom: result.value.data
|
||||
}
|
||||
const { roomsToDelete, roomsToInsert, roomsToUpdate } = roomListDetermineChanges([object], localListRoom.value)
|
||||
|
||||
for( const roomData of roomsToUpdate) {
|
||||
this.roomLocalDataSourceService.update(roomData.chatRoom.id, roomData.chatRoom)
|
||||
}
|
||||
|
||||
// ============================
|
||||
const localList = await this.MemberListLocalRepository.getRoomMemberById(id)
|
||||
|
||||
const { membersToInsert, membersToUpdate, membersToDelete } = roomMemberListDetermineChanges(result.value.data.members, localList, id)
|
||||
|
||||
for (const user of membersToInsert) {
|
||||
await this.MemberListLocalRepository.addMember(MemberListMapper(user, id))
|
||||
}
|
||||
|
||||
for (const user of membersToUpdate) {
|
||||
await this.MemberListLocalRepository.updateMemberRole(MemberListMapper(user, id))
|
||||
}
|
||||
|
||||
for(const user of membersToDelete) {
|
||||
await this.MemberListLocalRepository.removeMemberFromRoom(user.$roomIdUserId)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} else if (isHttpResponse(result.error) ) {
|
||||
if(result.error.status == 404) {
|
||||
await this.roomLocalDataSourceService.delete(id)
|
||||
}
|
||||
// this.httpErrorHandle.httpStatusHandle(result.error)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { roomListDetermineChanges } from '../../../data/async/list/rooms/roomListChangeDetector';
|
||||
import { RoomRemoteDataSourceService } from '../../../data/repository/room/room-remote-repository.service';
|
||||
import { RoomLocalRepository } from '../../../data/repository/room/room-local-repository.service';
|
||||
import { captureAndReraiseAsync } from 'src/app/services/decorators/captureAndReraiseAsync';
|
||||
import { isHttpResponse } from 'src/app/services/http.service';
|
||||
import { CronJobService } from 'src/app/utils/task-scheduler'
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class GetRoomListUseCaseService {
|
||||
|
||||
constructor(
|
||||
private roomRemoteDataSourceService: RoomRemoteDataSourceService,
|
||||
// private roomMemoryDataSourceService: Store<RoomRemoteDataSourceState>,
|
||||
private roomLocalDataSourceService: RoomLocalRepository,
|
||||
private CronJobService: CronJobService
|
||||
) { }
|
||||
|
||||
@captureAndReraiseAsync('RoomRepositoryService/list')
|
||||
async execute() {
|
||||
const result = await this.roomRemoteDataSourceService.getRoomList()
|
||||
|
||||
const localList = await this.roomLocalDataSourceService.findAll()
|
||||
|
||||
if(localList.isOk()) {
|
||||
if(result.isOk()) {
|
||||
const { roomsToDelete, roomsToInsert, roomsToUpdate } = roomListDetermineChanges(result.value.data, localList.value)
|
||||
|
||||
for( const roomData of roomsToInsert) {
|
||||
this.roomLocalDataSourceService.insert(roomData.chatRoom)
|
||||
|
||||
if(roomData.chatRoom.expirationDate) {
|
||||
console.log('room expiration date schedule')
|
||||
this.CronJobService.createCronJob('remove expired room', new Date(roomData.chatRoom.expirationDate), this.execute)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for( const roomData of roomsToUpdate) {
|
||||
this.roomLocalDataSourceService.update(roomData.chatRoom.id, roomData.chatRoom)
|
||||
}
|
||||
|
||||
for( const roomData of roomsToDelete) {
|
||||
this.roomLocalDataSourceService.delete(roomData.id)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { UserRemoveListInputDTO } from '../../../data/dto/room/userRemoveListInputDTO';
|
||||
import { isHttpResponse } from 'src/app/services/http.service';
|
||||
import { RoomRemoteDataSourceService } from '../../../data/repository/room/room-remote-repository.service';
|
||||
import { RoomLocalRepository } from '../../../data/repository/room/room-local-repository.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class RoomLeaveUseCase {
|
||||
|
||||
constructor(
|
||||
private roomRemoteDataSourceService: RoomRemoteDataSourceService,
|
||||
private roomLocalDataSourceService: RoomLocalRepository,
|
||||
) { }
|
||||
|
||||
|
||||
|
||||
async execute(data: UserRemoveListInputDTO) {
|
||||
const result = await this.roomRemoteDataSourceService.removeMemberFromRoom(data)
|
||||
|
||||
if(result.isOk()) {
|
||||
this.roomLocalDataSourceService.delete(data.id)
|
||||
} else if (isHttpResponse(result.error)) {
|
||||
if(result.error.status == 404) {
|
||||
await this.roomLocalDataSourceService.delete(data.id)
|
||||
|
||||
}
|
||||
// this.httpErrorHandle.httpStatusHandle(result.error)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { captureAndReraiseAsync } from 'src/app/services/decorators/captureAndReraiseAsync';
|
||||
import { RoomUpdateInputDTO } from '../../../data/dto/room/roomUpdateInputDTO';
|
||||
import { RoomRemoteDataSourceService } from '../../../data/repository/room/room-remote-repository.service';
|
||||
import { RoomLocalRepository } from '../../../data/repository/room/room-local-repository.service';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class UpdateRoomByIdUseCaseService {
|
||||
|
||||
constructor(
|
||||
private roomRemoteDataSourceService: RoomRemoteDataSourceService,
|
||||
private roomLocalDataSourceService: RoomLocalRepository,
|
||||
) { }
|
||||
|
||||
|
||||
@captureAndReraiseAsync('RoomRepositoryService/updateRoomBy')
|
||||
async execute(data: RoomUpdateInputDTO) {
|
||||
|
||||
const result = await this.roomRemoteDataSourceService.updateRoom(data)
|
||||
|
||||
if(result.isOk()) {
|
||||
const localList = await this.roomLocalDataSourceService.findAll()
|
||||
// const { roomsToDelete, roomsToInsert, roomsToUpdate } = roomListDetermineChanges([result.value.data], localList)
|
||||
|
||||
// for( const roomData of roomsToUpdate) {
|
||||
// if(!roomData.chatRoom.createdBy?.wxUserId) {
|
||||
// delete roomData.chatRoom.createdBy;
|
||||
// }
|
||||
|
||||
// this.roomLocalDataSourceService.updateRoom(roomData.chatRoom)
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user