Skip to content

Commit

Permalink
feat: add offer service
Browse files Browse the repository at this point in the history
  • Loading branch information
Apoorva64 committed Sep 28, 2024
1 parent 572936c commit 2e169ac
Show file tree
Hide file tree
Showing 15 changed files with 244 additions and 36 deletions.
3 changes: 2 additions & 1 deletion apps/backend-bff/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import { AppController } from './test/app.controller';
import { AppService } from './test/app.service';
import { RemoteGroupController } from "./remoteGroup/remote.group.controller";
import { RemoteTableController } from "./remoteTable/remote.table.controller";
import { RemoteOfferController } from "./remoteOffer/remote.offer.controller";
import { RemoteCatalogueController } from './remoteCatalogue/remote.catalogue.controller';

@Module({
imports: [],
controllers: [AppController, RemoteGroupController, RemoteTableController,RemoteCatalogueController],
controllers: [AppController, RemoteGroupController, RemoteTableController, RemoteOfferController, RemoteCatalogueController],
providers: [AppService],
})
export class AppModule {}
20 changes: 20 additions & 0 deletions apps/backend-bff/src/app/remoteOffer/remote.offer.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Controller, Get } from "@nestjs/common";
import { container, Offer, OfferService, TYPES } from "@spos/services/common";
import { ApiProperty, ApiTags } from "@nestjs/swagger";


class AnnotatedOffer implements Offer {
@ApiProperty()
availableItems: string[];
@ApiProperty()
name: string;
}

@Controller('remoteOffer')
@ApiTags('remoteOffer')
export class RemoteOfferController {
@Get()
async getOffers(): Promise<AnnotatedOffer[]> {
return container.get<OfferService>(TYPES.OfferService).getOffers();
}
}
2 changes: 1 addition & 1 deletion libs/clients/bff/openapi.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"openapi":"3.0.0","paths":{"/api/test":{"get":{"operationId":"AppController_getData","parameters":[],"responses":{"200":{"description":""}}}},"/api/remoteGroup":{"get":{"operationId":"RemoteGroupController_getGroups","parameters":[],"responses":{"200":{"description":"","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/AnnotatedGroup"}}}}}},"tags":["remoteGroup"]},"post":{"operationId":"RemoteGroupController_addGroup","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AnnotatedGroupCreateDto"}}}},"responses":{"201":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AnnotatedGroup"}}}}},"tags":["remoteGroup"]}},"/api/remoteGroup/{id}":{"get":{"operationId":"RemoteGroupController_getGroup","parameters":[{"name":"id","required":true,"in":"path","schema":{"type":"string"}}],"responses":{"200":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AnnotatedGroup"}}}}},"tags":["remoteGroup"]}},"/api/remoteTable":{"get":{"operationId":"RemoteTableController_getFreeTables","parameters":[],"responses":{"200":{"description":"","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/AnnotatedTableWithOrderDto"}}}}}},"tags":["remoteTable"]},"post":{"operationId":"RemoteTableController_closeAllTables","parameters":[],"responses":{"201":{"description":""}},"tags":["remoteTable"]}},"/api/remoteCatalogue/filteredCatalog":{"get":{"operationId":"RemoteCatalogueController_getFilteredCatalog","parameters":[{"name":"offerName","required":true,"in":"query","schema":{"type":"string"}}],"responses":{"200":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CategorizedCatalogDto"}}}}},"tags":["remoteCatalogue"]}},"/api/remoteCatalogue/items":{"get":{"operationId":"RemoteCatalogueController_getFullItemFromItemIdsArray","parameters":[{"name":"ids","required":true,"in":"query","schema":{"type":"array","items":{"type":"string"}}}],"responses":{"200":{"description":"","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/MenuItemDto"}}}}}},"tags":["remoteCatalogue"]}}},"info":{"title":"BFF API","description":"Backend For Frontend API","version":"1.0","contact":{}},"tags":[],"servers":[],"components":{"schemas":{"TableDto":{"type":"object","properties":{"id":{"type":"string"},"number":{"type":"number"},"customerCount":{"type":"number"}},"required":["id","number","customerCount"]},"AnnotatedGroup":{"type":"object","properties":{"id":{"type":"string"},"tables":{"type":"array","items":{"$ref":"#/components/schemas/TableDto"}},"offer":{"type":"string"}},"required":["id","tables","offer"]},"AnnotatedCreateTableDto":{"type":"object","properties":{"number":{"type":"number"},"customerCount":{"type":"number"}},"required":["number","customerCount"]},"AnnotatedGroupCreateDto":{"type":"object","properties":{"offer":{"type":"string"},"tables":{"type":"array","items":{"$ref":"#/components/schemas/AnnotatedCreateTableDto"}}},"required":["offer","tables"]},"AnnotatedTableWithOrderDto":{"type":"object","properties":{"_id":{"type":"string"},"number":{"type":"number"},"tableOrderId":{"type":"string"},"taken":{"type":"boolean"}},"required":["_id","number","tableOrderId","taken"]},"CategorizedCatalogDto":{"type":"object","properties":{"categories":{"type":"object","additionalProperties":{"type":"array","items":{"$ref":"#/components/schemas/MenuItemDto"}}}},"required":["categories"]},"MenuItemDto":{"type":"object","properties":{"_id":{"type":"string"},"fullName":{"type":"string"},"shortName":{"type":"string"},"price":{"type":"number"},"category":{"type":"string","enum":["STARTER","MAIN","DESSERT","BEVERAGE"]},"image":{"type":"string"}},"required":["_id","fullName","shortName","price","category","image"]}}}}
{"openapi":"3.0.0","paths":{"/api/test":{"get":{"operationId":"AppController_getData","parameters":[],"responses":{"200":{"description":""}}}},"/api/remoteGroup":{"get":{"operationId":"RemoteGroupController_getGroups","parameters":[],"responses":{"200":{"description":"","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/AnnotatedGroup"}}}}}},"tags":["remoteGroup"]},"post":{"operationId":"RemoteGroupController_addGroup","parameters":[],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/AnnotatedGroupCreateDto"}}}},"responses":{"201":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AnnotatedGroup"}}}}},"tags":["remoteGroup"]}},"/api/remoteGroup/{id}":{"get":{"operationId":"RemoteGroupController_getGroup","parameters":[{"name":"id","required":true,"in":"path","schema":{"type":"string"}}],"responses":{"200":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/AnnotatedGroup"}}}}},"tags":["remoteGroup"]}},"/api/remoteTable":{"get":{"operationId":"RemoteTableController_getFreeTables","parameters":[],"responses":{"200":{"description":"","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/AnnotatedTableWithOrderDto"}}}}}},"tags":["remoteTable"]},"post":{"operationId":"RemoteTableController_closeAllTables","parameters":[],"responses":{"201":{"description":""}},"tags":["remoteTable"]}},"/api/remoteOffer":{"get":{"operationId":"RemoteOfferController_getOffers","parameters":[],"responses":{"200":{"description":"","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/AnnotatedOffer"}}}}}},"tags":["remoteOffer"]}},"/api/remoteCatalogue/filteredCatalog":{"get":{"operationId":"RemoteCatalogueController_getFilteredCatalog","parameters":[{"name":"offerName","required":true,"in":"query","schema":{"type":"string"}}],"responses":{"200":{"description":"","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CategorizedCatalogDto"}}}}},"tags":["remoteCatalogue"]}},"/api/remoteCatalogue/items":{"get":{"operationId":"RemoteCatalogueController_getFullItemFromItemIdsArray","parameters":[{"name":"ids","required":true,"in":"query","schema":{"type":"array","items":{"type":"string"}}}],"responses":{"200":{"description":"","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/MenuItemDto"}}}}}},"tags":["remoteCatalogue"]}}},"info":{"title":"BFF API","description":"Backend For Frontend API","version":"1.0","contact":{}},"tags":[],"servers":[],"components":{"schemas":{"TableDto":{"type":"object","properties":{"id":{"type":"string"},"number":{"type":"number"},"customerCount":{"type":"number"}},"required":["id","number","customerCount"]},"AnnotatedGroup":{"type":"object","properties":{"id":{"type":"string"},"tables":{"type":"array","items":{"$ref":"#/components/schemas/TableDto"}},"offer":{"type":"string"}},"required":["id","tables","offer"]},"AnnotatedCreateTableDto":{"type":"object","properties":{"number":{"type":"number"},"customerCount":{"type":"number"}},"required":["number","customerCount"]},"AnnotatedGroupCreateDto":{"type":"object","properties":{"offer":{"type":"string"},"tables":{"type":"array","items":{"$ref":"#/components/schemas/AnnotatedCreateTableDto"}}},"required":["offer","tables"]},"AnnotatedTableWithOrderDto":{"type":"object","properties":{"_id":{"type":"string"},"number":{"type":"number"},"tableOrderId":{"type":"string"},"taken":{"type":"boolean"}},"required":["_id","number","tableOrderId","taken"]},"AnnotatedOffer":{"type":"object","properties":{"availableItems":{"type":"array","items":{"type":"string"}},"name":{"type":"string"}},"required":["availableItems","name"]},"CategorizedCatalogDto":{"type":"object","properties":{"categories":{"type":"object","additionalProperties":{"type":"array","items":{"$ref":"#/components/schemas/MenuItemDto"}}}},"required":["categories"]},"MenuItemDto":{"type":"object","properties":{"_id":{"type":"string"},"fullName":{"type":"string"},"shortName":{"type":"string"},"price":{"type":"number"},"category":{"type":"string","enum":["STARTER","MAIN","DESSERT","BEVERAGE"]},"image":{"type":"string"}},"required":["_id","fullName","shortName","price","category","image"]}}}}
2 changes: 2 additions & 0 deletions libs/clients/bff/src/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ api.ts
api/default-api.ts
api/remote-catalogue-api.ts
api/remote-group-api.ts
api/remote-offer-api.ts
api/remote-table-api.ts
base.ts
common.ts
Expand All @@ -12,6 +13,7 @@ index.ts
models/annotated-create-table-dto.ts
models/annotated-group-create-dto.ts
models/annotated-group.ts
models/annotated-offer.ts
models/annotated-table-with-order-dto.ts
models/categorized-catalog-dto.ts
models/index.ts
Expand Down
1 change: 1 addition & 0 deletions libs/clients/bff/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
export * from './api/default-api';
export * from './api/remote-catalogue-api';
export * from './api/remote-group-api';
export * from './api/remote-offer-api';
export * from './api/remote-table-api';

120 changes: 120 additions & 0 deletions libs/clients/bff/src/api/remote-offer-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/* tslint:disable */
/* eslint-disable */
/**
* BFF API
* Backend For Frontend API
*
* The version of the OpenAPI document: 1.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/


import type { Configuration } from '../configuration';
import type { AxiosPromise, AxiosInstance, RawAxiosRequestConfig } from 'axios';
import globalAxios from 'axios';
// Some imports not used depending on template conditions
// @ts-ignore
import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObject, setBearerAuthToObject, setOAuthToObject, setSearchParams, serializeDataIfNeeded, toPathString, createRequestFunction } from '../common';
// @ts-ignore
import { BASE_PATH, COLLECTION_FORMATS, type RequestArgs, BaseAPI, RequiredError, operationServerMap } from '../base';
// @ts-ignore
import type { AnnotatedOffer } from '../models';
/**
* RemoteOfferApi - axios parameter creator
* @export
*/
export const RemoteOfferApiAxiosParamCreator = function (configuration?: Configuration) {
return {
/**
*
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
remoteOfferControllerGetOffers: async (options: RawAxiosRequestConfig = {}): Promise<RequestArgs> => {
const localVarPath = `/api/remoteOffer`;
// use dummy base URL string because the URL constructor only accepts absolute URLs.
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions;
if (configuration) {
baseOptions = configuration.baseOptions;
}

const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options};
const localVarHeaderParameter = {} as any;
const localVarQueryParameter = {} as any;



setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers};

return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions,
};
},
}
};

/**
* RemoteOfferApi - functional programming interface
* @export
*/
export const RemoteOfferApiFp = function(configuration?: Configuration) {
const localVarAxiosParamCreator = RemoteOfferApiAxiosParamCreator(configuration)
return {
/**
*
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async remoteOfferControllerGetOffers(options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise<Array<AnnotatedOffer>>> {
const localVarAxiosArgs = await localVarAxiosParamCreator.remoteOfferControllerGetOffers(options);
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
const localVarOperationServerBasePath = operationServerMap['RemoteOfferApi.remoteOfferControllerGetOffers']?.[localVarOperationServerIndex]?.url;
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
},
}
};

/**
* RemoteOfferApi - factory interface
* @export
*/
export const RemoteOfferApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) {
const localVarFp = RemoteOfferApiFp(configuration)
return {
/**
*
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
remoteOfferControllerGetOffers(options?: RawAxiosRequestConfig): AxiosPromise<Array<AnnotatedOffer>> {
return localVarFp.remoteOfferControllerGetOffers(options).then((request) => request(axios, basePath));
},
};
};

/**
* RemoteOfferApi - object-oriented interface
* @export
* @class RemoteOfferApi
* @extends {BaseAPI}
*/
export class RemoteOfferApi extends BaseAPI {
/**
*
* @param {*} [options] Override http request option.
* @throws {RequiredError}
* @memberof RemoteOfferApi
*/
public remoteOfferControllerGetOffers(options?: RawAxiosRequestConfig) {
return RemoteOfferApiFp(this.configuration).remoteOfferControllerGetOffers(options).then((request) => request(this.axios, this.basePath));
}
}

36 changes: 36 additions & 0 deletions libs/clients/bff/src/models/annotated-offer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* tslint:disable */
/* eslint-disable */
/**
* BFF API
* Backend For Frontend API
*
* The version of the OpenAPI document: 1.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/



/**
*
* @export
* @interface AnnotatedOffer
*/
export interface AnnotatedOffer {
/**
*
* @type {Array<string>}
* @memberof AnnotatedOffer
*/
'availableItems': Array<string>;
/**
*
* @type {string}
* @memberof AnnotatedOffer
*/
'name': string;
}

1 change: 1 addition & 0 deletions libs/clients/bff/src/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './annotated-create-table-dto';
export * from './annotated-group';
export * from './annotated-group-create-dto';
export * from './annotated-offer';
export * from './annotated-table-with-order-dto';
export * from './categorized-catalog-dto';
export * from './menu-item-dto';
Expand Down
1 change: 1 addition & 0 deletions libs/services/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export * from './lib/group/groupCreate.dto';
export * from './lib/group/groupServiceWorkflow';
export * from './lib/bff.container';
export * from './lib/table/tableServiceWorkflow';
export * from "./lib/offer/offerServiceWorkflow";
export * from './lib/offer/catalogueServiceWorkflow';
5 changes: 3 additions & 2 deletions libs/services/common/src/lib/bff.container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { GroupService } from "./group/groupService";
import { BackendBffApiService } from "./apis/backendBffApiService";
import { GroupRemoteService } from "./group/groupRemoteService";
import { TableRemoteService } from "./table/tableRemoteService";
import { OfferRemoteService } from "./offer/offerRemoteService";
import { CatalogueService } from "./offer/catalogue.service";
import { CatalogueServiceWorkflow } from "./offer/catalogueServiceWorkflow";
import { CatalogueRemoteService } from "./offer/catalogueRemoteService";

const bffContainer = new Container();
Expand All @@ -18,6 +18,7 @@ bffContainer.bind<GroupService>(TYPES.GroupService).to(GroupRemoteService).inSin
bffContainer.bind<TableService>(TYPES.TableService).to(TableRemoteService).inSingletonScope();
bffContainer.bind<DiningApiService>(TYPES.DiningApiService).to(DiningApiService).inSingletonScope();
bffContainer.bind<MenuApiService>(TYPES.MenuApiService).to(MenuApiService).inSingletonScope();
bffContainer.bind<OfferService>(TYPES.OfferService).to(OfferService).inSingletonScope();
bffContainer.bind<OfferService>(TYPES.OfferService).to(OfferRemoteService).inSingletonScope();
bffContainer.bind<CatalogueService>(TYPES.CatalogueService).to(CatalogueRemoteService).inSingletonScope();
export { bffContainer };

4 changes: 2 additions & 2 deletions libs/services/common/src/lib/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import { CatalogueService } from "./offer/catalogue.service";
import { GroupService } from "./group/groupService";
import { TableServiceWorkflow } from "./table/tableServiceWorkflow";
import { CatalogueServiceWorkflow } from "./offer/catalogueServiceWorkflow";
import { OfferServiceWorkflow } from "./offer/offerServiceWorkflow";

const container = new Container();
container.bind<GroupService>(TYPES.GroupService).to(GroupServiceWorkflow).inSingletonScope();
container.bind<TableService>(TYPES.TableService).to(TableServiceWorkflow).inSingletonScope();
container.bind<DiningApiService>(TYPES.DiningApiService).to(DiningApiService).inSingletonScope();
container.bind<MenuApiService>(TYPES.MenuApiService).to(MenuApiService).inSingletonScope();
container.bind<OfferService>(TYPES.OfferService).to(OfferService).inSingletonScope();
//container.bind<CatalogService>(TYPES.CatalogService).to(CatalogService).inSingletonScope();
container.bind<OfferService>(TYPES.OfferService).to(OfferServiceWorkflow).inSingletonScope();
container.bind<CatalogueService>(TYPES.CatalogueService).to(CatalogueServiceWorkflow).inSingletonScope();

export { container };
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import { logger } from '../logger';

@injectable()
export class CatalogueServiceWorkflow implements CatalogueService {

private menuApiService = new MenuApiService();
private offerService = new OfferService();


constructor(
@inject(TYPES.OfferService) private offerService: OfferService) {
}
@logger
async getFilteredCatalog(offerName: string): Promise<CategorizedCatalog> {
const offer = await this.offerService.getOffers().then(response =>
Expand All @@ -37,7 +38,7 @@ export class CatalogueServiceWorkflow implements CatalogueService {

return categorizedCatalog;
}

@logger
async getFullItemFromItemIdsArray(idList: string[]): Promise<MenuItem[]> {
return (await this.menuApiService.getMenuApi().menusControllerGetFullMenu()).data.filter(
Expand Down
Loading

0 comments on commit 2e169ac

Please sign in to comment.