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

finished lab #3009

Open
wants to merge 2 commits 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
17 changes: 14 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ const express = require('express');

const hbs = require('hbs');
const path = require('path');
const PunkAPIWrapper = require('punkapi-javascript-wrapper');
const axios = require('axios');

const app = express();
const punkAPI = new PunkAPIWrapper();

app.set('view engine', 'hbs');
app.set('views', path.join(__dirname, 'views'));
Expand All @@ -14,12 +13,24 @@ app.use(express.static(path.join(__dirname, 'public')));

// Register the location for handlebars partials here:

// ...
hbs.registerPartials(path.join(__dirname, 'views/partials'));

// Add the route handlers here:

app.get('/', (req, res) => {
res.render('index');
});

app.get('/beers', (req, res) => {
axios.get('https://api.openbrewerydb.org/v1/breweries')
.then(response => res.render('beers', {data: response.data}))
.catch(error => console.log(error));
});

app.get('/random-beer', (req, res) => {
axios.get('https://api.openbrewerydb.org/v1/breweries/random')
.then(response => res.render('random-beer', {data: response.data}))
.catch(error => console.log(error));
});

app.listen(3000, () => console.log('🏃‍ on port 3000'));
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
},
"license": "ISC",
"dependencies": {
"axios": "^1.7.2",
"express": "^4.17.1",
"hbs": "^4.1.1",
"punkapi-javascript-wrapper": "^1.0.2"
Expand Down
71 changes: 64 additions & 7 deletions public/stylesheets/styles.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,64 @@
/*
white: #f7f9f9;
light-blue: #2081c3;
dark-blue: #0a2c42;
grey: #bfbfbf;
font-family: Arial, Helvetica, sans-serif;
*/
body {
font-family: Arial, Helvetica, sans-serif;
background-color: #f7f9f9;
}

nav {
background-color: #2081c3;
color: #f7f9f9;
text-decoration: none;
height: 50px;
display: flex;
align-items: center;
box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.5);
}

.bottom-bar {
background-color: #0a2c42;
color: #f7f9f9;
height: 50px;
display: flex;
align-items: center;
}

.btn {
background-color: #2081c3;
color: #f7f9f9;
width: 15%;
height: 40px;
border-radius: 5px;
text-decoration: none;
display: flex;
justify-content: center;
align-items: center;
box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.5);
}

h1 {
margin: 2px;
width: 100%;
text-align: center;
font-size: larger;
}

p {
margin: 0px;
padding-left: 10px;
}

.beer-data {
background-color: lightblue;
margin-bottom: 10px;
width: 20%;
border-radius: 10px;
display: flex;
flex-direction: column;
padding-bottom: 10px;
margin: auto;
}

a {
color: white;
text-decoration: none;
padding-left: 10px;
}
5 changes: 5 additions & 0 deletions views/beers.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div style="display: flex; flex-wrap: wrap;">
{{#each data}}
{{> beerpartial }}
{{/each}}
</div>
6 changes: 4 additions & 2 deletions views/index.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<div>

<div style="height: 570px; display: flex; flex-direction: column; align-items: center; justify-content: space-around">
<img src="./images/beer.png" width="20%">
<a class="btn" href="/beers">Check the Beers!</a>
<a class="btn" href="/random-beer">Check a Random Beer</a>
</div>
17 changes: 17 additions & 0 deletions views/layout.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="stylesheets/styles.css">
</head>
<body>
<nav>
<a href="/">Home</a>
<a href="/beers">Beers</a>
<a href="/random-beer">Random Beer</a>
</nav>
{{{ body }}}
<div class="bottom-bar">
<p>Developed by Ironhack ;)</p>
</div>
</body>
</html>
15 changes: 15 additions & 0 deletions views/partials/beerpartial.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div class="beer-data">
<h1>{{{ name }}}</h1>
<p>brewery type: {{{ brewery_type }}}</p>
<p>address: {{{ address_1 }}}</p>
<p>city: {{{ city }}}</p>
<p>state province: {{{ state_province }}}</p>
<p>postal_code: {{{ postal_code }}}</p>
<p>country: {{{ country }}}</p>
<p>longitude: {{{ longitude }}}</p>
<p>latitude: {{{ latitude }}}</p>
<p>phone: {{{ phone }}}</p>
<p>website url: {{{ website_url }}}</p>
<p>state: {{{ state }}}</p>
<p>street: {{{ street }}}</p>
</div>
3 changes: 3 additions & 0 deletions views/random-beer.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{#each data}}
{{> beerpartial }}
{{/each}}