-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from alexlee-dev/v0.5.0
📦 v0.5.0
- Loading branch information
Showing
23 changed files
with
556 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { starterBeers } from "../constants"; | ||
|
||
export const initializeStarterBeers = async () => { | ||
try { | ||
starterBeers.forEach(async ({ abv, brewer, description, name, type }) => { | ||
await fetch("/beer", { | ||
body: JSON.stringify({ | ||
abv, | ||
brewer, | ||
description, | ||
name, | ||
type, | ||
}), | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
method: "POST", | ||
}); | ||
}); | ||
|
||
return; | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
}; | ||
|
||
export const getBeers = async () => { | ||
try { | ||
const response = await fetch("/beers"); | ||
const beers = await response.json(); | ||
return beers; | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import * as React from "react"; | ||
|
||
const BeerDisplayer = ({ beers }) => ( | ||
<table> | ||
<thead> | ||
<tr> | ||
<th className="column1">ABV</th> | ||
<th>Brewer</th> | ||
<th>Description</th> | ||
<th>Name</th> | ||
<th className="column5">Type</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{beers.map((beer) => ( | ||
<tr key={beer._id}> | ||
<td className="column1">{beer.abv}</td> | ||
<td>{beer.brewer}</td> | ||
<td>{beer.description}</td> | ||
<td>{beer.name}</td> | ||
<td className="column5">{beer.type}</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
); | ||
|
||
export default BeerDisplayer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
export const starterBeers = [ | ||
{ | ||
abv: 7.0, | ||
brewer: "Cool Guy Brewing", | ||
description: "A very IPA-y beer!", | ||
name: "Tank Top", | ||
type: "IPA", | ||
}, | ||
{ | ||
abv: 4.2, | ||
brewer: "America Light", | ||
description: "Not quite pee water, but it's cheap.", | ||
name: "Light Me Up", | ||
type: "Light Beer", | ||
}, | ||
{ | ||
abv: 6.3, | ||
brewer: "Hip Ship", | ||
description: "It tastes like gold!", | ||
name: "El Dorado", | ||
type: "Amber Ale", | ||
}, | ||
{ | ||
abv: 14.4, | ||
brewer: "Grim Reaper", | ||
description: "Good god, I'm drunk.", | ||
name: "End Times", | ||
type: "Mead?", | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import express from "express"; | ||
import Beer from "../models/Beer"; | ||
|
||
class BeerController { | ||
router = express.Router(); | ||
|
||
constructor() { | ||
this.initializeRoutes(); | ||
} | ||
|
||
initializeRoutes() { | ||
this.router.get("/beers", async (req, res) => { | ||
try { | ||
const beers = await Beer.find(); | ||
|
||
res.send(beers); | ||
} catch (error) { | ||
res.status(500).send({ error }); | ||
} | ||
}); | ||
|
||
this.router.post("/beer", async (req, res) => { | ||
try { | ||
const newBeer = new Beer({ | ||
abv: req.body.abv, | ||
brewer: req.body.brewer, | ||
description: req.body.description, | ||
name: req.body.name, | ||
type: req.body.type, | ||
}); | ||
|
||
await newBeer.save(); | ||
|
||
res.status(201).send(newBeer); | ||
} catch (error) { | ||
res.status(500).send({ error: error.message }); | ||
} | ||
}); | ||
|
||
this.router.patch("/beer/:id", async (req, res) => { | ||
try { | ||
const beer = await Beer.findById(req.params.id); | ||
|
||
if (!beer) { | ||
return res.status(404).send(); | ||
} | ||
|
||
const updates = Object.keys(req.body); | ||
updates.forEach((update) => (beer[update] = req.body[update])); | ||
|
||
await beer.save(); | ||
|
||
res.send(beer); | ||
} catch (error) { | ||
res.status(500).send({ error }); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
export default BeerController; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import mongoose from "mongoose"; | ||
|
||
const beerSchema = new mongoose.Schema( | ||
{ | ||
abv: { | ||
required: true, | ||
type: Number, | ||
}, | ||
brewer: { | ||
required: true, | ||
type: String, | ||
}, | ||
description: { | ||
required: true, | ||
type: String, | ||
}, | ||
name: { | ||
required: true, | ||
type: String, | ||
}, | ||
type: { | ||
required: true, | ||
type: String, | ||
}, | ||
}, | ||
{ timestamps: true } | ||
); | ||
|
||
function applicationToJSON() { | ||
return this.toObject(); | ||
} | ||
|
||
beerSchema.methods.toJSON = applicationToJSON; | ||
|
||
const Beer = mongoose.model("Beer", beerSchema); | ||
|
||
export default Beer; |
Oops, something went wrong.