Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/hexagonal pattern poc v2 #235

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c165af7
feat: add ApiClient class with dependency injection
timothyrusso Aug 20, 2024
4a261bb
feat: add new Ideation Service
timothyrusso Aug 21, 2024
480996a
feat: tsyring configuration
timothyrusso Aug 21, 2024
ee52014
feat: tsyring configuration
timothyrusso Aug 21, 2024
c1e39ff
feat: tsyring configuration
timothyrusso Aug 21, 2024
673017d
feat: tsyring configuration
timothyrusso Aug 21, 2024
b882198
feat: add ideation use cases
timothyrusso Aug 22, 2024
fe1455f
feat: add injection utils
timothyrusso Aug 22, 2024
e148ba1
Merge remote-tracking branch 'origin/dev' into feature/exagonal-patte…
timothyrusso Aug 22, 2024
775d568
Merge branch 'feature/exagonal-pattern-poc' of github.com:chingu-x/ch…
Dan-Y-Ko Sep 2, 2024
77393e3
rest api module implementation
Dan-Y-Ko Sep 2, 2024
e8800cf
add dtos
Dan-Y-Ko Sep 3, 2024
75aab33
add ideation api repository implementation
Dan-Y-Ko Sep 3, 2024
de50783
refactor usecases
Dan-Y-Ko Sep 3, 2024
7065ad1
refactor add ideation in service
Dan-Y-Ko Sep 3, 2024
16865ee
test
Dan-Y-Ko Sep 3, 2024
83dc75e
move dtos
Dan-Y-Ko Sep 3, 2024
b5dcce9
refactor folder structure
Dan-Y-Ko Sep 4, 2024
effa6d9
usecase implement port
Dan-Y-Ko Sep 4, 2024
2a72351
test
Dan-Y-Ko Sep 4, 2024
6b789c3
test
Dan-Y-Ko Sep 4, 2024
98f341b
why is this so annoying
Dan-Y-Ko Sep 4, 2024
5972f54
update filename casing
Dan-Y-Ko Sep 4, 2024
99ae94b
not so optimal solution to enforcing cache and token
Dan-Y-Ko Sep 4, 2024
1c6d399
refactor server action as a functon to act as a wrapper calling a met…
Dan-Y-Ko Oct 1, 2024
5109f3d
rename ideation service file
Dan-Y-Ko Oct 1, 2024
f9a2a4c
move types
Dan-Y-Ko Oct 1, 2024
a857f86
fix build errors
Dan-Y-Ko Oct 1, 2024
5641cfb
move class instantiation out of the function
Dan-Y-Ko Oct 1, 2024
2ab7364
refactor server action and adapter
Dan-Y-Ko Oct 1, 2024
8aa077f
refactor types
Dan-Y-Ko Oct 1, 2024
23f220a
remove unnecessary interface
Dan-Y-Ko Oct 1, 2024
eaa93a9
fix build error
Dan-Y-Ko Oct 1, 2024
2f622a6
Merge branch 'dev' of github.com:chingu-x/chingu-dashboard into refac…
Dan-Y-Ko Oct 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
"react-hook-form": "^7.46.2",
"react-redux": "^8.1.2",
"redux-persist": "^6.0.0",
"reflect-metadata": "^0.2.2",
"tailwind-merge": "^2.0.0",
"tsyringe": "^4.8.0",
"zod": "^3.22.2"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion src/app/(auth)/authService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"use server";

import { cookies } from "next/headers";
import { type AsyncActionResponse, handleAsync } from "@/utils/handleAsync";
import { handleAsync } from "@/utils/handleAsync";
import { type AsyncActionResponse } from "@/utils/handleAsync";
import { getAccessToken, getRefreshToken } from "@/utils/getCookie";
import { POST, UNAUTHPOST } from "@/utils/requests";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { fetchSprints } from "@/myVoyage/sprints/components/RedirectToCurrentSpr
import { fetchMeeting } from "@/myVoyage/sprints/components/SprintWrapper";
import type { User } from "@/store/features/user/userSlice";
import type { Sprint, Voyage } from "@/store/features/sprint/sprintSlice";
import type { AppError } from "@/types/types";
import { type AppError } from "@/types/types";
import { type AsyncActionResponse } from "@/utils/handleAsync";
import { getCurrentSprint } from "@/utils/getCurrentSprint";
import { getCurrentVoyageData } from "@/utils/getCurrentVoyageData";
import { fetchResources } from "@/app/(main)/my-voyage/[teamId]/voyage-resources/components/ResourcesComponentWrapper";
Expand All @@ -13,7 +14,6 @@ import { type FeaturesList } from "@/store/features/features/featuresSlice";
import { type IdeationData } from "@/store/features/ideation/ideationSlice";
import { type TechStackData } from "@/store/features/techStack/techStackSlice";
import { type ResourceData } from "@/store/features/resources/resourcesSlice";
import type { AsyncActionResponse } from "@/utils/handleAsync";
import { ErrorType } from "@/utils/error";

interface GetDashboardDataResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import ErrorComponent from "@/components/Error";
import { type TeamDirectory } from "@/store/features/directory/directorySlice";

import { getAccessToken } from "@/utils/getCookie";
import { type AsyncActionResponse, handleAsync } from "@/utils/handleAsync";
import { handleAsync } from "@/utils/handleAsync";
import { type AsyncActionResponse } from "@/utils/handleAsync";
import { GET } from "@/utils/requests";
import { CacheTag } from "@/utils/cacheTag";
import { type User } from "@/store/features/user/userSlice";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import { revalidateTag } from "next/cache";
import { getAccessToken } from "@/utils/getCookie";
import { type AsyncActionResponse, handleAsync } from "@/utils/handleAsync";
import { handleAsync } from "@/utils/handleAsync";
import { type AsyncActionResponse } from "@/utils/handleAsync";
import { PATCH } from "@/utils/requests";
import { CacheTag } from "@/utils/cacheTag";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import { getUser } from "@/utils/getUser";
import { getAccessToken } from "@/utils/getCookie";
import { GET } from "@/utils/requests";
import { CacheTag } from "@/utils/cacheTag";
import { type AsyncActionResponse, handleAsync } from "@/utils/handleAsync";
import { handleAsync } from "@/utils/handleAsync";
import { type AsyncActionResponse } from "@/utils/handleAsync";
import { ErrorType } from "@/utils/error";

function transformData(features: Features[]): FeaturesList[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { revalidateTag } from "next/cache";
import { type Features } from "@/store/features/features/featuresSlice";
import { CacheTag } from "@/utils/cacheTag";
import { getAccessToken } from "@/utils/getCookie";
import { type AsyncActionResponse, handleAsync } from "@/utils/handleAsync";
import { handleAsync } from "@/utils/handleAsync";
import { type AsyncActionResponse } from "@/utils/handleAsync";
import { DELETE, PATCH, POST } from "@/utils/requests";

interface SaveOrderProps {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { type IdeationClientPort } from "@/modules/ideation/ports/primary/ideationClientPort";
import { type AddIdeationResponseDto } from "@/modules/ideation/application/dtos/response.dto";
import { AddIdeationUseCase } from "@/modules/ideation/application/usecases/addIdeationUseCase";
import { NextJsRestApiAdapter } from "@/modules/restApi/adapters/secondary/nextJsRestApiAdapter";
import { IdeationApiAdapter } from "@/modules/ideation/adapters/secondary/ideationApiAdapter";
import { type AddIdeationRequestDto } from "@/modules/ideation/application/dtos/request.dto";

const nextJsRestApiAdapter = new NextJsRestApiAdapter(
process.env.NEXT_PUBLIC_API_URL!,
);
const ideationApiPort = new IdeationApiAdapter(nextJsRestApiAdapter);

export class IdeationClientAdapter implements IdeationClientPort {
async addIdeation({
teamId,
title,
description,
vision,
token,
cache,
}: Required<AddIdeationRequestDto>): Promise<AddIdeationResponseDto> {
const addIdeationUseCase = new AddIdeationUseCase(ideationApiPort);

// refactor this later to not expect a function
return await addIdeationUseCase.execute({
teamId,
title,
description,
vision,
cache,
token,
});
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
"use server";

import { revalidateTag } from "next/cache";
import { IdeationClientAdapter } from "./ideationClientAdapter";
import { getAccessToken } from "@/utils/getCookie";
import { DELETE, PATCH, POST } from "@/utils/requests";
import { type AsyncActionResponse, handleAsync } from "@/utils/handleAsync";
import { handleAsync } from "@/utils/handleAsync";
import { type AsyncActionResponse } from "@/utils/handleAsync";
import { CacheTag } from "@/utils/cacheTag";
import { type AddIdeationResponseDto } from "@/modules/ideation/application/dtos/response.dto";
import { type AddIdeationRequestDto } from "@/modules/ideation/application/dtos/request.dto";

interface IdeationProps {
teamId: number;
Expand Down Expand Up @@ -53,21 +57,27 @@ export interface IdeationVoteResponse extends IdeationResponse {
projectIdeaId: number;
}

const addIdeationClientAdapter = new IdeationClientAdapter();

export async function addIdeation({
teamId,
title,
description,
vision,
}: AddIdeationProps): Promise<AsyncActionResponse<AddIdeationResponse>> {
}: AddIdeationRequestDto): Promise<
AsyncActionResponse<AddIdeationResponseDto>
> {
const token = getAccessToken();

const addIdeationAsync = () =>
POST<AddIdeationBody, AddIdeationResponse>(
`api/v1/voyages/teams/${teamId}/ideations`,
addIdeationClientAdapter.addIdeation({
teamId,
title,
description,
vision,
token,
"default",
{ title, description, vision },
);
cache: "default",
});

const [res, error] = await handleAsync(addIdeationAsync);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import FinalizedIdeationCard from "./FinalizedIdeationCard";
import IdeationContainer from "./IdeationContainer";
import IdeationProvider from "./IdeationProvider";
import VoteCard from "./VoteCard";
import { type FetchIdeationsProps } from "@/app/(main)/my-voyage/[teamId]/ideation/ideationService";
import { type FetchIdeationsProps } from "@/app/(main)/my-voyage/[teamId]/ideation/adapters/ideationSA";
import Banner from "@/components/banner/Banner";
import VoyagePageBannerContainer from "@/components/banner/VoyagePageBannerContainer";
import ErrorComponent from "@/components/Error";
Expand All @@ -15,7 +15,8 @@ import { CacheTag } from "@/utils/cacheTag";
import { getAccessToken } from "@/utils/getCookie";
import { getCurrentVoyageData } from "@/utils/getCurrentVoyageData";
import { getUser } from "@/utils/getUser";
import { handleAsync, type AsyncActionResponse } from "@/utils/handleAsync";
import { handleAsync } from "@/utils/handleAsync";
import { type AsyncActionResponse } from "@/utils/handleAsync";
import { GET } from "@/utils/requests";
import routePaths from "@/utils/routePaths";
import { ErrorType } from "@/utils/error";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
type EditIdeationProps,
addIdeation,
deleteIdeation,
} from "@/app/(main)/my-voyage/[teamId]/ideation/ideationService";
} from "@/app/(main)/my-voyage/[teamId]/ideation/adapters/ideationSA";
import useServerAction from "@/hooks/useServerAction";
import { persistor } from "@/store/store";
import { onOpenModal } from "@/store/features/modal/modalSlice";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import useServerAction from "@/hooks/useServerAction";
import {
addIdeationVote,
removeIdeationVote,
} from "@/app/(main)/my-voyage/[teamId]/ideation/ideationService";
} from "@/app/(main)/my-voyage/[teamId]/ideation/adapters/ideationSA";
import { onOpenModal } from "@/store/features/modal/modalSlice";
import AvatarGroup from "@/components/avatar/AvatarGroup";
import Avatar from "@/components/avatar/Avatar";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useParams, useRouter } from "next/navigation";
import { type FinalizedIdeation } from "./FinalizeIdeationList";
import useServerAction from "@/hooks/useServerAction";
import Button from "@/components/Button";
import { finalizeIdeation } from "@/myVoyage/ideation/ideationService";
import { finalizeIdeation } from "@/myVoyage/ideation/adapters/ideationSA";
import routePaths from "@/utils/routePaths";
import { useAppDispatch } from "@/store/hooks";
import { onOpenModal } from "@/store/features/modal/modalSlice";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import { getUser } from "@/utils/getUser";
import { getCurrentSprint } from "@/utils/getCurrentSprint";
import { GET } from "@/utils/requests";
import { CacheTag } from "@/utils/cacheTag";
import { type AsyncActionResponse, handleAsync } from "@/utils/handleAsync";
import { handleAsync } from "@/utils/handleAsync";
import { type AsyncActionResponse } from "@/utils/handleAsync";
import { type Sprint } from "@/store/features/sprint/sprintSlice";
import { getCurrentVoyageData } from "@/utils/getCurrentVoyageData";
import routePaths from "@/utils/routePaths";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import {
} from "@/store/features/sprint/sprintSlice";

import { getCurrentSprint } from "@/utils/getCurrentSprint";
import { type AsyncActionResponse, handleAsync } from "@/utils/handleAsync";
import { handleAsync } from "@/utils/handleAsync";
import { type AsyncActionResponse } from "@/utils/handleAsync";
import { GET } from "@/utils/requests";
import { getAccessToken } from "@/utils/getCookie";
import { getUser } from "@/utils/getUser";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { getAccessToken } from "@/utils/getCookie";
import { getUser } from "@/utils/getUser";
import { GET } from "@/utils/requests";
import { CacheTag } from "@/utils/cacheTag";
import { type AsyncActionResponse, handleAsync } from "@/utils/handleAsync";
import { handleAsync } from "@/utils/handleAsync";
import { type AsyncActionResponse } from "@/utils/handleAsync";
import { getCurrentVoyageData } from "@/utils/getCurrentVoyageData";
import routePaths from "@/utils/routePaths";
import { Forms, UserRole } from "@/utils/form/formsEnums";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import { revalidateTag } from "next/cache";
import { getAccessToken } from "@/utils/getCookie";
import { DELETE, PATCH, POST } from "@/utils/requests";
import { type AsyncActionResponse, handleAsync } from "@/utils/handleAsync";
import { handleAsync } from "@/utils/handleAsync";
import { type AsyncActionResponse } from "@/utils/handleAsync";
import { CacheTag } from "@/utils/cacheTag";
import { getSprintCache } from "@/utils/getSprintCache";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { revalidateTag } from "next/cache";
import type { Category } from "./finalize/types";
import { CacheTag } from "@/utils/cacheTag";
import { getAccessToken } from "@/utils/getCookie";
import { type AsyncActionResponse, handleAsync } from "@/utils/handleAsync";
import { handleAsync } from "@/utils/handleAsync";
import { type AsyncActionResponse } from "@/utils/handleAsync";
import { DELETE, PATCH, POST } from "@/utils/requests";
import { type TechStackItem } from "@/store/features/techStack/techStackSlice";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import { revalidateTag } from "next/cache";
import { getAccessToken } from "@/utils/getCookie";
import { POST, DELETE } from "@/utils/requests";
import { type AsyncActionResponse, handleAsync } from "@/utils/handleAsync";
import { handleAsync } from "@/utils/handleAsync";
import { type AsyncActionResponse } from "@/utils/handleAsync";
import { CacheTag } from "@/utils/cacheTag";

interface ResourceProps {
Expand Down
2 changes: 2 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { Inter } from "next/font/google";
import StoreProvider from "@/components/providers/StoreProvider";
import ThemeProvider from "@/components/providers/ThemeProvider";
import ModalProvider from "@/components/providers/ModalProvider";
import "reflect-metadata";
import "@/di/config";

export const metadata: Metadata = {
title: "Chingu Dashboard",
Expand Down
17 changes: 17 additions & 0 deletions src/di/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { container } from "tsyringe";

import { TYPES } from "./types";
import { type IdeationApiPort } from "@/modules/ideation/ports/secondary/ideationApiPort";
import { IdeationApiAdapter } from "@/modules/ideation/adapters/secondary/ideationApiAdapter";
import { type RestApiPort } from "@/modules/restApi/ports/secondary/restApiPort";
import { NextJsRestApiAdapter } from "@/modules/restApi/adapters/secondary/nextJsRestApiAdapter";

container.register<IdeationApiPort>(TYPES.IdeationApiPort, {
useClass: IdeationApiAdapter,
});

container.register<RestApiPort>(TYPES.RestApiPort, {
useValue: new NextJsRestApiAdapter(process.env.NEXT_PUBLIC_API_URL!),
});

export default container;
30 changes: 30 additions & 0 deletions src/di/injectables.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { container } from "tsyringe";
import { TYPES } from "./types";
import type { AddIdeationUseCase } from "@/modules/ideation/application/usecases/addIdeationUseCase";
import type { AddIdeationVoteUseCase } from "@/modules/ideation/application/usecases/addIdeationVoteUseCase";
import type { DeleteIdeationUseCase } from "@/modules/ideation/application/usecases/deleteIdeationUseCase";
import type { EditIdeationUseCase } from "@/modules/ideation/application/usecases/editIdeationUseCase";
import type { FinalizeIdeationUseCase } from "@/modules/ideation/application/usecases/finalizeIdeationUseCase";
import type { RemoveIdeationVoteUseCase } from "@/modules/ideation/application/usecases/removeIdeationVoteUseCase";

export const injectables = {
/* Ideation */
addIdeationUseCase: container.resolve<AddIdeationUseCase>(
TYPES.AddIdeationUseCase,
),
addIdeationVoteUseCase: container.resolve<AddIdeationVoteUseCase>(
TYPES.AddIdeationVoteUseCase,
),
deleteIdeationUseCase: container.resolve<DeleteIdeationUseCase>(
TYPES.DeleteIdeationUseCase,
),
editIdeationUseCase: container.resolve<EditIdeationUseCase>(
TYPES.EditIdeationUseCase,
),
finalizeIdeationUseCase: container.resolve<FinalizeIdeationUseCase>(
TYPES.FinalizeIdeationUseCase,
),
removeIdeationVoteUseCase: container.resolve<RemoveIdeationVoteUseCase>(
TYPES.RemoveIdeationVoteUseCase,
),
} as const;
9 changes: 9 additions & 0 deletions src/di/resolveInjection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import "reflect-metadata";

import { injectables } from "./injectables";

const resolveInjection = () => ({
...injectables,
});

export default resolveInjection;
10 changes: 10 additions & 0 deletions src/di/resolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { InjectionToken } from "tsyringe";

import container from "./config";

export const resolve =
<T>(token: InjectionToken<T>) =>
// eslint-disable-next-line indent
() =>
// eslint-disable-next-line indent
container.resolve(token);
18 changes: 18 additions & 0 deletions src/di/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export const TYPES = {
/* Ports */
RestApiPort: Symbol.for("RestApiPort"),
IdeationApiPort: Symbol.for("IdeationApiPort"),
IdeationClientPort: Symbol.for("IdeationClientPort"),

/* Adapters */
// NextJsRestApiAdapter: Symbol.for("NextJsRestApiAdapter"),
IdeationApiAdapter: Symbol.for("IdeationApiAdapter"),

/* UseCases */
AddIdeationUseCase: Symbol.for("AddIdeationUseCase"),
AddIdeationVoteUseCase: Symbol.for("AddIdeationVoteUseCase"),
DeleteIdeationUseCase: Symbol.for("DeleteIdeationUseCase"),
EditIdeationUseCase: Symbol.for("EditIdeationUseCase"),
FinalizeIdeationUseCase: Symbol.for("FinalizeIdeationUseCase"),
RemoveIdeationVoteUseCase: Symbol.for("RemoveIdeationVoteUseCase"),
};
18 changes: 18 additions & 0 deletions src/hooks/useInjection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import "reflect-metadata";

import { useMemo } from "react";

import { injectables } from "@/di/injectables";

const useInjection = () => {
const injection = useMemo(
() => ({
...injectables,
}),
[],
);

return injection;
};

export default useInjection;
Loading
Loading