Skip to content

Commit

Permalink
feat(posts): apply vertical slice to posts feature (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
Javimtib92 authored Sep 24, 2024
1 parent d47a528 commit 2b6a8a6
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 23 deletions.
3 changes: 1 addition & 2 deletions app/[locale]/create-post/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
import CreatePostPage from "@/src/ui/features/posts/views/create-post-page/create-post-page";

import CreatePostPage from "@/src/posts/presentation/pages/create-post/create-post";
export default CreatePostPage;
2 changes: 1 addition & 1 deletion app/[locale]/posts/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import PostsPage from "@/src/ui/features/posts/views/posts-page/posts-page";
import PostsPage from "@/src/posts/presentation/pages/posts/posts";

export default PostsPage;
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Expose } from "class-transformer";
import { Post } from "@/src/core/posts/domain/models/post";
import type { DataModel } from "@/src/common/interfaces/data-model";
import { Post } from "@/src/posts/domain/models/post";

export class PostDataModel implements DataModel<Post> {
export class PostDTO implements DataModel<Post> {
@Expose()
id!: string;
@Expose()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { IPostsRepository } from "../../domain/interfaces/posts-repository";
import { inject, injectable } from "inversify";
import { TYPES } from "@/src/core/app/ioc/__generated__/types";
import type { Post } from "@/src/core/posts/domain/models/post";
import type { Post } from "@/src/posts/domain/models/post";
import type { RestService } from "@/src/core/app/data/services/rest-service";
import { PostDataModel } from "@/src/core/posts/data/models/post-data-model";
import { PostDTO } from "@/src/posts/data/dtos/post";
import { fromJson, fromJsonPage } from "@/src/common/utils/class-transformer";
import type { Page } from "@/src/core/app/domain/models/page";
import type { IocProvider } from "@/src/core/app/ioc/interfaces";
Expand All @@ -22,7 +22,7 @@ export class PostsRepository implements IPostsRepository {
userId: 1
}
});
return fromJson<PostDataModel>(PostDataModel, {
return fromJson<PostDTO>(PostDTO, {
id,
title: input.title,
body: input.body,
Expand All @@ -38,6 +38,6 @@ export class PostsRepository implements IPostsRepository {
totalCount: dataPostList.length,
page: 1
};
return fromJsonPage<PostDataModel, Post>(PostDataModel, fakePage).toDomain();
return fromJsonPage<PostDTO, Post>(PostDTO, fakePage).toDomain();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CreatePostInputModel } from "@/src/core/posts/domain/models/create-post-input-model";
import type { Post } from "@/src/core/posts/domain/models/post";
import type { CreatePostInputModel } from "@/src/posts/domain/models/create-post-input-model";
import type { Post } from "@/src/posts/domain/models/post";
import type { Page } from "@/src/core/app/domain/models/page";

export interface IPostsRepository {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { inject, injectable } from "inversify";
import type { IocProvider } from "@/src/core/app/ioc/interfaces";
import { TYPES } from "@/src/core/app/ioc/__generated__/types";
import type { IPostsRepository } from "@/src/core/posts/domain/interfaces/posts-repository";
import type { IPostsRepository } from "@/src/posts/domain/interfaces/posts-repository";

@injectable()
export class CreatePostUseCase {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { inject, injectable } from "inversify";
import type { IocProvider } from "@/src/core/app/ioc/interfaces";
import { TYPES } from "@/src/core/app/ioc/__generated__/types";
import type { IPostsRepository } from "@/src/core/posts/domain/interfaces/posts-repository";
import type { Post } from "@/src/core/posts/domain/models/post";
import type { IPostsRepository } from "@/src/posts/domain/interfaces/posts-repository";
import type { Post } from "@/src/posts/domain/models/post";

@injectable()
export class GetPostsUseCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface Props {
subtitle: string;
}

export default function PageTitle({ title, subtitle }: Props) {
export default function PostsPageTitle({ title, subtitle }: Props) {
const { mdAndUp } = useBreakpointsMatch();
return mdAndUp ? (
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { TYPES } from "@/src/core/app/ioc/__generated__/types";
import { debounce } from "lodash";
import { Switch } from "@/src/ui/components/switch/switch";
import { useAsyncState } from "@front_web_mrmilu/hooks";
import type { CreatePostUseCase } from "@/src/core/posts/domain/use-cases/create-post-use-case";
import type { CreatePostUseCase } from "@/src/posts/domain/use-cases/create-post-use-case";
import { locator } from "@/src/core/app/ioc/__generated__";
import css from "./create-post-page.css";
import css from "@/src/common/presentation/styles/wrapper.css";

export default function CreatePostPage() {
const [postNumber, setPostNumber] = useState(1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import css from "../../../users/views/users-page/users-page.css";
import css from "@/src/common/presentation/styles/wrapper.css";
import { SimpleCard } from "@/src/ui/components/simple-card/simple-card";
import { locator } from "@/src/core/app/ioc/__generated__";
import type { IocProvider } from "@/src/core/app/ioc/interfaces";
import type { GetPostsUseCase } from "@/src/core/posts/domain/use-cases/get-posts-use-case";
import type { GetPostsUseCase } from "@/src/posts/domain/use-cases/get-posts-use-case";
import { TYPES } from "@/src/core/app/ioc/__generated__/types";
import PageTitle from "@/src/ui/features/posts/views/posts-page/components/page-title";
import type { Post } from "@/src/core/posts/domain/models/post";
import type { Post } from "@/src/posts/domain/models/post";
import { notFound } from "next/navigation";
import { getTranslations } from "next-intl/server";
import PostsPageTitle from "@/src/posts/presentation/components/posts-page-title";

export default async function PostsPage() {
let posts: Array<Post> = [];
Expand All @@ -21,7 +21,7 @@ export default async function PostsPage() {

return (
<div className={css.wrapper}>
<PageTitle title={t("title")} subtitle={t("subtitle")} />
<PostsPageTitle title={t("title")} subtitle={t("subtitle")} />
{posts.map((post, idx) => (
<SimpleCard key={`${post.id}_${idx}`} title={post.title} subtitle={post.body} />
))}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/base-layout/base-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const BaseLayout = ({ children }: PropsWithChildren) => {
<ListElement href="/" label="home" />
<ListElement href="/users_provider" label="users (with zustand provider)" />
<ListElement href="/users" label="users" />
<ListElement href="/create_post" label="create post" />
<ListElement href="/create-post" label="create post" />
<ListElement href="/posts" label="list post" />
</ul>
<Suspense>
Expand Down

0 comments on commit 2b6a8a6

Please sign in to comment.