-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Posts and comments cleanup read and write operations | triggered by w…
…orks well
- Loading branch information
Showing
33 changed files
with
860 additions
and
320 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 31 additions & 9 deletions
40
server/src/application/comment/create/create-comment.usecase.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,39 @@ | ||
import { BaseUseCase, UseCase } from '@application/shared'; | ||
import { CreateCommentRequest } from './create-comment.request'; | ||
import { CommentDetailsResponseDto } from '@contracts/dtos/comments'; | ||
@UseCase() | ||
class CreateCommentUseCase extends BaseUseCase<CreateCommentRequest,CommentDetailsResponseDto> { | ||
import { CommentResponseDto } from '@contracts/dtos/comments'; | ||
import { Comment, CommentRepository } from '@domain/entities'; | ||
import { Long } from 'typeorm'; | ||
import { Logger } from '@domain/shared'; | ||
|
||
constructor() { | ||
super(); | ||
@UseCase() | ||
class CreateCommentUseCase extends BaseUseCase< | ||
CreateCommentRequest, | ||
CommentResponseDto | ||
> { | ||
private readonly _commentRepository: CommentRepository; | ||
constructor(commentRepository: CommentRepository) { | ||
super(); | ||
this._commentRepository = commentRepository; | ||
} | ||
|
||
public async performOperation({ }: CreateCommentRequest): Promise<CommentDetailsResponseDto> { | ||
throw new Error('Method not implemented.'); | ||
public async performOperation( | ||
request: CreateCommentRequest, | ||
): Promise<CommentResponseDto> { | ||
const comment: Comment = Comment.create( | ||
null, | ||
request.postId, | ||
null, | ||
request.triggeredBy.toString(), | ||
null, | ||
request.content, | ||
new Date(), | ||
new Date(), | ||
null, | ||
); | ||
|
||
const createdComment = await this._commentRepository.create(comment); | ||
return CommentResponseDto.fromEntity(createdComment); | ||
} | ||
} | ||
|
||
export { CreateCommentUseCase }; | ||
export { CreateCommentUseCase }; |
13 changes: 6 additions & 7 deletions
13
server/src/application/comment/delete/delete-comment.usecase.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,15 @@ | ||
import { BaseUseCase, UseCase } from '@application/shared'; | ||
import { DeleteCommentRequest } from './delete-comment.request'; | ||
|
||
@UseCase() | ||
class DeleteCommentUseCase extends BaseUseCase<DeleteCommentRequest,bool> { | ||
|
||
@UseCase() | ||
class DeleteCommentUseCase extends BaseUseCase<DeleteCommentRequest, boolean> { | ||
constructor() { | ||
super(); | ||
super(); | ||
} | ||
|
||
public async performOperation({ }: DeleteCommentRequest): Promise<bool> { | ||
throw new Error('Method not implemented.'); | ||
public async performOperation({}: DeleteCommentRequest): Promise<boolean> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
} | ||
|
||
export { DeleteCommentUseCase }; | ||
export { DeleteCommentUseCase }; |
17 changes: 10 additions & 7 deletions
17
server/src/application/comment/edit/edit-comment.usecase.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
import { BaseUseCase, UseCase } from '@application/shared'; | ||
import { EditCommentRequest } from './edit-comment.request'; | ||
|
||
@UseCase() | ||
class EditCommentUseCase extends BaseUseCase<EditCommentRequest,CommentDetailsResponseDto> { | ||
import { CommentDetailsResponseDto } from '@contracts/dtos/comments'; | ||
|
||
@UseCase() | ||
class EditCommentUseCase extends BaseUseCase< | ||
EditCommentRequest, | ||
CommentDetailsResponseDto | ||
> { | ||
constructor() { | ||
super(); | ||
super(); | ||
} | ||
|
||
public async performOperation({ }: EditCommentRequest): Promise<CommentDetailsResponseDto> { | ||
throw new Error('Method not implemented.'); | ||
public async performOperation({}: EditCommentRequest): Promise<CommentDetailsResponseDto> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
} | ||
|
||
export { EditCommentUseCase }; | ||
export { EditCommentUseCase }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 23 additions & 9 deletions
32
server/src/application/comment/get-by-post-id/get-by-post-id-comment.usecase.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,30 @@ | ||
import { BaseUseCase, UseCase } from '@application/shared'; | ||
import { GetByPostIdCommentRequest } from './get-by-post-id-comment.request'; | ||
|
||
@UseCase() | ||
class GetByPostIdCommentUseCase extends BaseUseCase<GetByPostIdCommentRequest,CommentResponseDto> { | ||
import { FindCommentsByPostIdRequest } from './get-by-post-id-comment.request'; | ||
import { CommentResponseDto } from '@contracts/dtos/comments'; | ||
import { CommentRepository } from '@domain/entities'; | ||
import { Long } from 'typeorm'; | ||
import { Logger } from '@domain/shared'; | ||
|
||
constructor() { | ||
super(); | ||
@UseCase() | ||
class FindCommentsByPostIdUseCase extends BaseUseCase< | ||
FindCommentsByPostIdRequest, | ||
CommentResponseDto[] | ||
> { | ||
private readonly _commentRepository: CommentRepository; | ||
constructor(commentRepository: CommentRepository) { | ||
super(); | ||
this._commentRepository = commentRepository; | ||
} | ||
|
||
public async performOperation({ }: GetByPostIdCommentRequest): Promise<CommentResponseDto> { | ||
throw new Error('Method not implemented.'); | ||
public async performOperation( | ||
request: FindCommentsByPostIdRequest, | ||
): Promise<CommentResponseDto[]> { | ||
Logger.info('Get comments by post id'); | ||
const comments = await this._commentRepository.findByPostId(request.postId); | ||
Logger.info('Get comments by post id', comments); | ||
|
||
return comments.map(comment => CommentResponseDto.fromEntity(comment)); | ||
} | ||
} | ||
|
||
export { GetByPostIdCommentUseCase }; | ||
export { FindCommentsByPostIdUseCase }; |
17 changes: 10 additions & 7 deletions
17
server/src/application/comment/get-detail/get-detail-comment.usecase.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
import { BaseUseCase, UseCase } from '@application/shared'; | ||
import { GetDetailCommentRequest } from './get-detail-comment.request'; | ||
|
||
@UseCase() | ||
class GetDetailCommentUseCase extends BaseUseCase<GetDetailCommentRequest,CommentDetailsResponseDto> { | ||
import { CommentDetailsResponseDto } from '@contracts/dtos/comments'; | ||
|
||
@UseCase() | ||
class GetDetailCommentUseCase extends BaseUseCase< | ||
GetDetailCommentRequest, | ||
CommentDetailsResponseDto | ||
> { | ||
constructor() { | ||
super(); | ||
super(); | ||
} | ||
|
||
public async performOperation({ }: GetDetailCommentRequest): Promise<CommentDetailsResponseDto> { | ||
throw new Error('Method not implemented.'); | ||
public async performOperation({}: GetDetailCommentRequest): Promise<CommentDetailsResponseDto> { | ||
throw new Error('Method not implemented.'); | ||
} | ||
} | ||
|
||
export { GetDetailCommentUseCase }; | ||
export { GetDetailCommentUseCase }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,27 @@ | ||
import { Comment } from '@domain/entities'; | ||
import { Nullable } from '@domain/shared/types'; | ||
import { Comment, User } from '@domain/entities'; | ||
import { Nullable } from '@domain/shared'; | ||
import { UserResponseDto } from '@dtos/users'; | ||
|
||
export class CommentResponseDto { | ||
constructor( | ||
public id: string, | ||
public content: string, | ||
public author: UserResponseDto, | ||
public authorId: string, | ||
public author: Nullable<UserResponseDto>, | ||
public postId: string, | ||
public createdAt: Nullable<Date>, | ||
public createdAt: Date, | ||
public updatedAt: Date, | ||
) {} | ||
|
||
public static fromEntity(entity: Comment): CommentResponseDto { | ||
return new CommentResponseDto( | ||
entity.id!, | ||
entity.id as string, | ||
entity.content, | ||
UserResponseDto.fromEntity(entity.author as any), | ||
entity.authorId, | ||
UserResponseDto.fromEntity(entity.author as User), | ||
entity.postId, | ||
entity.createdAt, | ||
entity.updatedAt, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import { Comment } from '@domain/entities'; | ||
|
||
interface ICommentRepository { | ||
create(comment: Comment): Promise<Comment>; | ||
findByPostId(postId: string): Promise<Comment[]>; | ||
findById(commentId: string): Promise<Comment | null>; | ||
findByAuthor(authorId: string): Promise<Comment[]>; | ||
delete(commentId: string): Promise<void>; | ||
update(comment: Comment): Promise<Comment>; | ||
abstract class CommentRepository { | ||
abstract create(comment: Comment): Promise<Comment>; | ||
abstract findByPostId(postId: string): Promise<Comment[]>; | ||
abstract findById(commentId: string): Promise<Comment | null>; | ||
abstract findByAuthor(authorId: string): Promise<Comment[]>; | ||
abstract delete(commentId: string): Promise<boolean>; | ||
abstract update(comment: Comment): Promise<Comment>; | ||
} | ||
|
||
export { ICommentRepository }; | ||
export { CommentRepository }; |
Oops, something went wrong.