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

[BERLIN-PT-032024]- Franciely Beckert #2993

Open
wants to merge 3 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
45 changes: 43 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,54 @@ app.set('views', path.join(__dirname, 'views'));
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) => {
punkAPI
.getBeers()
.then(beersFromApi => {
res.render('beers', { beers: beersFromApi });
console.log('Beers from the database: ', beersFromApi);
})
.catch(error => {
res.status(500).send('Error fetching from the database');
console.log(error);
});
});

app.get('/random-beer', (req, res) => {
punkAPI
.getRandom()
.then(responseFromAPI => {
res.render('random-beer', { beer: responseFromAPI[0] });
console.log(responseFromAPI[0]);
})
.catch(error => {
res.status(500).send('Error fetching from the database');
console.log(error);
});
});

app.get('/beers/:id', (req, res) => {
const beerId = req.params.id;
console.log('beerId', beerId);
// Call the getBeer(id) method to retrieve the details of the specific beer
punkAPI
.getBeer(beerId)
.then(responseFromAPI => {
console.log("beer", responseFromAPI[0]);
res.render('beer-details', { beer: responseFromAPI[0] });
})
.catch(error => {
console.log(error);
res.status(500).send('Error fetching from the database');
});
});

app.listen(3000, () => console.log('🏃‍ on port 3000'));
18 changes: 18 additions & 0 deletions public/stylesheets/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,21 @@ dark-blue: #0a2c42;
grey: #bfbfbf;
font-family: Arial, Helvetica, sans-serif;
*/

#ul {
display: flex;
background-color: #2081c3;
list-style-type: none;
padding-top: 15px;
padding-bottom: 15px;
box-shadow: 1px 2px 2px gr;
}

.a {
text-decoration: none;
color: #f7f9f9;
}

.li {
margin-right: 50px;
}
4 changes: 4 additions & 0 deletions views/beer-details.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<h1>Beer Details</h1>
{{#with beer}}
{{> beerpartial}}
{{/with}}
11 changes: 11 additions & 0 deletions views/beers.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div class='beers'>
<h1>All Beers</h1>
<div class='beer'>
{{#each beers}}
{{!-- anchor to macke it clickable --}}
<a href="/beers/{{id}}">
{{> beerpartial}}
</a>
{{/each}}
</div>
</div>
7 changes: 7 additions & 0 deletions views/index.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
<link rel='stylesheet' href='/stylesheets/styles.css' />

<div>
<img src='/images/beer.png' alt='Beer Image' />
<ul id="ul">
<li class="li"><a class="a" href='/beers'>Check the Beers!</a></li>
<li class="li"><a class="a" href='/random-beer'>Check a Random Beer!</a></li>
</ul>

</div>
24 changes: 24 additions & 0 deletions views/layout.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<html lang='en'>
<head>
<meta charset='UTF-8' />
<meta name='viewport' content='width=device-width, initial-scale=1.0' />
<link rel='stylesheet' href='/stylesheets/styles.css' />
<title>Beer App</title>
</head>
<body>
<header>
<nav>
<ul id='ul'>
<li class='li'><a class='a' href='/'>Home</a></li>
<li class='li'><a class='a' href='/beers'>Beers</a></li>
<li class='li'><a class='a' href='/random-beer'>Random Beer</a></li>
</ul>
</nav>
</header>

<main>
{{{body}}}
</main>

</body>
</html>
6 changes: 6 additions & 0 deletions views/partials/beerpartial.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class='beers'>
<img src='{{image_url}}' alt='{{name}}' width='100' />
<h2> {{name}} </h2>
<p> {{description}} </p>
<p><em> {{tagline}} </em></p>
</div>
13 changes: 13 additions & 0 deletions views/random-beer.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

<div id='random-beer'>
{{#with beer}}
{{> beerpartial}}
<p> <strong>Food Pairing:</strong></p>
<ul>
{{#each food_pairing}}
<li>{{this}}</li>
{{/each}}
</ul>
<p><strong>Brewer Tips:</strong>{{brewers_tips}}</p>
{{/with}}
</div>