├── bookstore-webapp ├── src │ ├── assets │ │ ├── .gitkeep │ │ └── 404PageNotFound.png │ ├── app │ │ ├── app.component.css │ │ ├── components │ │ │ ├── footer │ │ │ │ ├── footer.component.css │ │ │ │ ├── footer.component.html │ │ │ │ ├── footer.component.ts │ │ │ │ └── footer.component.spec.ts │ │ │ ├── add-book │ │ │ │ ├── add-book.component.css │ │ │ │ ├── add-book.component.spec.ts │ │ │ │ ├── add-book.component.ts │ │ │ │ └── add-book.component.html │ │ │ ├── books-list │ │ │ │ ├── books-list.component.css │ │ │ │ ├── books-list.component.spec.ts │ │ │ │ ├── books-list.component.ts │ │ │ │ └── books-list.component.html │ │ │ ├── dashboard │ │ │ │ ├── dashboard.component.css │ │ │ │ ├── dashboard.component.ts │ │ │ │ ├── dashboard.component.spec.ts │ │ │ │ └── dashboard.component.html │ │ │ ├── delete-book │ │ │ │ ├── delete-book.component.css │ │ │ │ ├── delete-book.component.spec.ts │ │ │ │ ├── delete-book.component.ts │ │ │ │ └── delete-book.component.html │ │ │ ├── edit-book │ │ │ │ ├── edit-book.component.css │ │ │ │ ├── edit-book.component.spec.ts │ │ │ │ ├── edit-book.component.ts │ │ │ │ └── edit-book.component.html │ │ │ ├── side-navbar │ │ │ │ ├── side-navbar.component.css │ │ │ │ ├── side-navbar.component.html │ │ │ │ ├── side-navbar.component.ts │ │ │ │ └── side-navbar.component.spec.ts │ │ │ ├── top-navbar │ │ │ │ ├── top-navbar.component.css │ │ │ │ ├── top-navbar.component.ts │ │ │ │ ├── top-navbar.component.html │ │ │ │ └── top-navbar.component.spec.ts │ │ │ └── page-notfound │ │ │ │ ├── page-notfound.component.css │ │ │ │ ├── page-notfound.component.html │ │ │ │ ├── page-notfound.component.ts │ │ │ │ └── page-notfound.component.spec.ts │ │ ├── interfaces │ │ │ ├── addBook.Dto.ts │ │ │ └── book.Dto.ts │ │ ├── app.component.ts │ │ ├── services │ │ │ ├── books.service.spec.ts │ │ │ └── books.service.ts │ │ ├── app.component.html │ │ ├── app.component.spec.ts │ │ ├── app-routing.module.ts │ │ └── app.module.ts │ ├── environments │ │ ├── environment.prod.ts │ │ └── environment.ts │ ├── favicon.ico │ ├── index.html │ ├── main.ts │ ├── test.ts │ ├── styles.css │ └── polyfills.ts ├── .editorconfig ├── e2e │ ├── src │ │ ├── app.po.ts │ │ └── app.e2e-spec.ts │ ├── tsconfig.json │ └── protractor.conf.js ├── tsconfig.app.json ├── tsconfig.spec.json ├── tsconfig.json ├── tsconfig.base.json ├── .gitignore ├── .browserslistrc ├── README.md ├── karma.conf.js ├── package.json ├── tslint.json └── angular.json ├── bookstore-webapi ├── src │ ├── Config │ │ └── appConfig.env │ ├── models │ │ ├── book.SchemaValidator.js │ │ └── book.Model.js │ ├── Persistence │ │ └── mongoDb.Helper.js │ ├── middleware │ │ └── logger.js │ ├── server.js │ ├── app.js │ ├── routes │ │ └── book-Router.js │ └── controllers │ │ └── books.Controller.js ├── jest.setup.js ├── .gitignore ├── jest.config.js ├── tests │ └── unit │ │ ├── __mocks__ │ │ └── MongoDbMock.js │ │ ├── app.spec.js │ │ ├── book-Router.spec.js │ │ └── books.Controller.spec.js └── package.json ├── Documentation └── Images │ ├── Add-Book.PNG │ ├── BooksList.PNG │ ├── Edit-Book.PNG │ ├── Delete-Book.PNG │ ├── Angular-WebAPP.PNG │ └── NodeJS-WebAPI.PNG └── ReadMe.md /bookstore-webapp/src/assets/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/app.component.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/components/footer/footer.component.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/components/add-book/add-book.component.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/components/books-list/books-list.component.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/components/dashboard/dashboard.component.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/components/delete-book/delete-book.component.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/components/edit-book/edit-book.component.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/components/side-navbar/side-navbar.component.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/components/top-navbar/top-navbar.component.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/components/page-notfound/page-notfound.component.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /bookstore-webapi/src/Config/appConfig.env: -------------------------------------------------------------------------------- 1 | PORT = 4004 2 | 3 | MongoDbConnection=YourConnectionString -------------------------------------------------------------------------------- /bookstore-webapp/src/app/components/side-navbar/side-navbar.component.html: -------------------------------------------------------------------------------- 1 |

side-navbar works!

2 | -------------------------------------------------------------------------------- /bookstore-webapp/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /Documentation/Images/Add-Book.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abdullahthewebbee/book-store-MEAN-Stack-main/HEAD/Documentation/Images/Add-Book.PNG -------------------------------------------------------------------------------- /Documentation/Images/BooksList.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abdullahthewebbee/book-store-MEAN-Stack-main/HEAD/Documentation/Images/BooksList.PNG -------------------------------------------------------------------------------- /Documentation/Images/Edit-Book.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abdullahthewebbee/book-store-MEAN-Stack-main/HEAD/Documentation/Images/Edit-Book.PNG -------------------------------------------------------------------------------- /bookstore-webapp/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abdullahthewebbee/book-store-MEAN-Stack-main/HEAD/bookstore-webapp/src/favicon.ico -------------------------------------------------------------------------------- /Documentation/Images/Delete-Book.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abdullahthewebbee/book-store-MEAN-Stack-main/HEAD/Documentation/Images/Delete-Book.PNG -------------------------------------------------------------------------------- /Documentation/Images/Angular-WebAPP.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abdullahthewebbee/book-store-MEAN-Stack-main/HEAD/Documentation/Images/Angular-WebAPP.PNG -------------------------------------------------------------------------------- /Documentation/Images/NodeJS-WebAPI.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abdullahthewebbee/book-store-MEAN-Stack-main/HEAD/Documentation/Images/NodeJS-WebAPI.PNG -------------------------------------------------------------------------------- /bookstore-webapp/src/assets/404PageNotFound.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abdullahthewebbee/book-store-MEAN-Stack-main/HEAD/bookstore-webapp/src/assets/404PageNotFound.png -------------------------------------------------------------------------------- /bookstore-webapp/src/app/components/footer/footer.component.html: -------------------------------------------------------------------------------- 1 | 4 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/interfaces/addBook.Dto.ts: -------------------------------------------------------------------------------- 1 | export interface IAddBookDto { 2 | 3 | language: string; 4 | 5 | author: string; 6 | 7 | title: string; 8 | 9 | dateOfPublish:string; 10 | 11 | } 12 | -------------------------------------------------------------------------------- /bookstore-webapi/jest.setup.js: -------------------------------------------------------------------------------- 1 | // By default each test has a default timeout of 5 seconds 2 | // After 5 seconds jest exits from the test 3 | 4 | console.log('Running jest.setup.js') 5 | jest.setTimeout(5 * 1000); // 5 seconds -------------------------------------------------------------------------------- /bookstore-webapp/src/app/interfaces/book.Dto.ts: -------------------------------------------------------------------------------- 1 | 2 | export interface IBookDto { 3 | 4 | dateOfPublish: Date; 5 | 6 | language: string; 7 | 8 | author: string; 9 | 10 | title: string; 11 | 12 | _id: string; 13 | 14 | } 15 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-root', 5 | templateUrl: './app.component.html', 6 | styleUrls: ['./app.component.css'] 7 | }) 8 | export class AppComponent { 9 | title = 'bookstore-webapp'; 10 | } 11 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/components/page-notfound/page-notfound.component.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |
4 | 5 |
6 | 7 |
8 | 9 |
10 |
11 | 12 | 13 | -------------------------------------------------------------------------------- /bookstore-webapi/.gitignore: -------------------------------------------------------------------------------- 1 | # Dependency directories 2 | node_modules/ 3 | coverage/ 4 | .stryker* 5 | reports/ 6 | 7 | # Result html 8 | *.html 9 | *.log 10 | 11 | *.png 12 | /.vs/slnx.sqlite 13 | /.vs/ProjectSettings.json 14 | .vs/VSWorkspaceState.json 15 | .vs/booksstore-sample/v16/.suo 16 | 17 | # DotEnv Config files 18 | src/config/.env 19 | .env -------------------------------------------------------------------------------- /bookstore-webapp/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.ts] 12 | quote_type = single 13 | 14 | [*.md] 15 | max_line_length = off 16 | trim_trailing_whitespace = false 17 | -------------------------------------------------------------------------------- /bookstore-webapp/e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo(): Promise { 5 | return browser.get(browser.baseUrl) as Promise; 6 | } 7 | 8 | getTitleText(): Promise { 9 | return element(by.css('app-root .content span')).getText() as Promise; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /bookstore-webapp/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BookstoreWebapp 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /bookstore-webapp/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "./tsconfig.base.json", 4 | "compilerOptions": { 5 | "outDir": "./out-tsc/app", 6 | "types": [] 7 | }, 8 | "files": [ 9 | "src/main.ts", 10 | "src/polyfills.ts" 11 | ], 12 | "include": [ 13 | "src/**/*.d.ts" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /bookstore-webapp/e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "../tsconfig.base.json", 4 | "compilerOptions": { 5 | "outDir": "../out-tsc/e2e", 6 | "module": "commonjs", 7 | "target": "es2018", 8 | "types": [ 9 | "jasmine", 10 | "jasminewd2", 11 | "node" 12 | ] 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/components/footer/footer.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-footer', 5 | templateUrl: './footer.component.html', 6 | styleUrls: ['./footer.component.css'] 7 | }) 8 | export class FooterComponent implements OnInit { 9 | 10 | constructor() { } 11 | 12 | ngOnInit(): void { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/components/dashboard/dashboard.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-dashboard', 5 | templateUrl: './dashboard.component.html', 6 | styleUrls: ['./dashboard.component.css'] 7 | }) 8 | export class DashboardComponent implements OnInit { 9 | 10 | constructor() { } 11 | 12 | ngOnInit(): void { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/components/top-navbar/top-navbar.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-top-navbar', 5 | templateUrl: './top-navbar.component.html', 6 | styleUrls: ['./top-navbar.component.css'] 7 | }) 8 | export class TopNavbarComponent implements OnInit { 9 | 10 | constructor() { } 11 | 12 | ngOnInit(): void { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/components/side-navbar/side-navbar.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-side-navbar', 5 | templateUrl: './side-navbar.component.html', 6 | styleUrls: ['./side-navbar.component.css'] 7 | }) 8 | export class SideNavbarComponent implements OnInit { 9 | 10 | constructor() { } 11 | 12 | ngOnInit(): void { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/components/page-notfound/page-notfound.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-page-notfound', 5 | templateUrl: './page-notfound.component.html', 6 | styleUrls: ['./page-notfound.component.css'] 7 | }) 8 | export class PageNotfoundComponent implements OnInit { 9 | 10 | constructor() { } 11 | 12 | ngOnInit(): void { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /bookstore-webapp/src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.error(err)); 13 | -------------------------------------------------------------------------------- /bookstore-webapp/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "./tsconfig.base.json", 4 | "compilerOptions": { 5 | "outDir": "./out-tsc/spec", 6 | "types": [ 7 | "jasmine" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts", 12 | "src/polyfills.ts" 13 | ], 14 | "include": [ 15 | "src/**/*.spec.ts", 16 | "src/**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/services/books.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed } from '@angular/core/testing'; 2 | 3 | import { BooksService } from './books.service'; 4 | 5 | describe('BooksService', () => { 6 | let service: BooksService; 7 | 8 | beforeEach(() => { 9 | TestBed.configureTestingModule({}); 10 | service = TestBed.inject(BooksService); 11 | }); 12 | 13 | it('should be created', () => { 14 | expect(service).toBeTruthy(); 15 | }); 16 | }); 17 | -------------------------------------------------------------------------------- /bookstore-webapi/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: 'node', 3 | setupFilesAfterEnv: ['./jest.setup.js'], 4 | reporters: [ 5 | "default", 6 | [ 7 | "./node_modules/jest-html-reporter", 8 | { 9 | pageTitle: "Test-Report", 10 | outputPath: "./coverage/Books-Unit-Test-Report.html", 11 | includeFailureMsg: true 12 | } 13 | ] 14 | ], 15 | }; -------------------------------------------------------------------------------- /bookstore-webapi/src/models/book.SchemaValidator.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const joiValidator = require('@hapi/joi'); 4 | 5 | const bookSchemaValidator = joiValidator.object({ 6 | 7 | author: joiValidator.string().required(), 8 | 9 | title: joiValidator.string().required(), 10 | 11 | dateOfPublish: joiValidator.date(), 12 | 13 | language: joiValidator.string(), 14 | 15 | read: joiValidator.bool() 16 | 17 | }); 18 | 19 | module.exports = bookSchemaValidator; 20 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |
5 | 10 |
11 | 12 |
13 |
14 |
15 | 16 | 17 | -------------------------------------------------------------------------------- /bookstore-webapp/tsconfig.json: -------------------------------------------------------------------------------- 1 | /* 2 | This is a "Solution Style" tsconfig.json file, and is used by editors and TypeScript’s language server to improve development experience. 3 | It is not intended to be used to perform a compilation. 4 | 5 | To learn more about this file see: https://angular.io/config/solution-tsconfig. 6 | */ 7 | { 8 | "files": [], 9 | "references": [ 10 | { 11 | "path": "./tsconfig.app.json" 12 | }, 13 | { 14 | "path": "./tsconfig.spec.json" 15 | } 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /bookstore-webapi/src/models/book.Model.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const mongoose = require('mongoose'); 4 | const { Schema } = mongoose; 5 | 6 | const bookModel = new Schema({ 7 | author: { type: String, required: true }, 8 | 9 | title: { type: String, required: true }, 10 | 11 | dateOfPublish: { type: Date, required: true, default: new Date().toUTCString() }, 12 | 13 | language: { type: String, default: 'C#' }, 14 | 15 | read: { type: Boolean, default: false } 16 | }); 17 | 18 | module.exports = mongoose.model('book', bookModel); 19 | 20 | 21 | -------------------------------------------------------------------------------- /bookstore-webapp/tsconfig.base.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "compileOnSave": false, 4 | "compilerOptions": { 5 | "baseUrl": "./", 6 | "outDir": "./dist/out-tsc", 7 | "sourceMap": true, 8 | "declaration": false, 9 | "downlevelIteration": true, 10 | "experimentalDecorators": true, 11 | "moduleResolution": "node", 12 | "importHelpers": true, 13 | "target": "es2015", 14 | "module": "es2020", 15 | "lib": [ 16 | "es2018", 17 | "dom" 18 | ] 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/components/top-navbar/top-navbar.component.html: -------------------------------------------------------------------------------- 1 | 16 | -------------------------------------------------------------------------------- /bookstore-webapp/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * For easier debugging in development mode, you can import the following file 11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 12 | * 13 | * This import should be commented out in production mode because it will have a negative impact 14 | * on performance if an error is thrown. 15 | */ 16 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /bookstore-webapp/e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | import { browser, logging } from 'protractor'; 3 | 4 | describe('workspace-project App', () => { 5 | let page: AppPage; 6 | 7 | beforeEach(() => { 8 | page = new AppPage(); 9 | }); 10 | 11 | it('should display welcome message', () => { 12 | page.navigateTo(); 13 | expect(page.getTitleText()).toEqual('bookstore-webapp app is running!'); 14 | }); 15 | 16 | afterEach(async () => { 17 | // Assert that there are no errors emitted from the browser 18 | const logs = await browser.manage().logs().get(logging.Type.BROWSER); 19 | expect(logs).not.toContain(jasmine.objectContaining({ 20 | level: logging.Level.SEVERE, 21 | } as logging.Entry)); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/components/footer/footer.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { FooterComponent } from './footer.component'; 4 | 5 | describe('FooterComponent', () => { 6 | let component: FooterComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ FooterComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(FooterComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/components/add-book/add-book.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { AddBookComponent } from './add-book.component'; 4 | 5 | describe('AddBookComponent', () => { 6 | let component: AddBookComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ AddBookComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(AddBookComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/components/edit-book/edit-book.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { EditBookComponent } from './edit-book.component'; 4 | 5 | describe('EditBookComponent', () => { 6 | let component: EditBookComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ EditBookComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(EditBookComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/components/dashboard/dashboard.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { DashboardComponent } from './dashboard.component'; 4 | 5 | describe('DashboardComponent', () => { 6 | let component: DashboardComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ DashboardComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(DashboardComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/components/books-list/books-list.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { BooksListComponent } from './books-list.component'; 4 | 5 | describe('BooksListComponent', () => { 6 | let component: BooksListComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ BooksListComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(BooksListComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/components/top-navbar/top-navbar.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { TopNavbarComponent } from './top-navbar.component'; 4 | 5 | describe('TopNavbarComponent', () => { 6 | let component: TopNavbarComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ TopNavbarComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(TopNavbarComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/components/delete-book/delete-book.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { DeleteBookComponent } from './delete-book.component'; 4 | 5 | describe('DeleteBookComponent', () => { 6 | let component: DeleteBookComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ DeleteBookComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(DeleteBookComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/components/side-navbar/side-navbar.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { SideNavbarComponent } from './side-navbar.component'; 4 | 5 | describe('SideNavbarComponent', () => { 6 | let component: SideNavbarComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ SideNavbarComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(SideNavbarComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /bookstore-webapi/src/Persistence/mongoDb.Helper.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const mongoose = require('mongoose'); 4 | require('dotenv/config'); 5 | 6 | const connectToMongoDb = async () => { 7 | 8 | await mongoose.connect(process.env.MongoDbConnection, { 9 | 10 | useNewUrlParser: true, 11 | useUnifiedTopology: true 12 | 13 | }, (error) => { 14 | 15 | if (error) { 16 | 17 | console.log(`Error Connecting to Cloud MongoDb ${error}`); 18 | throw new Error(error); 19 | } else { 20 | 21 | // Connecting to the MongoDb Cloud Instance 22 | console.log(`Mongo Db Connection: ${process.env.MongoDbConnection}`); 23 | console.log('Connected to MongoDb in Cloud'); 24 | } 25 | 26 | }); 27 | } 28 | 29 | module.exports = { connectToMongoDb }; 30 | -------------------------------------------------------------------------------- /bookstore-webapi/src/middleware/logger.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const morgan = require('morgan') 4 | const chalk = require('chalk'); 5 | 6 | // Logger Middleware 7 | const morganLogger = morgan(function (tokens, req, res) { 8 | return chalk.blue.bold([ 9 | 'Method:', tokens.method(req, res), 10 | '\tEnd Point:', tokens.url(req, res), 11 | '\tStatus:', tokens.status(req, res), 12 | '\tContent Length:', tokens.res(req, res, 'content-length'), 13 | '\tResponse Time', tokens['response-time'](req, res), 'ms' 14 | ].join(' ')); 15 | }); 16 | 17 | module.exports = morganLogger; 18 | 19 | /* 20 | const logger = (req, res, next) => { 21 | 22 | console.log( 23 | `${req.method} ${req.protocol}://${req.get('host')}${req.originalUrl}` 24 | ); 25 | 26 | next(); 27 | 28 | }; 29 | */ 30 | 31 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/components/page-notfound/page-notfound.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { PageNotfoundComponent } from './page-notfound.component'; 4 | 5 | describe('PageNotfoundComponent', () => { 6 | let component: PageNotfoundComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ PageNotfoundComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(PageNotfoundComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /bookstore-webapp/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | # Only exists if Bazel was run 8 | /bazel-out 9 | 10 | # dependencies 11 | /node_modules 12 | 13 | # profiling files 14 | chrome-profiler-events*.json 15 | speed-measure-plugin*.json 16 | 17 | # IDEs and editors 18 | /.idea 19 | .project 20 | .classpath 21 | .c9/ 22 | *.launch 23 | .settings/ 24 | *.sublime-workspace 25 | 26 | # IDE - VSCode 27 | .vscode/* 28 | !.vscode/settings.json 29 | !.vscode/tasks.json 30 | !.vscode/launch.json 31 | !.vscode/extensions.json 32 | .history/* 33 | 34 | # misc 35 | /.sass-cache 36 | /connect.lock 37 | /coverage 38 | /libpeerconnection.log 39 | npm-debug.log 40 | yarn-error.log 41 | testem.log 42 | /typings 43 | 44 | # System Files 45 | .DS_Store 46 | Thumbs.db 47 | -------------------------------------------------------------------------------- /bookstore-webapp/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: { 11 | context(path: string, deep?: boolean, filter?: RegExp): { 12 | keys(): string[]; 13 | (id: string): T; 14 | }; 15 | }; 16 | 17 | // First, initialize the Angular testing environment. 18 | getTestBed().initTestEnvironment( 19 | BrowserDynamicTestingModule, 20 | platformBrowserDynamicTesting() 21 | ); 22 | // Then we find all the tests. 23 | const context = require.context('./', true, /\.spec\.ts$/); 24 | // And load the modules. 25 | context.keys().map(context); 26 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/components/books-list/books-list.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | import { IBookDto } from '../../interfaces/book.Dto'; 4 | import { BooksService } from '../../services/books.service'; 5 | 6 | @Component({ 7 | selector: 'app-books-list', 8 | templateUrl: './books-list.component.html', 9 | styleUrls: ['./books-list.component.css'] 10 | }) 11 | export class BooksListComponent implements OnInit { 12 | 13 | booksList: IBookDto[] = []; 14 | 15 | constructor(private booksService: BooksService) { 16 | } 17 | 18 | ngOnInit(): void { 19 | 20 | this.retrieveAllBooks(); 21 | } 22 | 23 | retrieveAllBooks() { 24 | 25 | this.booksService.GetAllBooks() 26 | .subscribe((data: IBookDto[]) => { 27 | 28 | this.booksList = data; 29 | console.log(this.booksList); 30 | }); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /bookstore-webapi/src/server.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const webApi = require('./app'); 4 | const mongoDbConnection = require('./Persistence/mongoDb.Helper'); 5 | const path = require('path'); 6 | const dotenv = require('dotenv'); 7 | 8 | // Load the Configuration from the given Path 9 | const _config = dotenv.config({ path: path.resolve(process.cwd(), 'src/config/.env')}); 10 | 11 | var port = process.env.PORT || 3000; 12 | 13 | mongoDbConnection 14 | .connectToMongoDb() 15 | .then(() => { 16 | 17 | // Listen to the server 18 | webApi.listen(port, () => { 19 | console.log(`Env Port: ${process.env.PORT}`); 20 | console.log(`Server Listening at port ${port}. http://localhost:${port}`); 21 | }); 22 | 23 | }) 24 | .catch((error) => { 25 | 26 | console.log(`Error:: Unable to connect to Mongo Database. Message:: ${error}`); 27 | 28 | }); 29 | -------------------------------------------------------------------------------- /bookstore-webapp/.browserslistrc: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # For the full list of supported browsers by the Angular framework, please see: 6 | # https://angular.io/guide/browser-support 7 | 8 | # You can see what browsers were selected by your queries by running: 9 | # npx browserslist 10 | 11 | last 1 Chrome version 12 | last 1 Firefox version 13 | last 2 Edge major versions 14 | last 2 Safari major versions 15 | last 2 iOS major versions 16 | Firefox ESR 17 | not IE 9-10 # Angular support for IE 9-10 has been deprecated and will be removed as of Angular v11. To opt-in, remove the 'not' prefix on this line. 18 | not IE 11 # Angular supports IE 11 only as an opt-in. To opt-in, remove the 'not' prefix on this line. 19 | -------------------------------------------------------------------------------- /bookstore-webapi/tests/unit/__mocks__/MongoDbMock.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const mongoose = require('mongoose'); 4 | const { MongoMemoryServer } = require('mongodb-memory-server'); 5 | const mongoDbServer = new MongoMemoryServer(); 6 | 7 | module.exports.connect = async () => { 8 | 9 | const uri = await mongoDbServer.getConnectionString();; 10 | 11 | const mongooseOpts = { 12 | useNewUrlParser: true, 13 | useUnifiedTopology: true, 14 | }; 15 | 16 | await mongoose.connect(uri, mongooseOpts); 17 | } 18 | 19 | module.exports.closeDatabase = async () => { 20 | await mongoose.connection.dropDatabase(); 21 | await mongoose.connection.close(); 22 | await mongoDbServer.stop(); 23 | } 24 | 25 | module.exports.clearDatabase = async () => { 26 | const collections = mongoose.connection.collections; 27 | 28 | for (const key in collections) { 29 | const collection = collections[key]; 30 | await collection.deleteMany(); 31 | } 32 | } -------------------------------------------------------------------------------- /bookstore-webapp/src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | 3 | .sidenav { 4 | height: inherit; 5 | width: 15%; 6 | position: fixed; 7 | z-index: 1; 8 | left: 0; 9 | transition: 0.5s; 10 | } 11 | 12 | .top-navbar-color { 13 | background: #3f51b5; 14 | color: white; 15 | } 16 | 17 | .bg-sidebar { 18 | background: #0428f173; 19 | color: white; 20 | } 21 | 22 | .PageTitle { 23 | color: royalblue; 24 | } 25 | 26 | footer { 27 | background: #3f51b5; 28 | color: white; 29 | padding: 1px; 30 | bottom: 0; 31 | vertical-align: middle; 32 | } 33 | 34 | .float { 35 | position: fixed; 36 | width: 60px; 37 | height: 60px; 38 | right: 40px; 39 | top: 70px; 40 | background-color: #0c9; 41 | color: #fff; 42 | border-radius: 50px; 43 | text-align: center; 44 | box-shadow: 2px 2px 3px #999; 45 | } 46 | 47 | .float-margintop { 48 | margin-top: 22px; 49 | } 50 | 51 | .labelAndTextbox { 52 | display: flex; 53 | } 54 | -------------------------------------------------------------------------------- /bookstore-webapp/e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | // Protractor configuration file, see link for more information 3 | // https://github.com/angular/protractor/blob/master/lib/config.ts 4 | 5 | const { SpecReporter, StacktraceOption } = require('jasmine-spec-reporter'); 6 | 7 | /** 8 | * @type { import("protractor").Config } 9 | */ 10 | exports.config = { 11 | allScriptsTimeout: 11000, 12 | specs: [ 13 | './src/**/*.e2e-spec.ts' 14 | ], 15 | capabilities: { 16 | browserName: 'chrome' 17 | }, 18 | directConnect: true, 19 | baseUrl: 'http://localhost:4200/', 20 | framework: 'jasmine', 21 | jasmineNodeOpts: { 22 | showColors: true, 23 | defaultTimeoutInterval: 30000, 24 | print: function() {} 25 | }, 26 | onPrepare() { 27 | require('ts-node').register({ 28 | project: require('path').join(__dirname, './tsconfig.json') 29 | }); 30 | jasmine.getEnv().addReporter(new SpecReporter({ 31 | spec: { 32 | displayStacktrace: StacktraceOption.PRETTY 33 | } 34 | })); 35 | } 36 | }; -------------------------------------------------------------------------------- /bookstore-webapi/src/app.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const express = require('express'); 4 | 5 | const Book = require('./models/book.Model'); 6 | const bookRouter = require('./routes/book-Router')(Book); 7 | const morganLogger = require('./middleware/logger'); 8 | 9 | 10 | // Initialized the application 11 | const webApi = express(); 12 | 13 | // Logger Middleware 14 | webApi.use(morganLogger); 15 | 16 | // Allowing CORS 17 | webApi.use(function (_, response, next) { 18 | 19 | response.header("Access-Control-Allow-Origin", "*"); 20 | response.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); 21 | response.header("Access-Control-Allow-Methods", "GET, POST, OPTIONS, PUT, DELETE"); 22 | 23 | next(); 24 | }); 25 | 26 | // express middleware to handle the json body request 27 | webApi.use(express.json()); 28 | 29 | // Default Route 30 | webApi.get('/api', (request, response) => { 31 | response.status(200).json("Welcome to Books Web API."); 32 | }); 33 | 34 | // Middleware (To Import Additional Routes) 35 | webApi.use('/api', bookRouter); 36 | 37 | 38 | module.exports = webApi; 39 | -------------------------------------------------------------------------------- /bookstore-webapp/README.md: -------------------------------------------------------------------------------- 1 | # BookstoreWebapp 2 | 3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 10.0.4. 4 | 5 | ## Development server 6 | 7 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. 8 | 9 | ## Code scaffolding 10 | 11 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. 12 | 13 | ## Build 14 | 15 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build. 16 | 17 | ## Running unit tests 18 | 19 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 20 | 21 | ## Running end-to-end tests 22 | 23 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). 24 | 25 | ## Further help 26 | 27 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md). 28 | -------------------------------------------------------------------------------- /bookstore-webapp/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, './coverage/bookstore-webapp'), 20 | reports: ['html', 'lcovonly', 'text-summary'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false, 30 | restartOnFileChange: true 31 | }); 32 | }; 33 | -------------------------------------------------------------------------------- /ReadMe.md: -------------------------------------------------------------------------------- 1 | # Book Store Application 2 | 3 |
4 | This is a Simple MEAN Stack application for Book Store which performs all the CRUD operations where: 5 |
6 | C - Create/Add a book
7 | R - Read the book entries from the database(MongoDB Atlas)
8 | U - Update the book details
9 | D - Delete the book entries 10 |

11 | This project is part of my 1 Month Industrial Training of MEAN Stack Development from WebTek Labs, Delhi. 12 |
13 | 14 | ## Application Looks and Feel 15 | 16 | ### Angular 10 UI 17 | 18 | ![Web APP Dashboard|150x150](./Documentation/Images/Angular-WebAPP.PNG)' 19 | ![Web APP Dashboard|150x150](./Documentation/Images/Add-Book.PNG)' 20 | ![Web APP Dashboard|150x150](./Documentation/Images/BooksList.PNG)' 21 | ![Web APP Dashboard|150x150](./Documentation/Images/Edit-Book.PNG)' 22 | ![Web APP Dashboard|150x150](./Documentation/Images/Delete-Book.PNG)' 23 | 24 | ### Web API 25 | 26 | ![Web API Output|150x150](./Documentation/Images/NodeJS-WebAPI.PNG) 27 | 28 | ## Technologies Used 29 | 30 | 1. Node JS + Express Web API 31 | 2. Angular 10 UI 32 | 3. [Mongo Db Atlas](https://cloud.mongodb.com/) 33 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async } from '@angular/core/testing'; 2 | import { RouterTestingModule } from '@angular/router/testing'; 3 | import { AppComponent } from './app.component'; 4 | 5 | describe('AppComponent', () => { 6 | beforeEach(async(() => { 7 | TestBed.configureTestingModule({ 8 | imports: [ 9 | RouterTestingModule 10 | ], 11 | declarations: [ 12 | AppComponent 13 | ], 14 | }).compileComponents(); 15 | })); 16 | 17 | it('should create the app', () => { 18 | const fixture = TestBed.createComponent(AppComponent); 19 | const app = fixture.componentInstance; 20 | expect(app).toBeTruthy(); 21 | }); 22 | 23 | it(`should have as title 'bookstore-webapp'`, () => { 24 | const fixture = TestBed.createComponent(AppComponent); 25 | const app = fixture.componentInstance; 26 | expect(app.title).toEqual('bookstore-webapp'); 27 | }); 28 | 29 | it('should render title', () => { 30 | const fixture = TestBed.createComponent(AppComponent); 31 | fixture.detectChanges(); 32 | const compiled = fixture.nativeElement; 33 | expect(compiled.querySelector('.content span').textContent).toContain('bookstore-webapp app is running!'); 34 | }); 35 | }); 36 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/components/add-book/add-book.component.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import { Router } from '@angular/router'; 4 | import { Component, NgZone, OnInit } from '@angular/core'; 5 | import { FormBuilder, FormGroup } from '@angular/forms'; 6 | 7 | import { BooksService } from '../../services/books.service'; 8 | import { IAddBookDto } from '../../interfaces/addBook.Dto'; 9 | 10 | @Component({ 11 | selector: 'app-add-book', 12 | templateUrl: './add-book.component.html', 13 | styleUrls: ['./add-book.component.css'] 14 | }) 15 | export class AddBookComponent implements OnInit { 16 | 17 | // addBookDto: IAddBookDto; 18 | addBookForm: FormGroup; 19 | 20 | constructor(private bookstoreService: BooksService, private ngZone: NgZone, 21 | private router: Router, private formBuilder: FormBuilder) { 22 | 23 | this.addBookForm = this.formBuilder.group({ 24 | dateOfPublish: '', 25 | language: '', 26 | author: '', 27 | title: '' 28 | }); 29 | } 30 | 31 | ngOnInit(): void { 32 | } 33 | 34 | onBookAdd(bookData: IAddBookDto): void { 35 | 36 | this.bookstoreService.AddBooks(bookData).subscribe(res => { 37 | 38 | console.log('Book Added!') 39 | this.ngZone.run(() => this.router.navigateByUrl('/books')) 40 | }); 41 | 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | 4 | import { AddBookComponent } from './components/add-book/add-book.component'; 5 | import { BooksListComponent } from './components/books-list/books-list.component'; 6 | import { DashboardComponent } from './components/dashboard/dashboard.component'; 7 | import { DeleteBookComponent } from './components/delete-book/delete-book.component'; 8 | import { EditBookComponent } from './components/edit-book/edit-book.component'; 9 | import { PageNotfoundComponent } from './components/page-notfound/page-notfound.component'; 10 | 11 | const routes: Routes = [ 12 | { path: 'add-book', component: AddBookComponent }, 13 | { path: 'books', component: BooksListComponent }, 14 | { path: 'dashboard', component: DashboardComponent }, 15 | { path: 'delete-book/:bookId', component: DeleteBookComponent }, 16 | { path: 'edit-book/:bookId', component: EditBookComponent }, 17 | { path: 'pagenotfound', component: PageNotfoundComponent }, 18 | { path: '', redirectTo: 'dashboard', pathMatch: 'full' }, 19 | { path: '**', redirectTo: 'pagenotfound', pathMatch: 'full' }, 20 | ]; 21 | 22 | @NgModule({ 23 | imports: [RouterModule.forRoot(routes)], 24 | exports: [RouterModule] 25 | }) 26 | export class AppRoutingModule { } 27 | -------------------------------------------------------------------------------- /bookstore-webapi/src/routes/book-Router.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const express = require('express'); 4 | const booksController = require('../controllers/books.Controller'); 5 | 6 | function routes(Book) { 7 | 8 | const bookRouter = express.Router(); 9 | const bookController = booksController(Book); 10 | 11 | // Middleware For Retrieving the Book 12 | bookRouter.use('/books/:bookId', (request, response, next) => { 13 | console.log(`Using Middleware for finding Book. ${request.params.bookId}`); 14 | 15 | Book.findById(request.params.bookId, (error, book) => { 16 | 17 | if (error) { 18 | return response.status(500).json(`Error from Middleware: ${error}`); 19 | } 20 | 21 | if (book) { 22 | console.log(`Book Found: ${book}`); 23 | request.book = book; 24 | return next(); 25 | } 26 | 27 | return response.status(404).json(); 28 | }); 29 | 30 | }); 31 | 32 | bookRouter.route('/books') 33 | .post(bookController.post) 34 | .get(bookController.get); 35 | 36 | bookRouter.route('/books/:bookId') 37 | .get(bookController.getBookById) 38 | .put(bookController.updateBookById) 39 | .delete(bookController.deleteBookById); 40 | 41 | return bookRouter; 42 | } 43 | 44 | module.exports = routes; 45 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/components/books-list/books-list.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |

Books List

4 |
5 |
6 |
7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 36 | 37 | 38 |
Book IDPublished OnLanguageAuthorTitleActions
{{ book._id }}{{ book.dateOfPublish | date}}{{ book.language }}{{ book.author}}{{ book.title }} 30 | 33 | 35 |
39 |
40 |
41 | -------------------------------------------------------------------------------- /bookstore-webapi/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bookstore-webapi", 3 | "version": "1.0.1", 4 | "description": "Simple NodeJS, express Web API using Mongo Db", 5 | "main": "server.js", 6 | "directories": { 7 | "test": "tests" 8 | }, 9 | "scripts": { 10 | "start": "nodemon ./src/server.js", 11 | "debug": "nodemon --inspect ./src/server.js", 12 | "test": "jest", 13 | "test:watch": "jest --watch" 14 | }, 15 | "author": "Yashita Namdeo", 16 | "license": "ISC", 17 | "devDependencies": { 18 | "faker": "^4.1.0", 19 | "jest": "^26.1.0", 20 | "jest-html-reporter": "^3.1.3", 21 | "mongodb-memory-server": "^6.6.1", 22 | "node-mocks-http": "^1.8.1", 23 | "nodemon": "^2.0.4", 24 | "proxyquire": "^2.1.3", 25 | "sinon": "^9.0.2", 26 | "supertest": "^4.0.2" 27 | }, 28 | "dependencies": { 29 | "@hapi/joi": "^17.1.1", 30 | "chalk": "^4.1.0", 31 | "colors": "^1.4.0", 32 | "dotenv": "^8.2.0", 33 | "express": "^4.17.1", 34 | "mongoose": "^5.9.20", 35 | "morgan": "^1.10.0" 36 | }, 37 | "nodemonConfig": { 38 | "restartable": "rs", 39 | "ignore": [ 40 | "node_modules/**/node_modules" 41 | ], 42 | "delay": "500", 43 | "env": { 44 | "NODE_ENV": "development", 45 | "PORT": 4000 46 | } 47 | }, 48 | "jest": { 49 | "modulePathIgnorePatterns": [ 50 | "__mocks__" 51 | ] 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /bookstore-webapp/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bookstore-webapp", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build": "ng build", 8 | "test": "ng test", 9 | "lint": "ng lint", 10 | "e2e": "ng e2e" 11 | }, 12 | "private": true, 13 | "dependencies": { 14 | "@angular/animations": "~10.0.5", 15 | "@angular/common": "~10.0.5", 16 | "@angular/compiler": "~10.0.5", 17 | "@angular/core": "~10.0.5", 18 | "@angular/forms": "~10.0.5", 19 | "@angular/platform-browser": "~10.0.5", 20 | "@angular/platform-browser-dynamic": "~10.0.5", 21 | "@angular/router": "~10.0.5", 22 | "bootstrap": "^4.5.2", 23 | "font-awesome": "^4.7.0", 24 | "guid-typescript": "^1.0.9", 25 | "jquery": "^3.5.1", 26 | "popper.js": "^1.16.1", 27 | "rxjs": "~6.5.5", 28 | "tslib": "^2.0.0", 29 | "zone.js": "~0.10.3" 30 | }, 31 | "devDependencies": { 32 | "@angular-devkit/build-angular": "~0.1000.4", 33 | "@angular/cli": "~10.0.4", 34 | "@angular/compiler-cli": "~10.0.5", 35 | "@types/node": "^12.11.1", 36 | "@types/jasmine": "~3.5.0", 37 | "@types/jasminewd2": "~2.0.3", 38 | "codelyzer": "^6.0.0", 39 | "jasmine-core": "~3.5.0", 40 | "jasmine-spec-reporter": "~5.0.0", 41 | "karma": "~5.0.0", 42 | "karma-chrome-launcher": "~3.1.0", 43 | "karma-coverage-istanbul-reporter": "~3.0.2", 44 | "karma-jasmine": "~3.3.0", 45 | "karma-jasmine-html-reporter": "^1.5.0", 46 | "protractor": "~7.0.0", 47 | "ts-node": "~8.3.0", 48 | "tslint": "~6.1.0", 49 | "typescript": "~3.9.5" 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { HttpClientModule } from '@angular/common/http'; 3 | import { NgModule } from '@angular/core'; 4 | import { ReactiveFormsModule } from '@angular/forms'; 5 | 6 | import { AppRoutingModule } from './app-routing.module'; 7 | import { AppComponent } from './app.component'; 8 | import { AddBookComponent } from './components/add-book/add-book.component'; 9 | import { BooksListComponent } from './components/books-list/books-list.component'; 10 | import { DashboardComponent } from './components/dashboard/dashboard.component'; 11 | import { DeleteBookComponent } from './components/delete-book/delete-book.component'; 12 | import { EditBookComponent } from './components/edit-book/edit-book.component'; 13 | import { FooterComponent } from './components/footer/footer.component'; 14 | import { PageNotfoundComponent } from './components/page-notfound/page-notfound.component'; 15 | import { SideNavbarComponent } from './components/side-navbar/side-navbar.component'; 16 | import { TopNavbarComponent } from './components/top-navbar/top-navbar.component'; 17 | 18 | @NgModule({ 19 | declarations: [ 20 | AppComponent, 21 | AddBookComponent, 22 | BooksListComponent, 23 | DashboardComponent, 24 | DeleteBookComponent, 25 | EditBookComponent, 26 | FooterComponent, 27 | PageNotfoundComponent, 28 | SideNavbarComponent, 29 | TopNavbarComponent 30 | ], 31 | imports: [ 32 | AppRoutingModule, 33 | BrowserModule, 34 | HttpClientModule, 35 | ReactiveFormsModule 36 | ], 37 | providers: [], 38 | bootstrap: [AppComponent] 39 | }) 40 | export class AppModule { } 41 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/components/delete-book/delete-book.component.ts: -------------------------------------------------------------------------------- 1 | import { ActivatedRoute, Router } from '@angular/router'; 2 | import { Component, NgZone, OnInit } from '@angular/core'; 3 | import { FormBuilder, FormGroup } from '@angular/forms'; 4 | 5 | import { BooksService } from '../../services/books.service'; 6 | import { IBookDto } from '../../interfaces/book.Dto'; 7 | 8 | @Component({ 9 | selector: 'app-delete-book', 10 | templateUrl: './delete-book.component.html', 11 | styleUrls: ['./delete-book.component.css'] 12 | }) 13 | export class DeleteBookComponent implements OnInit { 14 | 15 | deleteBookDto: IBookDto; 16 | deleteBookForm: FormGroup; 17 | 18 | constructor(private route: ActivatedRoute, private bookstoreService: BooksService, 19 | private ngZone: NgZone, private router: Router, private formBuilder: FormBuilder) { 20 | 21 | this.deleteBookForm = this.formBuilder.group({ 22 | dateOfPublish: '', 23 | language: '', 24 | author: '', 25 | title: '', 26 | id: '' 27 | }); 28 | } 29 | 30 | ngOnInit(): void { 31 | 32 | this.route.paramMap.subscribe(params => { 33 | 34 | this.bookstoreService.GetBookById(params.get('bookId')) 35 | .subscribe((deleteBookDto: IBookDto) => { 36 | 37 | this.deleteBookDto = deleteBookDto; 38 | console.log(`${this.deleteBookDto.title}`); 39 | }); 40 | }); 41 | } 42 | 43 | onBookstoreRemove(id: string): void { 44 | 45 | console.warn(`Product Delete Request for Id: ${id}`); 46 | 47 | this.bookstoreService.RemoveBookById(id).subscribe(res => { 48 | 49 | console.log('Book Deleted!') 50 | this.ngZone.run(() => this.router.navigateByUrl('/books')) 51 | }); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/components/add-book/add-book.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |

Add Book

4 |
5 |
6 | 7 | 8 |
9 |
10 | 11 |
12 | 13 | 14 |
15 | 16 |
17 | 18 | 19 |
20 | 21 |
22 | 23 | 24 |
25 | 26 |
27 | 28 | 29 |
30 | 31 | 33 | 35 | 36 |
37 | 38 |
39 |
40 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/components/edit-book/edit-book.component.ts: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import { ActivatedRoute, Router } from '@angular/router'; 4 | import { Component, NgZone, OnInit } from '@angular/core'; 5 | import { FormBuilder, FormGroup } from '@angular/forms'; 6 | 7 | import { BooksService } from '../../services/books.service'; 8 | import { IBookDto } from '../../interfaces/book.Dto'; 9 | 10 | @Component({ 11 | selector: 'app-edit-book', 12 | templateUrl: './edit-book.component.html', 13 | styleUrls: ['./edit-book.component.css'] 14 | }) 15 | export class EditBookComponent implements OnInit { 16 | 17 | editBookDto: IBookDto; 18 | editBookForm: FormGroup; 19 | 20 | constructor(private route: ActivatedRoute, private bookstoreService: BooksService, 21 | private ngZone: NgZone, private router: Router, private formBuilder: FormBuilder) { 22 | 23 | this.editBookForm = this.formBuilder.group({ 24 | dateOfPublish: '', 25 | language: '', 26 | author: '', 27 | title: '', 28 | id: '' 29 | }); 30 | } 31 | 32 | ngOnInit(): void { 33 | 34 | this.route.paramMap.subscribe(params => { 35 | 36 | this.bookstoreService.GetBookById(params.get('bookId')) 37 | .subscribe((editBookDto: IBookDto) => { 38 | 39 | this.editBookDto = editBookDto; 40 | console.log(`${this.editBookDto.title}`); 41 | }); 42 | }); 43 | } 44 | 45 | /* For Modify */ 46 | onBookEdit(id: string, bookstoreData: IBookDto): void { 47 | 48 | console.warn(`Book Edit Request for Id: ${id}`); 49 | 50 | this.bookstoreService.EditBookById(id, bookstoreData).subscribe(res => { 51 | 52 | console.log('Book Modified!') 53 | this.ngZone.run(() => this.router.navigateByUrl('/books')) 54 | }); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/components/dashboard/dashboard.component.html: -------------------------------------------------------------------------------- 1 |

Application Dashboard

2 | 3 |
4 |
5 |
6 |
Library
7 |
8 |
Books
9 |

Library Books Module. Add, View, Edit and Delete Books. The backend is Node JS + Express. It using Mongo Db for data store

10 | Books 11 |
12 |
13 |
14 |
15 |
16 |
University
17 |
18 |
Professors
19 |

College Professors Module. View, Edit and Delete Professors. The backend is .Net Core 3.1 with EF Core and SQL Server. It also uses Redis Cache.

20 | Coming Soon 21 |
22 |
23 |
24 |
25 | 26 |
27 |
28 |
29 |
Trading
30 |
31 |
Stock Ticker
32 |

Retrieving the Stock Price. Add, View, Edit and Delete Books. The backend is Node JS + Express. It using Mongo Db for data store

33 | Coming Soon 34 |
35 |
36 |
37 |
38 |
39 |
Students Enrollment
40 |
41 |
Students
42 |

Retrieving the Students. Add, View, Edit and Delete Books. The backend is Node JS + Express. It using Mongo Db for data store

43 | Coming Soon 44 |
45 |
46 |
47 |
48 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/components/edit-book/edit-book.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |

Edit Book

4 |
5 |
6 | 7 |
8 |
9 | 10 |
11 | 12 | 14 |
15 | 16 |
17 | 18 | 20 |
21 | 22 |
23 | 24 | 26 |
27 | 28 |
29 | 30 | 32 |
33 | 34 |
35 | 36 | 38 |
39 | 40 | 42 | 44 | 45 |
46 |
47 | 48 |
49 |
50 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/components/delete-book/delete-book.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |

Delete Book

4 |
5 |
6 | 7 |
8 |
10 | 11 |
12 | 13 | 15 |
16 | 17 |
18 | 19 | 21 |
22 | 23 |
24 | 25 | 27 |
28 | 29 |
30 | 31 | 33 |
34 | 35 |
36 | 37 | 39 |
40 | 41 | 43 | 45 | 46 |
47 |
48 | 49 |
50 |
51 | -------------------------------------------------------------------------------- /bookstore-webapi/tests/unit/app.spec.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const request = require('supertest'); 4 | const app = require('../../src/app'); 5 | const mockMongoDb = require('./__mocks__/MongoDbMock'); 6 | 7 | describe('Testing /src/app.js', () => { 8 | 9 | const apiServer = request(app); 10 | 11 | beforeAll(async () => await mockMongoDb.connect()); 12 | 13 | afterEach(async () => await mockMongoDb.clearDatabase()); 14 | 15 | afterAll(async () => await mockMongoDb.closeDatabase()); 16 | 17 | describe('Testing API Routes', () => { 18 | 19 | // "/" Routes 20 | describe('App :: "/" Routes', () => { 21 | 22 | const defaultMessage = 'Welcome to Books Web API.'; 23 | 24 | test('API Should return default response', async function (done) { 25 | const response = await apiServer.get('/api'); 26 | 27 | expect(response.status).toBe(200); 28 | expect(JSON.parse(response.text)).toBe(defaultMessage); 29 | 30 | done(); 31 | }); 32 | 33 | }); 34 | 35 | // "/api/books" Routes 36 | describe('Book Routers :: "/api/books" Routes', () => { 37 | 38 | const Book = require('../../src/models/book.Model'); 39 | 40 | const _book = { 41 | '_id': '5f0745314c16a3084cfa41fc', 42 | 'author': 'Dummy Author', 43 | 'title': 'Node JS', 44 | 'dateOfPublish': '01-Jan-2021', 45 | 'language': "JavaScript", 46 | 'read': false 47 | }; 48 | 49 | test('Book Router Should return 500 when invalid id is sent', async function (done) { 50 | const response = await apiServer.get('/api/books/InvalidId'); 51 | 52 | expect(response.status).toBe(500); 53 | 54 | done(); 55 | }); 56 | 57 | test('Book Router Should return 404 when no data available', async function (done) { 58 | const response = await apiServer.get('/api/books/5f0745314c16a3084cfa41fc'); 59 | 60 | expect(response.status).toBe(404); 61 | 62 | done(); 63 | }); 64 | 65 | test('Book Router Should return 200 when data available', async function (done) { 66 | Book.create(_book); 67 | 68 | const response = await apiServer.get('/api/books/5f0745314c16a3084cfa41fc'); 69 | 70 | expect(response.status).toBe(200); 71 | 72 | done(); 73 | }); 74 | 75 | }); 76 | 77 | }); 78 | 79 | }); 80 | -------------------------------------------------------------------------------- /bookstore-webapp/src/app/services/books.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { HttpClient, HttpHeaders } from '@angular/common/http'; 3 | import { Observable, throwError, from } from 'rxjs'; 4 | import { retry, catchError } from 'rxjs/operators'; 5 | 6 | import { IBookDto } from '../interfaces/book.Dto'; 7 | import { IAddBookDto } from '../interfaces/addBook.Dto'; 8 | 9 | const baseUrl = "http://localhost:4000/api"; 10 | const httpOptions = { 11 | headers: new HttpHeaders({ 12 | 'Content-Type': 'application/json', 13 | }), 14 | }; 15 | 16 | @Injectable({ 17 | providedIn: 'root' 18 | }) 19 | export class BooksService { 20 | 21 | constructor(private httpClient: HttpClient) { 22 | } 23 | 24 | // GET All Books 25 | GetAllBooks(): Observable { 26 | 27 | console.log(`Get All Books request received.`); 28 | 29 | return this.httpClient 30 | .get(`${baseUrl}/books`) 31 | .pipe(retry(1), catchError(this.errorHandler)); 32 | } 33 | 34 | // Retrieve Book By Id 35 | GetBookById(id: string): Observable { 36 | 37 | console.log(`Get Book request received for ${id}`); 38 | 39 | return this.httpClient 40 | .get(`${baseUrl}/books/${id}`) 41 | .pipe(retry(1), catchError(this.errorHandler)); 42 | } 43 | 44 | //Add Book 45 | AddBooks(bookstore: IAddBookDto): Observable { 46 | 47 | console.log(`Adding New Book: ${JSON.stringify(bookstore)}`); 48 | 49 | return this.httpClient 50 | .post(`${baseUrl}/books`, JSON.stringify(bookstore), httpOptions) 51 | .pipe( 52 | retry(1), 53 | catchError(this.errorHandler) 54 | ) 55 | } 56 | 57 | // Edit Book By Id 58 | EditBookById(id: string, bookstore: IBookDto) { 59 | 60 | console.log(`Edit Book request received for ${id} ${JSON.stringify(bookstore)}`); 61 | 62 | return this.httpClient 63 | .put(`${baseUrl}/books/${id}`, JSON.stringify(bookstore), httpOptions) 64 | .pipe(retry(1), catchError(this.errorHandler)); 65 | } 66 | 67 | RemoveBookById(id: string) { 68 | console.log(`Removed Book request received for ${id}`); 69 | return this.httpClient.delete(`${baseUrl}/books/${id}`, httpOptions) 70 | .pipe( 71 | retry(1), 72 | catchError(this.errorHandler) 73 | ) 74 | } 75 | 76 | // Error handling 77 | errorHandler(error) { 78 | 79 | let errorMessage = ''; 80 | if (error.error instanceof ErrorEvent) { 81 | // Get client-side error 82 | errorMessage = error.error.message; 83 | } else { 84 | // Get server-side error 85 | errorMessage = `Error Code: ${error.status}\nMessage: ${error.message}`; 86 | } 87 | console.log(errorMessage); 88 | return throwError(errorMessage); 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /bookstore-webapi/tests/unit/book-Router.spec.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const sinon = require('sinon'); 4 | const proxyquire = require('proxyquire') 5 | const httpMock = require('node-mocks-http'); 6 | 7 | describe('Testing /src/routes/bookRouter.js', () => { 8 | 9 | let expressStub, controllerStub, RouterStub, rootRouteStub, idRouteStub 10 | let request, response, next; 11 | 12 | describe('router', () => { 13 | 14 | beforeEach(() => { 15 | 16 | rootRouteStub = { 17 | "get": sinon.stub().callsFake(() => rootRouteStub), 18 | "post": sinon.stub().callsFake(() => rootRouteStub) 19 | }; 20 | 21 | idRouteStub = { 22 | "get": sinon.stub().callsFake(() => idRouteStub), 23 | "use": sinon.stub().callsFake(() => idRouteStub) 24 | }; 25 | 26 | RouterStub = { 27 | route: sinon.stub().callsFake((route) => { 28 | if (route === '/books/:bookId') { 29 | return idRouteStub 30 | } 31 | return rootRouteStub 32 | }) 33 | }; 34 | 35 | expressStub = { 36 | Router: sinon.stub().returns(RouterStub) 37 | }; 38 | 39 | controllerStub = { 40 | post: sinon.mock(), 41 | get: sinon.mock(), 42 | getBookById: sinon.mock() 43 | }; 44 | 45 | proxyquire('../../src/routes/book-Router.js', 46 | { 47 | 'express': expressStub, 48 | '../controllers/books.Controller.js': controllerStub 49 | } 50 | ); 51 | 52 | request = httpMock.createRequest(); 53 | response = httpMock.createResponse(); 54 | next = sinon.mock(); 55 | 56 | }); 57 | 58 | test('should map root get() router with controller::get()', () => { 59 | 60 | rootRouteStub.get('/books', controllerStub.get); 61 | 62 | expect(RouterStub.route.calledWith('/books')); 63 | expect(rootRouteStub.get.calledWith(controllerStub.get)); 64 | }); 65 | 66 | test('should map root getBookById() router with controller::getBookById()', () => { 67 | 68 | idRouteStub.use('/books/:bookId', (request, response, next) => { }); 69 | 70 | idRouteStub.get('/books/:bookId', controllerStub.getBookById); 71 | 72 | expect(RouterStub.route.calledWith('/books/:bookId')); 73 | expect(idRouteStub.get.calledWith(controllerStub.getBookById)); 74 | }); 75 | 76 | test('should map root post() router with controller::post()', () => { 77 | 78 | rootRouteStub.post('/books', controllerStub.post); 79 | 80 | expect(RouterStub.route.calledWith('/books')); 81 | expect(rootRouteStub.post.calledWith(controllerStub.post)); 82 | 83 | }); 84 | 85 | }); 86 | 87 | }); 88 | 89 | -------------------------------------------------------------------------------- /bookstore-webapp/src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 22 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 23 | 24 | /** 25 | * Web Animations `@angular/platform-browser/animations` 26 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 27 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 28 | */ 29 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 30 | 31 | /** 32 | * By default, zone.js will patch all possible macroTask and DomEvents 33 | * user can disable parts of macroTask/DomEvents patch by setting following flags 34 | * because those flags need to be set before `zone.js` being loaded, and webpack 35 | * will put import in the top of bundle, so user need to create a separate file 36 | * in this directory (for example: zone-flags.ts), and put the following flags 37 | * into that file, and then add the following code before importing zone.js. 38 | * import './zone-flags'; 39 | * 40 | * The flags allowed in zone-flags.ts are listed here. 41 | * 42 | * The following flags will work for all browsers. 43 | * 44 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 45 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 46 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 47 | * 48 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 49 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 50 | * 51 | * (window as any).__Zone_enable_cross_context_check = true; 52 | * 53 | */ 54 | 55 | /*************************************************************************************************** 56 | * Zone JS is required by default for Angular itself. 57 | */ 58 | import 'zone.js/dist/zone'; // Included with Angular CLI. 59 | 60 | 61 | /*************************************************************************************************** 62 | * APPLICATION IMPORTS 63 | */ 64 | -------------------------------------------------------------------------------- /bookstore-webapi/src/controllers/books.Controller.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const bookSchemaValidator = require('../models/book.SchemaValidator'); 4 | 5 | function booksController(Book) { 6 | 7 | async function post(request, response) { 8 | 9 | console.log(`Input Received: ${JSON.stringify(request.body)}`); 10 | 11 | // We need to verify both Author Name and Title 12 | const isBookValid = bookSchemaValidator.validate(request.body); 13 | 14 | if (isBookValid.error) { 15 | console.log("validation result", isBookValid); 16 | return response.status(400).json(isBookValid.error); 17 | } 18 | 19 | // Verify if book's title with same author already exists. 20 | const similarBookExist = await Book.findOne({ author: request.body.author, title: request.body.title, language: request.body.language }); 21 | 22 | if (similarBookExist) { 23 | console.log(`Does Similar Book Exists: ${similarBookExist}`); 24 | return response.status(400).json(`Book with "${request.body.title}" title exists from "${request.body.author}" author.`); 25 | } 26 | 27 | try { 28 | const book = await (Book.create(request.body)) 29 | 30 | console.log(`Sending Output: ${JSON.stringify(book)}`); 31 | return response.status(201).json(book); 32 | 33 | } catch (error) { 34 | return response.status(500).json(error); 35 | } 36 | 37 | } 38 | 39 | async function get(request, response) { 40 | try { 41 | 42 | const allBooks = await Book.find({}); 43 | 44 | if (allBooks && allBooks.length > 0) { 45 | return response.status(200).json(allBooks); 46 | } else { 47 | return response.status(404).json(); 48 | } 49 | 50 | } catch (error) { 51 | return response.status(500).json(error); 52 | } 53 | } 54 | 55 | async function getBookById(request, response) { 56 | return response.status(200).json(request.book); 57 | } 58 | 59 | async function updateBookById(request, response) { 60 | 61 | console.log(`Book Id: ${JSON.parse(JSON.stringify(request.book))._id} | Complete Book: ${JSON.stringify(request.book)}`); 62 | 63 | Book.findByIdAndUpdate(request.params.bookId, request.body, { 64 | new: true, 65 | useFindAndModify: false, 66 | runValidators: true 67 | }, 68 | function (error, book) { 69 | if (error) { 70 | return response.status(500).json(error); 71 | } else { 72 | return response.status(200).json({ 'success': true, 'Message': 'Book updated Successfully', data: book }); 73 | } 74 | }); 75 | 76 | } 77 | 78 | async function deleteBookById(request, response) { 79 | 80 | console.log(`Book Id: ${JSON.parse(JSON.stringify(request.book))._id} | Completed Book: ${JSON.stringify(request.book)}`); 81 | 82 | Book.findByIdAndDelete(request.book._id, function (error, book) { 83 | if (error) { 84 | return response.status(500).json(error); 85 | } 86 | else { 87 | return response.status(204).json({ 'success': true, 'Message': 'Book Deleted Successfully' }); 88 | } 89 | }); 90 | 91 | } 92 | 93 | return { post, get, getBookById, updateBookById, deleteBookById }; 94 | } 95 | 96 | module.exports = booksController; 97 | -------------------------------------------------------------------------------- /bookstore-webapp/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:recommended", 3 | "rules": { 4 | "align": { 5 | "options": [ 6 | "parameters", 7 | "statements" 8 | ] 9 | }, 10 | "array-type": false, 11 | "arrow-return-shorthand": true, 12 | "curly": true, 13 | "deprecation": { 14 | "severity": "warning" 15 | }, 16 | "component-class-suffix": true, 17 | "contextual-lifecycle": true, 18 | "directive-class-suffix": true, 19 | "directive-selector": [ 20 | true, 21 | "attribute", 22 | "app", 23 | "camelCase" 24 | ], 25 | "component-selector": [ 26 | true, 27 | "element", 28 | "app", 29 | "kebab-case" 30 | ], 31 | "eofline": true, 32 | "import-blacklist": [ 33 | true, 34 | "rxjs/Rx" 35 | ], 36 | "import-spacing": true, 37 | "indent": { 38 | "options": [ 39 | "spaces" 40 | ] 41 | }, 42 | "max-classes-per-file": false, 43 | "max-line-length": [ 44 | true, 45 | 140 46 | ], 47 | "member-ordering": [ 48 | true, 49 | { 50 | "order": [ 51 | "static-field", 52 | "instance-field", 53 | "static-method", 54 | "instance-method" 55 | ] 56 | } 57 | ], 58 | "no-console": [ 59 | true, 60 | "debug", 61 | "info", 62 | "time", 63 | "timeEnd", 64 | "trace" 65 | ], 66 | "no-empty": false, 67 | "no-inferrable-types": [ 68 | true, 69 | "ignore-params" 70 | ], 71 | "no-non-null-assertion": true, 72 | "no-redundant-jsdoc": true, 73 | "no-switch-case-fall-through": true, 74 | "no-var-requires": false, 75 | "object-literal-key-quotes": [ 76 | true, 77 | "as-needed" 78 | ], 79 | "quotemark": [ 80 | true, 81 | "single" 82 | ], 83 | "semicolon": { 84 | "options": [ 85 | "always" 86 | ] 87 | }, 88 | "space-before-function-paren": { 89 | "options": { 90 | "anonymous": "never", 91 | "asyncArrow": "always", 92 | "constructor": "never", 93 | "method": "never", 94 | "named": "never" 95 | } 96 | }, 97 | "typedef": [ 98 | true, 99 | "call-signature" 100 | ], 101 | "typedef-whitespace": { 102 | "options": [ 103 | { 104 | "call-signature": "nospace", 105 | "index-signature": "nospace", 106 | "parameter": "nospace", 107 | "property-declaration": "nospace", 108 | "variable-declaration": "nospace" 109 | }, 110 | { 111 | "call-signature": "onespace", 112 | "index-signature": "onespace", 113 | "parameter": "onespace", 114 | "property-declaration": "onespace", 115 | "variable-declaration": "onespace" 116 | } 117 | ] 118 | }, 119 | "variable-name": { 120 | "options": [ 121 | "ban-keywords", 122 | "check-format", 123 | "allow-pascal-case" 124 | ] 125 | }, 126 | "whitespace": { 127 | "options": [ 128 | "check-branch", 129 | "check-decl", 130 | "check-operator", 131 | "check-separator", 132 | "check-type", 133 | "check-typecast" 134 | ] 135 | }, 136 | "no-conflicting-lifecycle": true, 137 | "no-host-metadata-property": true, 138 | "no-input-rename": true, 139 | "no-inputs-metadata-property": true, 140 | "no-output-native": true, 141 | "no-output-on-prefix": true, 142 | "no-output-rename": true, 143 | "no-outputs-metadata-property": true, 144 | "template-banana-in-box": true, 145 | "template-no-negated-async": true, 146 | "use-lifecycle-interface": true, 147 | "use-pipe-transform-interface": true 148 | }, 149 | "rulesDirectory": [ 150 | "codelyzer" 151 | ] 152 | } -------------------------------------------------------------------------------- /bookstore-webapp/angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "bookstore-webapp": { 7 | "projectType": "application", 8 | "schematics": {}, 9 | "root": "", 10 | "sourceRoot": "src", 11 | "prefix": "app", 12 | "architect": { 13 | "build": { 14 | "builder": "@angular-devkit/build-angular:browser", 15 | "options": { 16 | "outputPath": "dist/bookstore-webapp", 17 | "index": "src/index.html", 18 | "main": "src/main.ts", 19 | "polyfills": "src/polyfills.ts", 20 | "tsConfig": "tsconfig.app.json", 21 | "aot": true, 22 | "assets": [ 23 | "src/favicon.ico", 24 | "src/assets" 25 | ], 26 | "styles": [ 27 | "src/styles.css", 28 | "./node_modules/font-awesome/css/font-awesome.css", 29 | "./node_modules/bootstrap/dist/css/bootstrap.css" 30 | ], 31 | "scripts": [ 32 | "./node_modules/jquery/dist/jquery.js", 33 | "./node_modules/popper.js/dist/umd/popper.js", 34 | "./node_modules/bootstrap/dist/js/bootstrap.js" 35 | ] 36 | }, 37 | "configurations": { 38 | "production": { 39 | "fileReplacements": [ 40 | { 41 | "replace": "src/environments/environment.ts", 42 | "with": "src/environments/environment.prod.ts" 43 | } 44 | ], 45 | "optimization": true, 46 | "outputHashing": "all", 47 | "sourceMap": false, 48 | "extractCss": true, 49 | "namedChunks": false, 50 | "extractLicenses": true, 51 | "vendorChunk": false, 52 | "buildOptimizer": true, 53 | "budgets": [ 54 | { 55 | "type": "initial", 56 | "maximumWarning": "2mb", 57 | "maximumError": "5mb" 58 | }, 59 | { 60 | "type": "anyComponentStyle", 61 | "maximumWarning": "6kb", 62 | "maximumError": "10kb" 63 | } 64 | ] 65 | } 66 | } 67 | }, 68 | "serve": { 69 | "builder": "@angular-devkit/build-angular:dev-server", 70 | "options": { 71 | "browserTarget": "bookstore-webapp:build", 72 | "port": 5003 73 | }, 74 | "configurations": { 75 | "production": { 76 | "browserTarget": "bookstore-webapp:build:production" 77 | } 78 | } 79 | }, 80 | "extract-i18n": { 81 | "builder": "@angular-devkit/build-angular:extract-i18n", 82 | "options": { 83 | "browserTarget": "bookstore-webapp:build" 84 | } 85 | }, 86 | "test": { 87 | "builder": "@angular-devkit/build-angular:karma", 88 | "options": { 89 | "main": "src/test.ts", 90 | "polyfills": "src/polyfills.ts", 91 | "tsConfig": "tsconfig.spec.json", 92 | "karmaConfig": "karma.conf.js", 93 | "assets": [ 94 | "src/favicon.ico", 95 | "src/assets" 96 | ], 97 | "styles": [ 98 | "src/styles.css" 99 | ], 100 | "scripts": [] 101 | } 102 | }, 103 | "lint": { 104 | "builder": "@angular-devkit/build-angular:tslint", 105 | "options": { 106 | "tsConfig": [ 107 | "tsconfig.app.json", 108 | "tsconfig.spec.json", 109 | "e2e/tsconfig.json" 110 | ], 111 | "exclude": [ 112 | "**/node_modules/**" 113 | ] 114 | } 115 | }, 116 | "e2e": { 117 | "builder": "@angular-devkit/build-angular:protractor", 118 | "options": { 119 | "protractorConfig": "e2e/protractor.conf.js", 120 | "devServerTarget": "bookstore-webapp:serve" 121 | }, 122 | "configurations": { 123 | "production": { 124 | "devServerTarget": "bookstore-webapp:serve:production" 125 | } 126 | } 127 | } 128 | } 129 | } 130 | }, 131 | "defaultProject": "bookstore-webapp", 132 | "cli": { 133 | "analytics": "3ca1c347-709d-4f19-87e5-822d599aa016" 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /bookstore-webapi/tests/unit/books.Controller.spec.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const Book = require('../../src/models/book.Model'); 4 | const booksController = require('../../src/controllers/books.Controller')(Book); 5 | const httpMock = require('node-mocks-http'); 6 | 7 | describe('Testing books.Controller /src/controllers/books.Controller.js', () => { 8 | 9 | // Variables. 10 | let request, response; 11 | 12 | const _book = { 13 | 'author': 'Dummy Author', 14 | 'title': 'Node JS', 15 | 'dateOfPublish': '01-Jan-2020', 16 | 'language': "JavaScript", 17 | 'read': false 18 | }; 19 | 20 | const _bookInvalid = { 21 | title: 'Node JS', 22 | dateOfPublish: '01-Jan-2020', 23 | language: "JavaScript", 24 | read: false 25 | }; 26 | 27 | const _bookExists = { 28 | dateOfPublish: '2020 - 07 - 07T03: 37: 43.000Z', 29 | language: 'Python', 30 | read: false, 31 | _id: '5f03ee290d4b4a1198c4e1e8', 32 | author: 'Viswanatha Swamy', 33 | title: '4th Book', 34 | __v: 0 35 | }; 36 | 37 | beforeEach(() => { 38 | request = httpMock.createRequest(); 39 | response = httpMock.createResponse(); 40 | 41 | request.book = _book; 42 | Book.find = jest.fn(); 43 | }); 44 | 45 | afterEach(() => { 46 | Book.find.mockClear(); 47 | 48 | request.book = {}; 49 | }); 50 | 51 | // getBookById() return 200 52 | describe('Books Controller :: getBookById()', () => { 53 | 54 | test('getBookById() function is defined', async (done) => { 55 | 56 | expect(typeof booksController.getBookById).toBe('function'); 57 | 58 | done(); 59 | }); 60 | 61 | test('getBookById() function should return 200', async (done) => { 62 | 63 | await booksController.getBookById(request, response); 64 | 65 | expect(response.statusCode).toBe(200); 66 | expect(response._getJSONData()).toStrictEqual(_book); 67 | 68 | done(); 69 | }); 70 | 71 | }); 72 | 73 | // get() Returns all the books. 200, 404 OR 500 74 | describe('Books Controller :: get()', () => { 75 | 76 | test('get() function is defined', async () => { 77 | 78 | expect(typeof booksController.get).toBe('function'); 79 | 80 | }); 81 | 82 | test('get() function should return 404', async (done) => { 83 | 84 | Book.find = jest.fn().mockReturnValue([]); 85 | 86 | await booksController.get(request, response); 87 | 88 | expect(response.statusCode).toBe(404); 89 | 90 | done(); 91 | }); 92 | 93 | test('get() function should return 200', async (done) => { 94 | Book.find = jest.fn().mockResolvedValue([_book]); 95 | 96 | await booksController.get(request, response); 97 | 98 | expect(response.statusCode).toBe(200); 99 | 100 | done(); 101 | }); 102 | 103 | test('get() function should return 500', async (done) => { 104 | Book.find = jest.fn().mockRejectedValue('Dummy Error'); 105 | 106 | await booksController.get(request, response); 107 | 108 | expect(response.statusCode).toBe(500); 109 | 110 | done(); 111 | }); 112 | 113 | }); 114 | 115 | // post() return 200, 400, and 500 116 | describe('Books Controller :: post()', () => { 117 | 118 | test('post() function is defined', async (done) => { 119 | 120 | expect(typeof booksController.post).toBe('function'); 121 | 122 | done(); 123 | }); 124 | 125 | test('post() function should return 400 when Invalid request is sent', async (done) => { 126 | 127 | request.body = _bookInvalid; 128 | 129 | await booksController.post(request, response); 130 | 131 | expect(response.statusCode).toBe(400); 132 | 133 | done(); 134 | }); 135 | 136 | test('post() function should return 400 when record already exists', async (done) => { 137 | 138 | request.body = _book; 139 | 140 | Book.findOne = jest.fn().mockReturnValue(_bookExists); 141 | 142 | await booksController.post(request, response); 143 | 144 | expect(response.statusCode).toBe(400); 145 | 146 | console.log(`Response: ${JSON.stringify(response._getJSONData())}`); 147 | 148 | done(); 149 | }); 150 | 151 | test('post() function should return 201 when record does not exists', async (done) => { 152 | 153 | request.body = _book; 154 | 155 | Book.findOne = jest.fn().mockReturnValue(null); 156 | Book.create = jest.fn().mockReturnValue(_book); 157 | 158 | await booksController.post(request, response); 159 | 160 | expect(response.statusCode).toBe(201); 161 | 162 | done(); 163 | }); 164 | 165 | test('post() function should return 500 when it fail to create', async (done) => { 166 | 167 | request.body = _book; 168 | 169 | Book.findOne = jest.fn().mockReturnValue(null); 170 | Book.create = jest.fn().mockRejectedValue('Unable to save'); 171 | 172 | await booksController.post(request, response); 173 | 174 | expect(response.statusCode).toBe(500); 175 | 176 | done(); 177 | }); 178 | 179 | }); 180 | 181 | }); 182 | 183 | // console.log(`Response: ${JSON.stringify(response)}`); 184 | // expect(response._getJSONData()).toStrictEqual(_book); 185 | // console.log(`Request.Book: ${JSON.stringify(request.book)}`); 186 | // expect(response._getJSONData()).toStrictEqual(_book); 187 | // console.log(`Response: ${JSON.stringify(response._getJSONData())}`); 188 | // console.log(`Response: ${JSON.stringify(response._getJSONData())}`); 189 | // console.log(`Response: ${JSON.stringify(response._getJSONData())}`); 190 | // console.log(`Output Received: ${JSON.stringify(response._getJSONData())}`); --------------------------------------------------------------------------------