Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: comment repository #1214

Merged
merged 5 commits into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Inject, Injectable } from '@nestjs/common';
import { CreateCommentApplication } from '../interfaces/applications/create.comment.application.interface';
import { CreateCommentApplicationInterface } from '../interfaces/applications/create.comment.application.interface';
import { CreateCommentServiceInterface } from '../interfaces/services/create.comment.service.interface';
import { TYPES } from '../interfaces/types';

@Injectable()
export class CreateCommentApplicationImpl implements CreateCommentApplication {
export class CreateCommentApplication implements CreateCommentApplicationInterface {
constructor(
@Inject(TYPES.services.CreateCommentService)
private createCommentService: CreateCommentServiceInterface
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Inject, Injectable } from '@nestjs/common';
import { DeleteCommentApplication } from '../interfaces/applications/delete.comment.application.interface';
import { DeleteCommentService } from '../interfaces/services/delete.comment.service.interface';
import { DeleteCommentApplicationInterface } from '../interfaces/applications/delete.comment.application.interface';
import { TYPES } from '../interfaces/types';
import DeleteCommentService from '../services/delete.comment.service';

@Injectable()
export class DeleteCommentApplicationImpl implements DeleteCommentApplication {
export class DeleteCommentApplication implements DeleteCommentApplicationInterface {
constructor(
@Inject(TYPES.services.DeleteCommentService)
private deleteCommentService: DeleteCommentService
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
import { Inject, Injectable } from '@nestjs/common';
import { UpdateCommentApplication } from '../interfaces/applications/update.comment.application.interface';
import { UpdateCommentService } from '../interfaces/services/update.comment.service.interface';
import { UpdateCommentApplicationInterface } from '../interfaces/applications/update.comment.application.interface';
import { UpdateCommentServiceInterface } from '../interfaces/services/update.comment.service.interface';
import { TYPES } from '../interfaces/types';

@Injectable()
export class UpdateCommentApplicationImpl implements UpdateCommentApplication {
export class UpdateCommentApplication implements UpdateCommentApplicationInterface {
constructor(
@Inject(TYPES.services.UpdateCommentService)
private updateCommentService: UpdateCommentService
private updateCommentService: UpdateCommentServiceInterface
) {}

updateItemComment(
boardId: string,
cardId: string,
cardItemId: string,
commentId: string,
userId: string,
text: string,
anonymous: boolean
) {
Expand All @@ -24,7 +23,6 @@ export class UpdateCommentApplicationImpl implements UpdateCommentApplication {
cardId,
cardItemId,
commentId,
userId,
text,
anonymous
);
Expand All @@ -34,15 +32,13 @@ export class UpdateCommentApplicationImpl implements UpdateCommentApplication {
boardId: string,
cardId: string,
commentId: string,
userId: string,
text: string,
anonymous: boolean
) {
return this.updateCommentService.updateCardGroupComment(
boardId,
cardId,
commentId,
userId,
text,
anonymous
);
Expand Down
30 changes: 18 additions & 12 deletions backend/src/modules/comments/comment.providers.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,43 @@
import { CreateCommentApplicationImpl } from './applications/create.comment.application';
import { DeleteCommentApplicationImpl } from './applications/delete.comment.application';
import { UpdateCommentApplicationImpl } from './applications/update.comment.application';
import { DeleteCommentApplication } from './applications/delete.comment.application';
import { CreateCommentApplication } from './applications/create.comment.application';
import { UpdateCommentApplication } from './applications/update.comment.application';
import { TYPES } from './interfaces/types';
import CreateCommentServiceImpl from './services/create.comment.service';
import DeleteCommentServiceImpl from './services/delete.comment.service';
import UpdateCommentServiceImpl from './services/update.comment.service';
import { CommentRepository } from './repositories/comment.repository';
import CreateCommentService from './services/create.comment.service';
import DeleteCommentService from './services/delete.comment.service';
import UpdateCommentService from './services/update.comment.service';

export const createCommentService = {
provide: TYPES.services.CreateCommentService,
useClass: CreateCommentServiceImpl
useClass: CreateCommentService
};

export const updateCommentService = {
provide: TYPES.services.UpdateCommentService,
useClass: UpdateCommentServiceImpl
useClass: UpdateCommentService
};

export const deleteCommentService = {
provide: TYPES.services.DeleteCommentService,
useClass: DeleteCommentServiceImpl
useClass: DeleteCommentService
};

export const createCommentApplication = {
provide: TYPES.applications.CreateCommentApplication,
useClass: CreateCommentApplicationImpl
useClass: CreateCommentApplication
};

export const updateCommentApplication = {
provide: TYPES.applications.UpdateCommentApplication,
useClass: UpdateCommentApplicationImpl
useClass: UpdateCommentApplication
};

export const deleteCommentApplication = {
provide: TYPES.applications.DeleteCommentApplication,
useClass: DeleteCommentApplicationImpl
useClass: DeleteCommentApplication
};

export const commentRepository = {
provide: TYPES.repositories.CommentRepository,
useClass: CommentRepository
};
4 changes: 3 additions & 1 deletion backend/src/modules/comments/comments.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { mongooseBoardModule } from 'src/infrastructure/database/mongoose.module
import SocketModule from 'src/modules/socket/socket.module';
import { CardsModule } from '../cards/cards.module';
import {
commentRepository,
createCommentApplication,
createCommentService,
deleteCommentApplication,
Expand All @@ -21,7 +22,8 @@ import CommentsController from './controller/comments.controller';
updateCommentService,
updateCommentApplication,
deleteCommentApplication,
deleteCommentService
deleteCommentService,
commentRepository
],
exports: []
})
Expand Down
14 changes: 6 additions & 8 deletions backend/src/modules/comments/controller/comments.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ import { UserDocument } from 'src/modules/users/entities/user.schema';
import CreateCommentDto from '../dto/create.comment.dto';
import DeleteCommentDto from '../dto/delete.comment.dto';
import UpdateCardCommentDto from '../dto/update.comment.dto';
import { CreateCommentApplication } from '../interfaces/applications/create.comment.application.interface';
import { DeleteCommentApplication } from '../interfaces/applications/delete.comment.application.interface';
import { UpdateCommentApplication } from '../interfaces/applications/update.comment.application.interface';
import { CreateCommentApplicationInterface } from '../interfaces/applications/create.comment.application.interface';
import { DeleteCommentApplicationInterface } from '../interfaces/applications/delete.comment.application.interface';
import { UpdateCommentApplicationInterface } from '../interfaces/applications/update.comment.application.interface';
import { TYPES } from '../interfaces/types';

@ApiBearerAuth('access-token')
Expand All @@ -54,11 +54,11 @@ import { TYPES } from '../interfaces/types';
export default class CommentsController {
constructor(
@Inject(TYPES.services.CreateCommentService)
private createCommentApp: CreateCommentApplication,
private createCommentApp: CreateCommentApplicationInterface,
@Inject(TYPES.services.UpdateCommentService)
private updateCommentApp: UpdateCommentApplication,
private updateCommentApp: UpdateCommentApplicationInterface,
@Inject(TYPES.services.DeleteCommentService)
private deleteCommentApp: DeleteCommentApplication,
private deleteCommentApp: DeleteCommentApplicationInterface,
private socketService: SocketGateway
) {}

Expand Down Expand Up @@ -205,7 +205,6 @@ export default class CommentsController {
cardId,
itemId,
commentId,
request.user._id,
text,
anonymous
);
Expand Down Expand Up @@ -252,7 +251,6 @@ export default class CommentsController {
boardId,
cardId,
commentId,
request.user._id,
text,
anonymous
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Comment from '../../schemas/comment.schema';
import Comment from 'src/modules/comments/schemas/comment.schema';

export interface CreateCommentApplication {
export interface CreateCommentApplicationInterface {
createItemComment(
boardId: string,
cardId: string,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LeanDocument } from 'mongoose';
import { BoardDocument } from 'src/modules/boards/entities/board.schema';

export interface DeleteCommentApplication {
export interface DeleteCommentApplicationInterface {
deleteItemComment(
boardId: string,
commentId: string,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { LeanDocument } from 'mongoose';
import { BoardDocument } from 'src/modules/boards/entities/board.schema';

export interface UpdateCommentApplication {
export interface UpdateCommentApplicationInterface {
updateItemComment(
boardId: string,
cardId: string,
cardItemId: string,
commentId: string,
userId: string,
text: string,
anonymous: boolean
): Promise<LeanDocument<BoardDocument> | null>;
Expand All @@ -16,7 +15,6 @@ export interface UpdateCommentApplication {
boardId: string,
cardId: string,
commentId: string,
userId: string,
text: string,
anonymous: boolean
): Promise<LeanDocument<BoardDocument> | null>;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { BaseInterfaceRepository } from 'src/libs/repositories/interfaces/base.repository.interface';
import Board from 'src/modules/boards/entities/board.schema';

export interface CommentRepositoryInterface extends BaseInterfaceRepository<Board> {
// CREATE COMMENTS
insertItemComment(
boardId: string,
cardId: string,
itemId: string,
userId: string,
text: string,
anonymous: boolean
): Promise<Board>;

insertCardGroupComment(
boardId: string,
cardId: string,
userId: string,
text: string,
anonymous: boolean
): Promise<Board>;

// UPDATE COMMENTS
updateItemComment(
boardId: string,
cardId: string,
cardItemId: string,
commentId: string,
text: string,
anonymous: boolean
): Promise<Board>;

updateCardGroupComment(
boardId: string,
cardId: string,
commentId: string,
text: string,
anonymous: boolean
): Promise<Board>;

// DELETE COMMENTS
deleteItemComment(boardId: string, commentId: string, userId: string): Promise<Board>;

deleteCardGroupComment(boardId: string, commentId: string, userId: string): Promise<Board>;
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
import { LeanDocument } from 'mongoose';
import { BoardDocument } from 'src/modules/boards/entities/board.schema';
import Board from 'src/modules/boards/entities/board.schema';

export interface DeleteCommentService {
deleteItemComment(
boardId: string,
commentId: string,
userId: string
): Promise<LeanDocument<BoardDocument>>;
export interface DeleteCommentServiceInterface {
deleteItemComment(boardId: string, commentId: string, userId: string): Promise<Board>;

deleteCardGroupComment(
boardId: string,
commentId: string,
userId: string
): Promise<LeanDocument<BoardDocument>>;
deleteCardGroupComment(boardId: string, commentId: string, userId: string): Promise<Board>;
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
import { LeanDocument } from 'mongoose';
import { BoardDocument } from 'src/modules/boards/entities/board.schema';
import Board from 'src/modules/boards/entities/board.schema';

export interface UpdateCommentService {
export interface UpdateCommentServiceInterface {
updateItemComment(
boardId: string,
cardId: string,
cardItemId: string,
commentId: string,
userId: string,
text: string,
anonymous: boolean
): Promise<LeanDocument<BoardDocument> | null>;
): Promise<Board>;

updateCardGroupComment(
boardId: string,
cardId: string,
commentId: string,
userId: string,
text: string,
anonymous: boolean
): Promise<LeanDocument<BoardDocument> | null>;
): Promise<Board>;
}
3 changes: 3 additions & 0 deletions backend/src/modules/comments/interfaces/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ export const TYPES = {
CreateCommentApplication: 'CreateCommentApplication',
DeleteCommentApplication: 'DeleteCommentApplication',
UpdateCommentApplication: 'UpdateCommentApplication'
},
repositories: {
CommentRepository: 'CommentRepository'
}
};
Loading