Skip to content

Commit

Permalink
extract visitor into seperate file
Browse files Browse the repository at this point in the history
  • Loading branch information
Metauriel committed Sep 18, 2023
1 parent e668e52 commit 9afc77b
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 29 deletions.
2 changes: 1 addition & 1 deletion apps/server/src/modules/board/board.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
ContentElementService,
SubmissionItemService,
} from './service';
import { BoardDoCopyService } from './service/board-do-copy.service';
import { BoardDoCopyService } from './service/board-do-copy-service';
import { ColumnBoardCopyService } from './service/column-board-copy.service';

@Module({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Injectable } from '@nestjs/common';
import { AnyBoardDo, EntityId } from '@shared/domain';
import { CopyStatus } from '@src/modules/copy-helper';
import { FilesStorageClientAdapterService } from '@src/modules/files-storage-client';
import { RecursiveCopyVisitor } from './recursive-copy.visitor';

export type BoardDoCopyParams = {
originSchoolId: EntityId;
targetSchoolId?: EntityId;
userId: EntityId;
original: AnyBoardDo;
};

@Injectable()
export class BoardDoCopyService {
constructor(private readonly filesStorageClientAdapterService: FilesStorageClientAdapterService) {}

public async copy(params: BoardDoCopyParams): Promise<CopyStatus> {
const visitor = new RecursiveCopyVisitor(this.filesStorageClientAdapterService, {
userId: params.userId,
originSchoolId: params.originSchoolId,
targetSchoolId: params.targetSchoolId || params.originSchoolId,
});

const result = await visitor.copy(params.original);

return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './board-do-copy.service';
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Injectable } from '@nestjs/common';
import {
AnyBoardDo,
BoardCompositeVisitorAsync,
Expand All @@ -22,7 +21,7 @@ type RecursiveCopyVisitorParams = {
userId: EntityId;
};

class RecursiveCopyVisitor implements BoardCompositeVisitorAsync {
export class RecursiveCopyVisitor implements BoardCompositeVisitorAsync {
resultMap = new Map<EntityId, CopyStatus>();

copyMap = new Map<EntityId, AnyBoardDo>();
Expand Down Expand Up @@ -213,27 +212,3 @@ class RecursiveCopyVisitor implements BoardCompositeVisitorAsync {
return copies;
}
}

export type BoardDoCopyParams = {
originSchoolId: EntityId;
targetSchoolId?: EntityId;
userId: EntityId;
original: AnyBoardDo;
};

@Injectable()
export class BoardDoCopyService {
constructor(private readonly filesStorageClientAdapterService: FilesStorageClientAdapterService) {}

public async copy(params: BoardDoCopyParams): Promise<CopyStatus> {
const visitor = new RecursiveCopyVisitor(this.filesStorageClientAdapterService, {
userId: params.userId,
originSchoolId: params.originSchoolId,
targetSchoolId: params.targetSchoolId || params.originSchoolId,
});

const result = await visitor.copy(params.original);

return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { columnBoardFactory, courseFactory, schoolFactory, setupEntities, userFa
import { CopyElementType, CopyStatus, CopyStatusEnum } from '@src/modules/copy-helper';
import { UserService } from '@src/modules/user';
import { BoardDoRepo } from '../repo';
import { BoardDoCopyService } from './board-do-copy.service';
import { BoardDoCopyService } from './board-do-copy-service';
import { ColumnBoardCopyService } from './column-board-copy.service';

describe('column board copy service', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { CourseRepo } from '@shared/repo';
import { CopyStatus } from '@src/modules/copy-helper';
import { UserService } from '@src/modules/user';
import { BoardDoRepo } from '../repo';
import { BoardDoCopyService } from './board-do-copy.service';
import { BoardDoCopyService } from './board-do-copy-service';

@Injectable()
export class ColumnBoardCopyService {
Expand Down

0 comments on commit 9afc77b

Please sign in to comment.