Skip to content

Commit

Permalink
add get method apis
Browse files Browse the repository at this point in the history
  • Loading branch information
AdithyakrishnaV committed Jun 27, 2021
0 parents commit 761aee2
Show file tree
Hide file tree
Showing 1,070 changed files with 120,888 additions and 0 deletions.
34 changes: 34 additions & 0 deletions database.js
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};
180 changes: 180 additions & 0 deletions index.js
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..."));
15 changes: 15 additions & 0 deletions node_modules/.bin/is-ci

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

17 changes: 17 additions & 0 deletions node_modules/.bin/is-ci.cmd

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

18 changes: 18 additions & 0 deletions node_modules/.bin/is-ci.ps1

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

15 changes: 15 additions & 0 deletions node_modules/.bin/mime

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

17 changes: 17 additions & 0 deletions node_modules/.bin/mime.cmd

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

18 changes: 18 additions & 0 deletions node_modules/.bin/mime.ps1

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

15 changes: 15 additions & 0 deletions node_modules/.bin/nodemon

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

17 changes: 17 additions & 0 deletions node_modules/.bin/nodemon.cmd

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

18 changes: 18 additions & 0 deletions node_modules/.bin/nodemon.ps1

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

15 changes: 15 additions & 0 deletions node_modules/.bin/nodetouch

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

Loading

0 comments on commit 761aee2

Please sign in to comment.