wip
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import {
|
||||
ARTICLE_REPOSITORY,
|
||||
type IArticleRepository,
|
||||
} from '../../../domain/repositories/article.repository.interface.js';
|
||||
import { ArticleNotFoundException } from '../../../domain/exceptions/article-not-found.exception.js';
|
||||
import { GetArticleQuery } from './get-article.query.js';
|
||||
import { ArticleDto } from '../../dto/article.dto.js';
|
||||
import { ArticleApplicationMapper } from '../../mappers/article-application.mapper.js';
|
||||
|
||||
@Injectable()
|
||||
export class GetArticleUseCase {
|
||||
constructor(
|
||||
@Inject(ARTICLE_REPOSITORY)
|
||||
private readonly articleRepository: IArticleRepository,
|
||||
) {}
|
||||
|
||||
async execute(query: GetArticleQuery): Promise<ArticleDto> {
|
||||
const article = await this.articleRepository.findById(query.id);
|
||||
|
||||
if (!article) {
|
||||
throw new ArticleNotFoundException(query.id);
|
||||
}
|
||||
|
||||
return ArticleApplicationMapper.toDto(article);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user