From 2b6a8a6bdd208531e562d0fa561b73814b4a4930 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Mu=C3=B1oz=20Tous?= Date: Tue, 24 Sep 2024 10:20:43 +0200 Subject: [PATCH] feat(posts): apply vertical slice to posts feature (#23) --- app/[locale]/create-post/page.tsx | 3 +-- app/[locale]/posts/page.tsx | 2 +- .../presentation/styles/wrapper.css.ts} | 0 .../post-data-model.ts => posts/data/dtos/post.ts} | 4 ++-- .../posts/data/repositories/posts-repository.ts | 8 ++++---- .../posts/domain/interfaces/posts-repository.ts | 4 ++-- .../posts/domain/models/create-post-input-model.ts | 0 src/{core => }/posts/domain/models/post.ts | 0 .../posts/domain/use-cases/create-post-use-case.ts | 2 +- .../posts/domain/use-cases/get-posts-use-case.ts | 4 ++-- .../presentation/components/posts-page-title.tsx} | 2 +- .../presentation/pages/create-post/create-post.tsx} | 4 ++-- .../presentation/pages/posts/posts.tsx} | 10 +++++----- src/ui/components/base-layout/base-layout.tsx | 2 +- 14 files changed, 22 insertions(+), 23 deletions(-) rename src/{ui/features/posts/views/create-post-page/create-post-page.css.ts => common/presentation/styles/wrapper.css.ts} (100%) rename src/{core/posts/data/models/post-data-model.ts => posts/data/dtos/post.ts} (75%) rename src/{core => }/posts/data/repositories/posts-repository.ts (83%) rename src/{core => }/posts/domain/interfaces/posts-repository.ts (54%) rename src/{core => }/posts/domain/models/create-post-input-model.ts (100%) rename src/{core => }/posts/domain/models/post.ts (100%) rename src/{core => }/posts/domain/use-cases/create-post-use-case.ts (86%) rename src/{core => }/posts/domain/use-cases/get-posts-use-case.ts (76%) rename src/{ui/features/posts/views/posts-page/components/page-title.tsx => posts/presentation/components/posts-page-title.tsx} (81%) rename src/{ui/features/posts/views/create-post-page/create-post-page.tsx => posts/presentation/pages/create-post/create-post.tsx} (94%) rename src/{ui/features/posts/views/posts-page/posts-page.tsx => posts/presentation/pages/posts/posts.tsx} (71%) diff --git a/app/[locale]/create-post/page.tsx b/app/[locale]/create-post/page.tsx index e294bed..b43e7f6 100644 --- a/app/[locale]/create-post/page.tsx +++ b/app/[locale]/create-post/page.tsx @@ -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; diff --git a/app/[locale]/posts/page.tsx b/app/[locale]/posts/page.tsx index 443a96b..a5aadc3 100644 --- a/app/[locale]/posts/page.tsx +++ b/app/[locale]/posts/page.tsx @@ -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; diff --git a/src/ui/features/posts/views/create-post-page/create-post-page.css.ts b/src/common/presentation/styles/wrapper.css.ts similarity index 100% rename from src/ui/features/posts/views/create-post-page/create-post-page.css.ts rename to src/common/presentation/styles/wrapper.css.ts diff --git a/src/core/posts/data/models/post-data-model.ts b/src/posts/data/dtos/post.ts similarity index 75% rename from src/core/posts/data/models/post-data-model.ts rename to src/posts/data/dtos/post.ts index 1600eab..b26afc6 100644 --- a/src/core/posts/data/models/post-data-model.ts +++ b/src/posts/data/dtos/post.ts @@ -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 { +export class PostDTO implements DataModel { @Expose() id!: string; @Expose() diff --git a/src/core/posts/data/repositories/posts-repository.ts b/src/posts/data/repositories/posts-repository.ts similarity index 83% rename from src/core/posts/data/repositories/posts-repository.ts rename to src/posts/data/repositories/posts-repository.ts index 18c0c8a..1f97bcb 100644 --- a/src/core/posts/data/repositories/posts-repository.ts +++ b/src/posts/data/repositories/posts-repository.ts @@ -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"; @@ -22,7 +22,7 @@ export class PostsRepository implements IPostsRepository { userId: 1 } }); - return fromJson(PostDataModel, { + return fromJson(PostDTO, { id, title: input.title, body: input.body, @@ -38,6 +38,6 @@ export class PostsRepository implements IPostsRepository { totalCount: dataPostList.length, page: 1 }; - return fromJsonPage(PostDataModel, fakePage).toDomain(); + return fromJsonPage(PostDTO, fakePage).toDomain(); } } diff --git a/src/core/posts/domain/interfaces/posts-repository.ts b/src/posts/domain/interfaces/posts-repository.ts similarity index 54% rename from src/core/posts/domain/interfaces/posts-repository.ts rename to src/posts/domain/interfaces/posts-repository.ts index 4085985..a2b6280 100644 --- a/src/core/posts/domain/interfaces/posts-repository.ts +++ b/src/posts/domain/interfaces/posts-repository.ts @@ -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 { diff --git a/src/core/posts/domain/models/create-post-input-model.ts b/src/posts/domain/models/create-post-input-model.ts similarity index 100% rename from src/core/posts/domain/models/create-post-input-model.ts rename to src/posts/domain/models/create-post-input-model.ts diff --git a/src/core/posts/domain/models/post.ts b/src/posts/domain/models/post.ts similarity index 100% rename from src/core/posts/domain/models/post.ts rename to src/posts/domain/models/post.ts diff --git a/src/core/posts/domain/use-cases/create-post-use-case.ts b/src/posts/domain/use-cases/create-post-use-case.ts similarity index 86% rename from src/core/posts/domain/use-cases/create-post-use-case.ts rename to src/posts/domain/use-cases/create-post-use-case.ts index abe0671..1950243 100644 --- a/src/core/posts/domain/use-cases/create-post-use-case.ts +++ b/src/posts/domain/use-cases/create-post-use-case.ts @@ -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 { diff --git a/src/core/posts/domain/use-cases/get-posts-use-case.ts b/src/posts/domain/use-cases/get-posts-use-case.ts similarity index 76% rename from src/core/posts/domain/use-cases/get-posts-use-case.ts rename to src/posts/domain/use-cases/get-posts-use-case.ts index 096ff03..7f5f2ab 100644 --- a/src/core/posts/domain/use-cases/get-posts-use-case.ts +++ b/src/posts/domain/use-cases/get-posts-use-case.ts @@ -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 { diff --git a/src/ui/features/posts/views/posts-page/components/page-title.tsx b/src/posts/presentation/components/posts-page-title.tsx similarity index 81% rename from src/ui/features/posts/views/posts-page/components/page-title.tsx rename to src/posts/presentation/components/posts-page-title.tsx index f5d6380..41cdf65 100644 --- a/src/ui/features/posts/views/posts-page/components/page-title.tsx +++ b/src/posts/presentation/components/posts-page-title.tsx @@ -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 ? (
diff --git a/src/ui/features/posts/views/create-post-page/create-post-page.tsx b/src/posts/presentation/pages/create-post/create-post.tsx similarity index 94% rename from src/ui/features/posts/views/create-post-page/create-post-page.tsx rename to src/posts/presentation/pages/create-post/create-post.tsx index 18252ac..4a88fa0 100644 --- a/src/ui/features/posts/views/create-post-page/create-post-page.tsx +++ b/src/posts/presentation/pages/create-post/create-post.tsx @@ -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); diff --git a/src/ui/features/posts/views/posts-page/posts-page.tsx b/src/posts/presentation/pages/posts/posts.tsx similarity index 71% rename from src/ui/features/posts/views/posts-page/posts-page.tsx rename to src/posts/presentation/pages/posts/posts.tsx index d663c50..3c5120c 100644 --- a/src/ui/features/posts/views/posts-page/posts-page.tsx +++ b/src/posts/presentation/pages/posts/posts.tsx @@ -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 = []; @@ -21,7 +21,7 @@ export default async function PostsPage() { return (
- + {posts.map((post, idx) => ( ))} diff --git a/src/ui/components/base-layout/base-layout.tsx b/src/ui/components/base-layout/base-layout.tsx index c80adcf..8642a43 100644 --- a/src/ui/components/base-layout/base-layout.tsx +++ b/src/ui/components/base-layout/base-layout.tsx @@ -20,7 +20,7 @@ export const BaseLayout = ({ children }: PropsWithChildren) => { - +