diff --git a/app.js b/app.js index a206dd8d91..e8c5f73c1a 100644 --- a/app.js +++ b/app.js @@ -1,25 +1,79 @@ const express = require('express'); - +const app = express(); const hbs = require('hbs'); const path = require('path'); -const PunkAPIWrapper = require('punkapi-javascript-wrapper'); +/* +app.set("view engine", "hbs"); +*/ +app.use(express.static(`${__dirname}/public`)); + +hbs.registerPartials(__dirname + "/views/partials"); + -const app = express(); -const punkAPI = new PunkAPIWrapper(); app.set('view engine', 'hbs'); app.set('views', path.join(__dirname, 'views')); - app.use(express.static(path.join(__dirname, 'public'))); -// Register the location for handlebars partials here: -// ... -// Add the route handlers here: +app.get("/", (req, res) => { + + res.render("index"); + +}); +app.get("/brewery", (req, res) => { -app.get('/', (req, res) => { - res.render('index'); + fetch("https://api.openbrewerydb.org/v1/breweries") + .then((response) => response.json()) + .then((response) => { + res.render("beers", { breweries: response}); + }); }); + +app.get("/random-brewery", (req, res) => { + fetch("https://api.openbrewerydb.org/v1/breweries/random") + .then((response) => response.json()) + .then((response) => res.render("random-brewery", { brewery: response[0] })); +}); + +/*app.get('/', (req, res) => { + res.render('home', { title: 'Home' }); +});*/ + + +/*app.get("/beers/:id" (req, res) => { + const id = req.params.id; + fetch("https://api.openbrewerydb.org/v1/breweries/${id}") + .then((response) => response.json()) + .then((response) => res.render("reandom-brewerry",{beers : response})) +}); +*/ +app.get("/breweries/:id", (req, res) => { + const id = req.params.id; + fetch(`https://api.openbrewerydb.org/v1/breweries/${id}`) + .then((response) => response.json()) + .then((response) => res.render("random-brewery", { brewery: response })); +}); + + app.listen(3000, () => console.log('🏃‍ on port 3000')); + + + + + + + + + + + + + + + +/*app.listen(3000, () => { + console.log("Server listening...") +});*/ \ No newline at end of file diff --git a/package.json b/package.json index 111c4e477d..307eab35ed 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "main": "app.js", "scripts": { "start": "node app.js", - "dev": "nodemon app.js" + "dev": "nodemon app.js -e js,hbs" }, "license": "ISC", "dependencies": { diff --git a/public/stylesheets/styles.css b/public/stylesheets/styles.css index 251470be83..115465b95c 100644 --- a/public/stylesheets/styles.css +++ b/public/stylesheets/styles.css @@ -1,7 +1,16 @@ -/* -white: #f7f9f9; -light-blue: #2081c3; -dark-blue: #0a2c42; -grey: #bfbfbf; -font-family: Arial, Helvetica, sans-serif; -*/ +body { + font-family: Arial, Arial, Helvetica, sans-serif; +} + +.grid { + display: grid; + grid-template-columns: 1fr 1fr 1fr; + grid-gap: 15px; +} + +.card { + border: 1px solid #ccc; + border-radius: 5px; + padding: 10px; + +} \ No newline at end of file diff --git a/views/beers.hbs b/views/beers.hbs new file mode 100644 index 0000000000..1f3d413681 --- /dev/null +++ b/views/beers.hbs @@ -0,0 +1,14 @@ +

Breweries page

+ + +
+ + {{#each breweries}} +
+

{{name}}

+

{{brewery_type}}

+ +
+ {{/each}} + +
\ No newline at end of file diff --git a/views/index.hbs b/views/index.hbs index 3a6cce8d18..5c4e90319a 100644 --- a/views/index.hbs +++ b/views/index.hbs @@ -1,3 +1,2 @@ -
- -
\ No newline at end of file + + diff --git a/views/layout.hbs b/views/layout.hbs new file mode 100644 index 0000000000..654bed991e --- /dev/null +++ b/views/layout.hbs @@ -0,0 +1,16 @@ + + + + + + + Breweries + + + {{>navbar}} + {{{body}}} + {{>footer}} + + + + diff --git a/views/partials/footer.hbs b/views/partials/footer.hbs new file mode 100644 index 0000000000..ca4e27393b --- /dev/null +++ b/views/partials/footer.hbs @@ -0,0 +1 @@ +

Developed by Pedro

\ No newline at end of file diff --git a/views/partials/navbar.hbs b/views/partials/navbar.hbs new file mode 100644 index 0000000000..313f2b4136 --- /dev/null +++ b/views/partials/navbar.hbs @@ -0,0 +1,5 @@ + diff --git a/views/random-brewery.hbs b/views/random-brewery.hbs new file mode 100644 index 0000000000..fed083248b --- /dev/null +++ b/views/random-brewery.hbs @@ -0,0 +1,6 @@ +

Random Brewery

+ +

name: {{brewery.name}}

+

Address: {{brewery.address_1}}

+

City: {{brewery.city}}

+

Type: {{brewery.brewery_type}}

\ No newline at end of file