From af6ae980a9633bf3c8aeb0d073135c01392cda15 Mon Sep 17 00:00:00 2001 From: Apoorva Srinivas Appadoo Date: Wed, 25 Sep 2024 23:46:23 +0200 Subject: [PATCH] feat: move frontend bff to use RemoteGroupService --- .../src/app/remoteGroup/remote.group.controller.ts | 12 ++++++------ apps/frontend-bff/src/main.tsx | 4 ++-- libs/services/common/src/index.ts | 1 + .../common/src/lib/apis/backendBffApiService.ts | 1 + .../common/src/lib/group/groupRemoteService.ts | 3 +++ libs/ui/common/src/lib/offers/offers.tsx | 4 +++- 6 files changed, 16 insertions(+), 9 deletions(-) diff --git a/apps/backend-bff/src/app/remoteGroup/remote.group.controller.ts b/apps/backend-bff/src/app/remoteGroup/remote.group.controller.ts index 2687091..4f7ccec 100644 --- a/apps/backend-bff/src/app/remoteGroup/remote.group.controller.ts +++ b/apps/backend-bff/src/app/remoteGroup/remote.group.controller.ts @@ -3,11 +3,11 @@ import { Body, Controller, Get, HttpCode, Param, Post } from '@nestjs/common'; import { container, Group, - GroupCreateDto, + GroupCreateDto, GroupService, GroupServiceWorkflow, Table, - TableCreateDto, -} from '@spos/services/common'; + TableCreateDto, TYPES +} from "@spos/services/common"; import { ApiProperty, ApiTags } from '@nestjs/swagger'; export class TableDto implements Table { @@ -48,7 +48,7 @@ export class AnnotatedGroupCreateDto implements GroupCreateDto { export class RemoteGroupController { @Get() async getGroups(): Promise { - return container.get(GroupServiceWorkflow).getGroups(); + return container.get(TYPES.GroupService).getGroups(); } @Get(':id') @@ -56,7 +56,7 @@ export class RemoteGroupController { @Param('id') id: string ): Promise { - return container.get(GroupServiceWorkflow).getGroup(id); + return container.get(TYPES.GroupService).getGroup(id); } @Post() @@ -64,6 +64,6 @@ export class RemoteGroupController { async addGroup( @Body() body: AnnotatedGroupCreateDto ): Promise { - return container.get(GroupServiceWorkflow).addGroup(body); + return container.get(TYPES.GroupService).addGroup(body); } } diff --git a/apps/frontend-bff/src/main.tsx b/apps/frontend-bff/src/main.tsx index 25eae37..e6bb2b0 100644 --- a/apps/frontend-bff/src/main.tsx +++ b/apps/frontend-bff/src/main.tsx @@ -6,7 +6,7 @@ import { BrowserRouter } from "react-router-dom"; import App from "./app/app"; import { CssBaseline } from "@mui/material"; import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; -import { container } from "@spos/services/common"; +import { bffContainer, container } from "@spos/services/common"; import { ContainerContext } from "@spos/ui/common"; const root = ReactDOM.createRoot( @@ -17,7 +17,7 @@ root.render( - + diff --git a/libs/services/common/src/index.ts b/libs/services/common/src/index.ts index 17cd302..d25279e 100644 --- a/libs/services/common/src/index.ts +++ b/libs/services/common/src/index.ts @@ -6,3 +6,4 @@ export * from './lib/container'; export * from './lib/types'; export * from './lib/group/groupCreate.dto'; export * from './lib/group/groupServiceWorkflow'; +export * from './lib/bff.container'; diff --git a/libs/services/common/src/lib/apis/backendBffApiService.ts b/libs/services/common/src/lib/apis/backendBffApiService.ts index 94859bd..0525336 100644 --- a/libs/services/common/src/lib/apis/backendBffApiService.ts +++ b/libs/services/common/src/lib/apis/backendBffApiService.ts @@ -4,6 +4,7 @@ import { Configuration, RemoteGroupApi } from "@spos/clients-bff"; @injectable() export class BackendBffApiService { private configuration = new Configuration({ + basePath: "http://localhost:3000", }); private remoteGroupApi = new RemoteGroupApi(this.configuration); diff --git a/libs/services/common/src/lib/group/groupRemoteService.ts b/libs/services/common/src/lib/group/groupRemoteService.ts index 131e34b..e371282 100644 --- a/libs/services/common/src/lib/group/groupRemoteService.ts +++ b/libs/services/common/src/lib/group/groupRemoteService.ts @@ -14,12 +14,14 @@ export class GroupRemoteService implements GroupService { } async addGroup(groupCreateDto: GroupCreateDto): Promise { + console.log('addGroupRemoteService', groupCreateDto, 'groupCreateDto'); return (await this.backendBffApiService.getRemoteGroupApi().remoteGroupControllerAddGroup({ annotatedGroupCreateDto: groupCreateDto, })).data; } async getGroup(id: string): Promise { + console.log('getGroupRemoteService', id, 'id'); return (await (this.backendBffApiService.getRemoteGroupApi().remoteGroupControllerGetGroup({ id, }))).data; @@ -27,6 +29,7 @@ export class GroupRemoteService implements GroupService { } async getGroups(): Promise { + console.log('getGroupsRemoteService'); return (await this.backendBffApiService.getRemoteGroupApi().remoteGroupControllerGetGroups()).data; } diff --git a/libs/ui/common/src/lib/offers/offers.tsx b/libs/ui/common/src/lib/offers/offers.tsx index 3f98ac4..e952b6d 100644 --- a/libs/ui/common/src/lib/offers/offers.tsx +++ b/libs/ui/common/src/lib/offers/offers.tsx @@ -4,12 +4,13 @@ import { useOffers } from './stores/offers'; import { useNavigate } from 'react-router-dom'; import { useMutation } from '@tanstack/react-query'; import { - container, GroupCreateDto, GroupService, TYPES, } from '@spos/services/common'; import { useCurrentSelectedGroup } from '../tables/stores/currentSelectedGroup'; +import { ContainerContext } from "../containerHook/containerContext"; +import { useContext } from "react"; export function Offers() { const offers = useOffers((state) => state.offers); @@ -17,6 +18,7 @@ export function Offers() { const resetCurrentSelectedGroup = useCurrentSelectedGroup( (state) => state.resetTables ); + const container = useContext(ContainerContext); const mutation = useMutation({ mutationFn: (newGroup: GroupCreateDto) => { return container.get(TYPES.GroupService).addGroup(newGroup);