Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
backend/node_modules
frontend/node_modules
56 changes: 56 additions & 0 deletions backend/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const express = require('express');
const authorRouter = require('./routes/author');
const bookRouter = require('./routes/book');

const cors = require('cors');
const mongoose = require('mongoose');

const BookSeed = require('./book_seed');
const AuthorSeed = require('./author_seed');
const app = express();
const port = 4000;

app.use(cors());
app.use(express.urlencoded({extended: true}))
app.use(express.json())


// Inserting initial data to database for one time only
/*
Books.insertMany(BookSeed, (err, res) => {
if(err){ console.log(err)}
mongoose.connection.close;
})

Authors.insertMany(AuthorSeed, (err, res) => {
if(err){ console.log(err) }
mongoose.connection.close;
})
*/


app.use('/',bookRouter)
app.use('/', authorRouter)
app.use('/getBooks', bookRouter);

app.use('/getAuthors', authorRouter);

app.get('/userBooks', bookRouter);

app.use('/addBook', bookRouter);

app.use('/updateBook', bookRouter);

app.use('/deleteBook', bookRouter);

app.use('/addAuthor', authorRouter);

app.use('/updateAuthor', authorRouter);

app.use('/deleteAuthor', authorRouter);

app.listen(port, () => {
console.log(`Server running on port: ${port}`);
})

module.exports = app;
96 changes: 96 additions & 0 deletions backend/author_seed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
module.exports = [
{
name: "Osama Al Muslim",
age: 44,
nationality: "Saudi Arabia",
image: "https://adab-news.com/wp-content/uploads/2020/01/Capture.jpg",
gender: "male",
books: [
{
title: "This is what happened to me",
pages: 447,
price: 87,
image:
"https://www.jarir.com/cdn-cgi/image/fit=contain,width=400,height=400/https://www.jarir.com/media//catalog/product/5/6/568335.jpg?1",
},
{
title: "sakhab alkhasif",
pages: 447,
price: 69,
image:
"https://www.jarir.com/cdn-cgi/image/fit=contain,width=400,height=400/https://www.jarir.com/media//catalog/product/4/7/478793.jpg?1",
},
{
title: "fear",
pages: 302,
price: 53,
image:
"https://www.jarir.com/cdn-cgi/image/fit=contain,width=400,height=400/https://www.jarir.com/media//catalog/product/4/3/439941.jpg?1",
},
],
},
{
name: "Ali Jaber Al-Fifi",
nationality: "Saudi Arabia",
image:
"https://www.alriyadh.com/media/article/2010/12/28/img/808263677439.jpg",
gender: "male",
books: [
{
title: "li'anak Allh",
pages: 192,
price: 17,
image:
"https://www.jarir.com/cdn-cgi/image/fit=contain,width=400,height=400/https://www.jarir.com/media//catalog/product/4/6/465531.jpg?1",
},
],
},
{
name: "Buthaina Al-Issa",
age: 39,
nationality: "Kuwait",
image:
"https://www.almrsal.com/wp-content/uploads/2017/01/%D8%A8%D8%AB%D9%8A%D9%86%D8%A9-%D8%A7%D9%84%D8%B9%D9%8A%D8%B3%D9%89.jpeg",
gender: "female",
books: [
{
title: "wandering maps",
pages: 405,
price: 52,
image:
"https://www.jarir.com/cdn-cgi/image/fit=contain,width=400,height=400/https://www.jarir.com/media//catalog/product/4/4/448496.jpg?1",
},
],
},
{
name: "Abdulwahab Al-Rifai",
age: 48,
nationality: "Kuwait",
image: "https://i.ytimg.com/vi/8SzCOrmEC1A/sddefault.jpg",
gender: "male",
books: [
{
title: "halat nadira",
pages: 323,
price: 47,
image: "https://d34gac3gqli6v2.cloudfront.net/images/162x222/5092.jpg",
},
],
},
{
name: "aya keto",
age: 25,
nationality: "Japan",
image:
"https://upload.wikimedia.org/wikipedia/commons/thumb/3/34/Aya_Kit%C5%8D.jpg/180px-Aya_Kit%C5%8D.jpg",
gender: "female",
books: [
{
title: "liter of tears",
pages: 199,
price: 46,
image: "https://img.wattpad.com/cover/178974102-352-k864815.jpg",
},
],
},
];
44 changes: 44 additions & 0 deletions backend/book_seed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module.exports = [
{
title: 'wandering maps',
pages: 405,
price: 52,
image: "https://www.jarir.com/cdn-cgi/image/fit=contain,width=400,height=400/https://www.jarir.com/media//catalog/product/4/4/448496.jpg?1"
},
{
title: 'liter of tears',
pages: 199,
price: 46,
image: "https://img.wattpad.com/cover/178974102-352-k864815.jpg"
},
{
title: 'This is what happened to me',
pages: 447,
price: 87,
image: "https://www.jarir.com/cdn-cgi/image/fit=contain,width=400,height=400/https://www.jarir.com/media//catalog/product/5/6/568335.jpg?1"
},
{
title: "li'anak Allah",
pages: 192,
price: 17,
image: "https://www.jarir.com/cdn-cgi/image/fit=contain,width=400,height=400/https://www.jarir.com/media//catalog/product/4/6/465531.jpg?1"
},
{
title: 'sakhab alkhasif',
pages: 447,
price: 69,
image: "https://www.jarir.com/cdn-cgi/image/fit=contain,width=400,height=400/https://www.jarir.com/media//catalog/product/4/7/478793.jpg?1"
},
{
title: 'fear',
pages: 302,
price: 53,
image: "https://www.jarir.com/cdn-cgi/image/fit=contain,width=400,height=400/https://www.jarir.com/media//catalog/product/4/3/439941.jpg?1"
},
{
title: 'halat nadira',
pages: 323,
price: 47,
image: "https://d34gac3gqli6v2.cloudfront.net/images/162x222/5092.jpg"
}
]
25 changes: 25 additions & 0 deletions backend/models/booksAndAuthors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const mongoose = require('mongoose');

const BookSchema = mongoose.Schema({
title: {type: String, required: "Book title should be provided"},
pages: {type: Number, required: "Book pages should be provided"},
price: {type: Number, default: 0},
image: {type: String, required: "Book image should be provided"}
})

const Books = mongoose.model("Books", BookSchema);

const AuthorSchema = mongoose.Schema({
name: {type: String, required: "Author name should be provided"},
age: {type: Number},
nationality: {type: String, required: "Author nationality should be provided"},
image: {type: String, required: "Author image should be provided"},
gender: {type: String},
books: {type: [BookSchema]}

})

const Authors = mongoose.model("Authors", AuthorSchema);


module.exports = {Books, Authors}
Loading