-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c061bd4
commit 7b33c04
Showing
15 changed files
with
307 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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:[email protected]:21339/videoplayer"; | ||
//const db = "mongodb://hisan:[email protected]: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); | ||
} | ||
}); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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:[email protected]: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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<div class="row"> | ||
<div class = "col-md-12" id="loadSection"> | ||
<div class="table-responsive"> | ||
<!-- <button type="button" class="btn btn-md main-color-bg" data-toggle="modal" data-target="#addItem"> | ||
<span class="glyphicon glyphicon-plus-sign"> Add | ||
</button> --> | ||
<br><br> | ||
<table class="table table-bordered" id="item_table"> | ||
<thead> | ||
<tr> | ||
<td width="20%">Name</td> | ||
<td width="40%">Description</td> | ||
<td width="10%">Price (Rs)</td> | ||
<td width="10%">Image</td> | ||
<td width="10%"></td> | ||
<td width="10%"></td> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
|
||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<BooksComponent>; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ BooksComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(BooksComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() { | ||
} | ||
|
||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<div class="row"> | ||
<div class="col-sm-9"> | ||
<div *ngIf= "!hidenewLab"> | ||
<h2>New Lab</h2> | ||
<form #form="ngForm" (ngSubmit)= "onSubmitAddLab(form.value)" class="well"> | ||
<div class="form-group"> | ||
<label>Name</label> | ||
<input type="text" class="form-control" required name="name" ngModel> | ||
</div> | ||
<div class="form-group"> | ||
<label>Description</label> | ||
<input type="text" class="form-control" required name="description" ngModel> | ||
</div> | ||
<div class="form-group"> | ||
<label>Location</label> | ||
<input type="text" class="form-control" name="location" ngModel> | ||
</div> | ||
<button type="submit" class="btn btn-success">Save</button> | ||
</form> | ||
</div> | ||
<video-detail (updateLabEvent)="onUpdateLabEvent($event)" (deleteLabEvent)="onDeleteLabEvent($event)" *ngIf="selectedLab && hidenewLab" [video]="selectedVideo"></video-detail> | ||
</div> | ||
<div class="col-sm-3"> | ||
<button style="margin-bottom:2px;" (click)="newVideo()" type="button" class="btn btn-success btn-block">+ New Video</button> | ||
<video-list (SelectVideo)="onSelectVideo($event)" [videos]="videos"></video-list> | ||
</div> | ||
</div> | ||
|
Oops, something went wrong.