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

Added IOC-container #9

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
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
Added IOC-container
lorentzimys committed Aug 3, 2023
commit 4f1e1475ba1fca00cfa95aedce5cde790fb0d474
24 changes: 23 additions & 1 deletion booksService/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion booksService/package.json
Original file line number Diff line number Diff line change
@@ -16,11 +16,13 @@
"express": "^4.18.2",
"express-ejs-layouts": "^2.5.1",
"express-session": "^1.17.3",
"inversify": "^6.0.1",
"module-alias": "^2.2.2",
"mongoose": "^7.2.2",
"multer": "^1.4.5-lts.1",
"passport": "^0.6.0",
"passport-local": "^1.0.0",
"reflect-metadata": "^0.1.13",
"socket.io": "^4.7.1",
"uuid": "^9.0.0",
"yargs": "^17.7.2"
@@ -46,6 +48,6 @@
},
"engines": {
"node": "18.x",
"npm": "8.x"
"npm": ">8.x"
}
}
1 change: 1 addition & 0 deletions booksService/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "reflect-metadata";
import express from "express";
import session from "express-session";
import { Server } from "socket.io";
7 changes: 7 additions & 0 deletions booksService/src/ioc-container.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Container } from "inversify";
import { BooksRepository } from "./BooksRepository";

const iocContainer = new Container();
iocContainer.bind(BooksRepository).toSelf();

export { iocContainer };
10 changes: 9 additions & 1 deletion booksService/src/routes/books.ts
Original file line number Diff line number Diff line change
@@ -2,6 +2,8 @@ import { Router } from "express";

import BooksController from "@root/controllers/books";
import fileUpload from "@root/middleware/file";
import { iocContainer } from "@root/ioc-container";
import { BooksRepository } from "@root/BooksRepository";

const booksRouter = Router({ strict: true });

@@ -51,7 +53,13 @@ booksRouter.get(BOOKS_PATHS.MVC.EDIT_BOOK, BooksController.getEditBookView);
booksRouter.post(BOOKS_PATHS.MVC.EDIT_BOOK, BooksController.updateBook);

/** Get book */
booksRouter.get(BOOKS_PATHS.MVC.GET_BOOK, BooksController.getBookView);
// booksRouter.get(BOOKS_PATHS.MVC.GET_BOOK, BooksController.getBookView);
booksRouter.get(BOOKS_PATHS.MVC.GET_BOOK, async (req, res, next) => {
const repo = iocContainer.get(BooksRepository);
const book = await repo.getBook(req.params.id);

res.json(book);
});

/** Get all books */
booksRouter.get(BOOKS_PATHS.MVC.GET_BOOKS, BooksController.getBooksView);
7 changes: 5 additions & 2 deletions booksService/tsconfig.json
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
/* Modules */
"module": "commonjs", /* Specify what module code is generated. */
// "rootDir": "./", /* Specify the root folder within your source files. */
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
"baseUrl": ".", /* Specify the base directory to resolve non-relative module names. */
"paths": {
"@root/*": [
@@ -35,7 +35,8 @@
], /* Specify multiple folders that act like './node_modules/@types'. */
"types": [
"node",
"express"
"express",
"reflect-metadata"
],
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
@@ -44,6 +45,8 @@
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
"resolveJsonModule": true, /* Enable importing .json files. */
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */