Skip to content
Permalink
Browse files
Finished up until Linking pages
  • Loading branch information
mitroio committed Oct 12, 2018
1 parent 001f84c commit 316212b627ff64e67e77bfb4c9da0f065a80d110
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 50 deletions.
@@ -22,7 +22,7 @@ const db = new sqlite3.Database('./bookshop.db', (err) => {
console.log('Connected to the "bookshop.db" SQlite database.')
})

app.get('/', async(req, res) => {
/*app.get('/', async(req, res) => {
const sql = 'SELECT id, title, description, publisher FROM books;'
console.log(sql)
db.all(sql, (err, data) => {
@@ -31,17 +31,19 @@ app.get('/', async(req, res) => {
console.log(JSON.stringify(data, null, 2))
res.render('home', {books: data})
})
})
})*/

/* app.get('/', async(req, res) => {
app.get('/', async(req, res) => {
let sql = 'SELECT id, title FROM books;'
// --------
let querystring = ''
console.log(req.query.q)
if(req.query !== undefined && req.query.q !== undefined) {
sql = `SELECT id, title FROM books
sql = `SELECT id, title, description, year, publisher FROM books
WHERE upper(title) LIKE "%${req.query.q}%"
OR upper(description) LIKE upper("%${req.query.q}%");`
OR upper(description) LIKE upper("%${req.query.q}%")
OR upper(publisher) LIKE upper("%${req.query.q}%")
OR upper(year) LIKE upper("%${req.query.q}%");`
querystring = req.query.q
}
// --------
@@ -50,15 +52,15 @@ app.get('/', async(req, res) => {
console.log(data)
res.render('newindex', {books: data, query: querystring})
})
}) */
})

app.get('/details/:id', (req, res) => {
console.log(req.params.id)
console.log(req.headers.referer)
const sql = `SELECT * FROM books WHERE id = ${req.params.id};`
console.log(sql)
db.get(sql, (err, data) => {
if(err) console.error(err.message)
console.log(data)
data.referer = req.headers.referer;
res.render('details', data)
})
})
@@ -10,15 +10,8 @@
"license": "ISC",
"dependencies": {
"express": "^4.16.3",
<<<<<<< HEAD
"express-es6-template-engine": "^2.0.3",
"express-handlebars": "latest",
||||||| merged common ancestors
"express-es6-template-engine": "^2.0.3",
"express-handlebars": "^3.0.0",
=======
"express-handlebars": "^3.0.0",
>>>>>>> c67bf3ae57c2be05ac191dcdb105faa490aba5cc
"sqlite3": "^4.0.2"
},
"devDependencies": {
@@ -1,7 +1,6 @@
<<<<<<< HEAD

body{
overflow: hidden;

}
table{
border-collapse: collapse;
@@ -46,10 +45,10 @@ td.haspopup{
td.haspopup:hover > .popup {
display: inline;
}
||||||| merged common ancestors
=======

body {
font-family: Arial, Helvetica, sans-serif;
}
>>>>>>> c67bf3ae57c2be05ac191dcdb105faa490aba5cc
.details h1 {
color: red;
}
@@ -1,5 +1,10 @@
{{#if referer}}
<header>
<a href="{{referer}}">Go back to search results</a>
</header>
{{/if}}
<div class='details'>
<h1>{{title}}</h1>
<h2>ISBN: {{isbn}}</h2>
<p>{{description}}</p>
<h1>{{title}}</h1>
<h2>ISBN: {{isbn}}</h2>
<p>{{description}}</p>
</div>
@@ -1,17 +1,11 @@

<p>The following books will help you in this module:</p>
<<<<<<< HEAD
<table>
<tr class='headers'>
<th>Title</th>
<th>Publisher</th>
<th>Amazon</th>
</tr>
||||||| merged common ancestors
<ol>
=======
<ul>
>>>>>>> c67bf3ae57c2be05ac191dcdb105faa490aba5cc
{{#each books}}
<tr>
<td class='title haspopup'>
@@ -23,11 +17,4 @@
<td><a href='https://www.amazon.co.uk/gp/search/ref=sr_adv_b/?search-alias=stripbooks&field-isbn={{this.isbn}}'>Buy</a></td>
</tr>
{{/each}}
<<<<<<< HEAD
</table>

||||||| merged common ancestors
</ol>
=======
</ul>
>>>>>>> c67bf3ae57c2be05ac191dcdb105faa490aba5cc
@@ -1,14 +1,12 @@

<!DOCTYPE html>
<html>
<head>
<title>My Favourite Books</title>
<<<<<<< HEAD
{{#if title}}
<title>{{title}}</title>
{{else}}
<title>Bookshop</title>
{{/if}}
<link rel='stylesheet' href='/css/style.css' type='text/css'>
||||||| merged common ancestors
=======
<link href="css/style.css" type="text/css" rel="stylesheet" />
>>>>>>> c67bf3ae57c2be05ac191dcdb105faa490aba5cc
</head>
<body>
<header>
@@ -4,23 +4,38 @@
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bookshop</title>

<meta name="description" content="Google Book Search">
<meta name="author" content="Mark Tyers">
<link rel='stylesheet' href='/css/style.css' type='text/css'>
</head>
<body>
<h1>Bookshop</h1>
<form action="/" method="get">
<input type="text" name="q" value="{{query}}">
<input type="submit" value="Search">
</form>
<ol>
{{#if query}}
<p>{{query}}</p>
{{/if}}
{{#each books}}
<li>{{this.title}}</li>
{{/each}}
</ol>
<table>
<tr class='headers'>
<th>Title</th>
<th>Publisher</th>
<th>Amazon</th>
</tr>
{{#each books}}
<tr>
<td class='title haspopup'>
<a href='/details/{{this.id}}' class='titles'>{{this.title}}</a>
<p class="popup">{{this.description}}</p>
</td>
<td>{{this.publisher}}</td>

<td><a href='https://www.amazon.co.uk/gp/search/ref=sr_adv_b/?search-alias=stripbooks&field-isbn={{this.isbn}}'>Buy</a></td>
</tr>
{{/each}}
</table>
{{/if}}

</body>
</html>

0 comments on commit 316212b

Please sign in to comment.