Skip to content

Commit

Permalink
Implement the usecase to get blogpost with m17n
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinyaigeek committed Apr 26, 2024
1 parent c97e4f5 commit 19e9d50
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { BlogContent } from "../../model/blog/blog.entity";
import type { BlogRepository } from "../../model/blog/blog.repository";
import { M17NContents } from "../../model/m17n/m17n.entity";

export class GetBlogPostUsecase {
constructor(private blogPostRepository: BlogRepository) {}

async getBlogPost(id: string): Promise<M17NContents<BlogContent>> {
const [ja, en] = await Promise.all([
this.blogPostRepository.getBlog(id, "ja"),
this.blogPostRepository.getBlog(id, "en"),
]);

return new M17NContents(ja, en);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ export class BlogRepository {
this._path = injectedPath;
}

public async getBlog(slug: string): Promise<BlogContent> {
public async getBlog(
slug: string,
language: "ja" | "en",
): Promise<BlogContent> {
const blogPath = this._path.resolve(
process.cwd(),
"packages/applications/turbo-blog/src/articles/public",
"packages/applications/turbo-blog/src/articles/",
language === "ja" ? "public" : "en",
`${slug}.md`,
);
const blogContent = this._fs.readFileSync(blogPath, "utf-8");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Content } from "../content/content.entity";

export class M17NContents<T extends Content> {
constructor(
public ja: T,
public en: T,
public ja?: T,
public en?: T,
) {}
}

0 comments on commit 19e9d50

Please sign in to comment.