Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solvedLabBrewery #3004

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
74 changes: 64 additions & 10 deletions app.js
Original file line number Diff line number Diff line change
@@ -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...")
});*/
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
23 changes: 16 additions & 7 deletions public/stylesheets/styles.css
Original file line number Diff line number Diff line change
@@ -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;

}
14 changes: 14 additions & 0 deletions views/beers.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<h1>Breweries page</h1>


<div class="grid">

{{#each breweries}}
<div class="card">
<h3><a href="/breweries/{{id}}">{{name}}</a></h3>
<p>{{brewery_type}}</p>

</div>
{{/each}}

</div>
5 changes: 2 additions & 3 deletions views/index.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
<div>

</div>
<button><a href="/brewery">Home Check the Beers!</a></button>
<button><a href="/random-brewery">Check a Random Beer</a></button>
16 changes: 16 additions & 0 deletions views/layout.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<link rel="stylesheet" href="/stylesheets/style.css">
<title>Breweries</title>
</head>
<body>
{{>navbar}}
{{{body}}}
{{>footer}}
</body>


</html>
1 change: 1 addition & 0 deletions views/partials/footer.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>Developed by Pedro</p>
5 changes: 5 additions & 0 deletions views/partials/navbar.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<ul>
<li><a href="/">Home</a></li>
<li><a href="/brewery">Breweries</a></li>
<li><a href="/random-brewery">Random Brewery</a></li>
</ul>
6 changes: 6 additions & 0 deletions views/random-brewery.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h1>Random Brewery</h1>

<h2>name: {{brewery.name}}</h2>
<p>Address: {{brewery.address_1}}</p>
<p>City: {{brewery.city}}</p>
<p>Type: {{brewery.brewery_type}}</p>