30 lines
1.1 KiB
TypeScript
30 lines
1.1 KiB
TypeScript
import { Article } from "article/domain/articleEntity";
|
|
import { ArticleStore } from "article/domain/articleStore";
|
|
|
|
|
|
class FetchArticleUseCase {
|
|
/* ------------------------------ Dependencies ------------------------------ */
|
|
_fetchArticleCallback: (id: string) => Promise<Article | null>;
|
|
_store: ArticleStore;
|
|
/* -------------------------------------------------------------------------- */
|
|
constructor(
|
|
fetchArticle: (id: string) => Promise<Article | null>,
|
|
store: ArticleStore,
|
|
) {
|
|
this._fetchArticleCallback = fetchArticle;
|
|
this._store = store;
|
|
}
|
|
/* ----------------------------- Implementation ----------------------------- */
|
|
async call(id: string): Promise<Article | null> {
|
|
return this._fetchArticleCallback(id).then((article) => {
|
|
if (article != null) {
|
|
this._store.setArticle(article);
|
|
}
|
|
return article;
|
|
})
|
|
}
|
|
/* -------------------------------------------------------------------------- */
|
|
}
|
|
|
|
export { FetchArticleUseCase };
|