-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const books = [{ | ||
ISBN:"1234BOOK", | ||
title:"Getting started with MERN", | ||
pubDate:"20201-07-07", | ||
language:"en", | ||
numPage:250, | ||
author:[1, 2], | ||
publication:[1], | ||
category:["tech", "programing", "education", "triller"], | ||
}, | ||
]; | ||
|
||
const author = [ | ||
{ | ||
id:1, | ||
name:"Adi", | ||
books:["1234BOOK"] | ||
}, | ||
{ | ||
id:2, | ||
name:"Elon Musk", | ||
books:["1234BOOK"] | ||
}, | ||
]; | ||
|
||
const publication = [ | ||
{ | ||
id:1, | ||
name:"Writex", | ||
books:["1234BOOK"] | ||
} | ||
]; | ||
|
||
module.exports = {books, author, publication}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
const { json } = require("express"); | ||
const express = require("express"); | ||
|
||
//Database | ||
const database = require("./database"); | ||
|
||
// Initialization | ||
const booky = express(); | ||
|
||
|
||
/* | ||
Route / | ||
Discription Get all books | ||
Access Public | ||
Parameter None | ||
Method GET | ||
*/ | ||
booky.get("/", (req, res) => { | ||
return res.json({ books: database.books }); | ||
}); | ||
|
||
|
||
/* | ||
Route /is | ||
Discription Get specific books based on ISBN | ||
Access Public | ||
Parameter isbn | ||
Method GET | ||
*/ | ||
booky.get("/is/:isbn", (req, res) => { | ||
const getSpecificBook = database.books.filter( | ||
(book) => book.ISBN === req.params.isbn | ||
); | ||
if (getSpecificBook.length === 0) { | ||
return res.json({error:`No book found for the ISBN of ${req.params.isbn}`,}); | ||
} | ||
|
||
return res.json({book: getSpecificBook}); | ||
}); | ||
|
||
|
||
|
||
/* | ||
Route /c | ||
Discription Get specific books based on category | ||
Access Public | ||
Parameter category | ||
Method GET | ||
*/ | ||
booky.get("/c/:category", (req, res) => { | ||
const getSpecificBook = database.books.filter( | ||
(book) => book.category.includes(req.params.category) | ||
); | ||
|
||
if (getSpecificBook.length === 0) { | ||
return res.json({error:`No book found for the category of ${req.params.category}`,}); | ||
} | ||
|
||
return res.json({book: getSpecificBook}); | ||
}); | ||
|
||
/* | ||
Route /lan | ||
Discription Get specific books based on language | ||
Access Public | ||
Parameter lan | ||
Method GET | ||
*/ | ||
booky.get("/lan/:language", (req, res) => { | ||
const getSpecificBook = database.books.filter( | ||
(book) => book.language.includes(req.params.language) | ||
); | ||
|
||
if (getSpecificBook.length === 0) { | ||
return res.json({error:`No book found for the language of ${req.params.language}`,}); | ||
} | ||
|
||
return res.json({book: getSpecificBook}); | ||
}); | ||
|
||
|
||
/* | ||
Route /author | ||
Discription Get all authors | ||
Access Public | ||
Parameter None | ||
Method GET | ||
*/ | ||
booky.get("/author", (req, res) => { | ||
return res.json({ authors: database.author}); | ||
}); | ||
|
||
/* | ||
Route /author/name | ||
Discription Get specific authors | ||
Access Public | ||
Parameter name | ||
Method GET | ||
*/ | ||
booky.get("/author/:name", (req, res) => { | ||
const getSpecificBook = database.author.filter( | ||
(author) => author.name === req.params.name | ||
); | ||
if (getSpecificBook.length === 0) { | ||
return res.json({error:`No book found for the author of ${req.params.name}`,}); | ||
} | ||
|
||
return res.json({author: getSpecificBook}); | ||
}); | ||
|
||
/* | ||
Route /author/book | ||
Discription Get specific authors based on books | ||
Access Public | ||
Parameter isbn | ||
Method GET | ||
*/ | ||
booky.get("/author/book/:isbn", (req, res) => { | ||
const getSpecificAuthor = database.author.filter( | ||
(author) => author.books.includes(req.params.isbn) | ||
); | ||
|
||
if (getSpecificAuthor.length === 0) { | ||
return res.json({error:`No Author found for the book of ${req.params.isbn}`, | ||
}); | ||
} | ||
|
||
return res.json({authors: getSpecificAuthor}); | ||
}); | ||
|
||
|
||
/* | ||
Route /publications | ||
Discription Get all publication | ||
Access Public | ||
Parameter NONE | ||
Method GET | ||
*/ | ||
booky.get("/publication/", (req, res) => { | ||
return res.json({publications:database.publication}); | ||
}); | ||
|
||
/* | ||
Route /publications | ||
Discription Get specific publications | ||
Access Public | ||
Parameter publications | ||
Method GET | ||
*/ | ||
booky.get("/publication/:name", (req, res) => { | ||
const getSpecificPublication = database.publication.filter( | ||
(publication) => publication.name === req.params.name | ||
); | ||
if (getSpecificPublication.length === 0) { | ||
return res.json({error:`No book found for the publication of ${req.params.name}`,}); | ||
} | ||
|
||
return res.json({publication: getSpecificPublication}); | ||
}); | ||
|
||
/* | ||
Route /publications/book | ||
Discription Get list of publication based on book | ||
Access Public | ||
Parameter isbn | ||
Method GET | ||
*/ | ||
booky.get("/publication/book/:isbn", (req, res) => { | ||
const getSpecificPublication = database.publication.filter( | ||
(publication) => publication.books.includes(req.params.isbn) | ||
); | ||
|
||
if (getSpecificPublication.length === 0) { | ||
return res.json({error:`No publication found for the book of ${req.params.isbn}`,}); | ||
} | ||
|
||
return res.json({publication: getSpecificPublication}); | ||
}); | ||
|
||
booky.listen(3000, () => console.log("Hey server booting...")); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.