diff --git a/server/models/book.js b/server/models/book.js new file mode 100644 index 0000000..57c770f --- /dev/null +++ b/server/models/book.js @@ -0,0 +1,15 @@ +const mongoose = require('mongoose'); + +const Schema = mongoose.Schema; + +const bookSchema = new Schema({ + isbn: Number, + name: String, + category: String, + author: String, + publisher: String, + edition: Number, + noOfCopies: Number +}); + +module.exports = mongoose.model('book', bookSchema, 'books'); \ No newline at end of file diff --git a/server/models/lab.js b/server/models/lab.js new file mode 100644 index 0000000..fb51e1d --- /dev/null +++ b/server/models/lab.js @@ -0,0 +1,13 @@ +const mongoose = require('mongoose'); + +const Schema = mongoose.Schema; + +const labSchema = new Schema({ + name: String, + description: String, + location: String, + noOfComputers: Number, + projector: String +}); + +module.exports = mongoose.model('lab', labSchema, 'labs'); \ No newline at end of file diff --git a/server/routes/api.js b/server/routes/api.js index 56c3ccf..e8c5409 100644 --- a/server/routes/api.js +++ b/server/routes/api.js @@ -2,9 +2,10 @@ const express = require('express'); const router = express.Router(); const mongoose = require('mongoose'); -const Video = require('../models/video'); +const Book = require('../models/book'); -const db = "mongodb://hisan:Sacrificer1!@ds221339.mlab.com:21339/videoplayer"; +//const db = "mongodb://hisan:Sacrificer1!@ds221339.mlab.com:21339/videoplayer"; +const db = "mongodb://localhost:27017/library"; mongoose.Promise = global.Promise; mongoose.connect(db, function(err){ @@ -14,50 +15,58 @@ mongoose.connect(db, function(err){ } }); -router.get('/videos', function(req, res){ - console.log("Get request for all videos"); - Video.find({}) - .exec(function(err, videos){ +router.get('/', function(req,res){ + res.send('api works'); +}) + +router.get('/books', function(req, res){ + console.log("Get request for all books"); + Book.find({}) + .exec(function(err, books){ if(err) { - console.log("Error retrieving videos"); + console.log("Error retrieving books"); } else { - res.json(videos); + res.json(books); } }); }); -router.get('/videos/:id', function(req, res){ - console.log("Get request for a single video"); - Video.findById(req.params.id) - .exec(function(err, video){ +router.get('/books/:id', function(req, res){ + console.log("Get request for a single book"); + Book.findById(req.params.id) + .exec(function(err, book){ if(err) { - console.log("Error retrieving video"); + console.log("Error retrieving book"); } else { - res.json(video); + res.json(book); } }); }); -router.post('/video', function(req, res){ - console.log("Post a Video"); - var newVideo = new Video(); - newVideo.title = req.body.title; - newVideo.url = req.body.url; - newVideo.description = req.body.description; - newVideo.save(function(err, insertedVideo){ +router.post('/book', function(req, res){ + console.log("Post a Book"); + var newBook = new Book(); + newBook.isbn = req.body.isbn; + newBook.name = req.body.name; + newBook.category = req.body.category; + newBook.author = req.body.author; + newBook.publisher = req.body.publisher; + newBook.edition = req.body.edition; + newBook.noOfCopies = req.body.noOfCopies; + newBook.save(function(err, insertedBook){ if(err) { - console.log("Error saving video"); + console.log("Error saving book"); } else { - res.json(insertedVideo); + res.json(insertedBook); } }); }); diff --git a/server/routes/api2.js b/server/routes/api2.js new file mode 100644 index 0000000..454d622 --- /dev/null +++ b/server/routes/api2.js @@ -0,0 +1,106 @@ +const express = require('express'); +const router = express.Router(); + +const mongoose = require('mongoose'); +const Video = require('../models/video'); + +//const db = "mongodb://hisan:Sacrificer1!@ds221339.mlab.com:21339/videoplayer"; +const db = "mongodb://localhost:27017/library"; +mongoose.Promise = global.Promise; + +mongoose.connect(db, function(err){ + if(err) + { + console.error("Error : " + err); + } +}); + +router.get('/videos', function(req, res){ + console.log("Get request for all videos"); + Video.find({}) + .exec(function(err, videos){ + if(err) + { + console.log("Error retrieving videos"); + } + else + { + res.json(videos); + } + }); +}); + +router.get('/videos/:id', function(req, res){ + console.log("Get request for a single video"); + Video.findById(req.params.id) + .exec(function(err, video){ + if(err) + { + console.log("Error retrieving video"); + } + else + { + res.json(video); + } + }); +}); + +router.post('/video', function(req, res){ + console.log("Post a Video"); + var newVideo = new Video(); + newVideo.title = req.body.title; + newVideo.url = req.body.url; + newVideo.description = req.body.description; + newVideo.save(function(err, insertedVideo){ + if(err) + { + console.log("Error saving video"); + } + else + { + res.json(insertedVideo); + } + }); +}); + +router.put('/video/:id', function(req, res){ + console.log("Update a Video"); + Video.findByIdAndUpdate(req.params.id, + { + $set: {title: req.body.title, url: req.body.url, description: req.body.description} + }, + { + new: true + }, + function(err, insertedVideo) + { + if(err) + { + res.send("Error Updating video"); + } + else + { + res.json(insertedVideo); + } + } + ); +}); + +router.delete('/video/:id', function(req, res){ + console.log("Delete a Video"); + Video.findByIdAndRemove(req.params.id, + function(err, deletedVideo) + { + if(err) + { + res.send("Error Deleting video"); + } + else + { + res.json(deletedVideo); + } + } + ); +}); + +module.exports = router; \ No newline at end of file diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 35ce8ac..06a3188 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -1,12 +1,12 @@ import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; import { HomeComponent } from './home/home.component'; -import { VideoCenterComponent } from './video-center/video-center.component'; +import { BooksComponent } from './books/books.component'; const routes: Routes = [ {path: '', redirectTo:'/home', pathMatch:'full'}, {path: 'home', component: HomeComponent}, - {path: 'videos', component: VideoCenterComponent} + {path: 'books', component: BooksComponent} ]; @NgModule({ diff --git a/src/app/app.component.html b/src/app/app.component.html index 04a9020..c5c1cf9 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -25,7 +25,7 @@

Angular bl diff --git a/src/app/app.module.ts b/src/app/app.module.ts index bd0e76b..560c25c 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -10,6 +10,8 @@ import { VideoCenterComponent } from './video-center/video-center.component'; import { VideoListComponent } from './video-list/video-list.component'; import { VideoDetailComponent } from './video-detail/video-detail.component'; import { SafePipe } from './safe.pipe'; +import { LabCenterComponent } from './lab-center/lab-center.component'; +import { BooksComponent } from './books/books.component'; @NgModule({ declarations: [ @@ -18,7 +20,9 @@ import { SafePipe } from './safe.pipe'; VideoCenterComponent, VideoListComponent, VideoDetailComponent, - SafePipe + SafePipe, + LabCenterComponent, + BooksComponent ], imports: [ BrowserModule, diff --git a/src/app/books/books.component.css b/src/app/books/books.component.css new file mode 100644 index 0000000..e69de29 diff --git a/src/app/books/books.component.html b/src/app/books/books.component.html new file mode 100644 index 0000000..42bb472 --- /dev/null +++ b/src/app/books/books.component.html @@ -0,0 +1,25 @@ +
+
+
+ +

+ + + + + + + + + + + + + + +
NameDescriptionPrice (Rs)Image
+
+
+
\ No newline at end of file diff --git a/src/app/books/books.component.spec.ts b/src/app/books/books.component.spec.ts new file mode 100644 index 0000000..13067ba --- /dev/null +++ b/src/app/books/books.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { BooksComponent } from './books.component'; + +describe('BooksComponent', () => { + let component: BooksComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ BooksComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(BooksComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/books/books.component.ts b/src/app/books/books.component.ts new file mode 100644 index 0000000..94640e9 --- /dev/null +++ b/src/app/books/books.component.ts @@ -0,0 +1,15 @@ +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'books', + templateUrl: './books.component.html', + styleUrls: ['./books.component.css'] +}) +export class BooksComponent implements OnInit { + + constructor() { } + + ngOnInit() { + } + +} diff --git a/src/app/lab-center/lab-center.component.css b/src/app/lab-center/lab-center.component.css new file mode 100644 index 0000000..e69de29 diff --git a/src/app/lab-center/lab-center.component.html b/src/app/lab-center/lab-center.component.html new file mode 100644 index 0000000..02c709f --- /dev/null +++ b/src/app/lab-center/lab-center.component.html @@ -0,0 +1,28 @@ +
+
+
+

New Lab

+
+
+ + +
+
+ + +
+
+ + +
+ +
+
+ +
+
+ + +
+
+ diff --git a/src/app/lab-center/lab-center.component.spec.ts b/src/app/lab-center/lab-center.component.spec.ts new file mode 100644 index 0000000..f43d5e8 --- /dev/null +++ b/src/app/lab-center/lab-center.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { LabCenterComponent } from './lab-center.component'; + +describe('LabCenterComponent', () => { + let component: LabCenterComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ LabCenterComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(LabCenterComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/lab-center/lab-center.component.ts b/src/app/lab-center/lab-center.component.ts new file mode 100644 index 0000000..d734fb6 --- /dev/null +++ b/src/app/lab-center/lab-center.component.ts @@ -0,0 +1,15 @@ +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'app-lab-center', + templateUrl: './lab-center.component.html', + styleUrls: ['./lab-center.component.css'] +}) +export class LabCenterComponent implements OnInit { + + constructor() { } + + ngOnInit() { + } + +}