Food waste in the US continues to be a crippling issue which effects everyone in our community. Here are a few stats to illustrate the issue.
This app is a humble contribution to a solution that may bring about a much needed change in the dominant culture of waste. We can’t build electric cars or a rocket to mars, but we can build this app in the mean time.
The idea for the project came about through a mixture of activism and sustainability. Our main focus was to create an app that promotes waste reduction through food management by bringing businesses and the community together to tackle a common issue and provide a tool to effectively fight hunger.
✴️ Click here to view our app live
- API Overview
- Technologies Used
- Response Requests Cycle Diagram
- Database Model
- Connection
- Testing
- Vendor Data Example
- Code Samples
- Bugs & Fixes
- Future Additions
- Contribution Guidelines
- Sources
The API contains two models- Vendor and Listing. The Vendor model is made up of all the information for said Vendor- name, email, password, street address, type of vendor (restaurant, farm, or market), and all the adjoining listings for that vendor. The Listing model contains all the information for any given listing- item name, quantity, price, dietary classification (vegan? vegetarian?), and vendorId (the adjoining vendor information of the vendor that the listing belongs to). So, to speak in programming terms, the Vendor model has many listings, while the Listing model belongs to Vendor. Through our API, our users can easily traverse through different vendors and all of their listings to choose which food they would like to purchase.
{
id: 1,
name: 'Dollys Donuts',
type: 'Restaurant',
phone: '1234567890',
email: '[email protected]',
password: '$2b$10$uHjWS3xW/R1D7llH43dt9OQNAkgWpFBwdkiMfl6/BMIaOEcBkjs2G',
closing_time: '12:00 AM',
street: '123',
city: 'New York City',
state: 'NY',
zip_code: '33211',
description: 'Local, family business that know how to fry & glaze puffy dough like no other.',
image: 'https://www.bakingbusiness.com/ext/resources/2019/8/08192019/GlobalTrends.jpg?1566494557',
createdAt: '2017-07-04T00:00:00.000Z',
updatedAt: '2020-03-09T16:22:27.115Z',
Listings:
[
{
id: 1,
name: 'Glazed Donut',
price: 1.59,
quantity: 20,
vegan: false,
vegetarian: true,
description: "Who doesn't love a classic. Soft yeast dough covered in an all natural glaze makes these donuts to die for.",
image: 'https://www.gosoftstuff.com/web/image/product.template/28091/image?unique=23e3a82',
createdAt: '2017-07-04T00:00:00.000Z',
updatedAt: '2020-03-09T16:22:27.215Z',
VendorId: 1,
},
],
}
Example of a GET request to view all vendors:
router.get('/', async (req, res) => {
try {
const vendors = await Vendor.findAll({
include: [Listing]
});
res.json(vendors);
} catch (err) {
console.error(err);
}
});
Example of a POST request to create a new vendor with password encryption:
router.post('/new', async (req, res) => {
// new vendor info
let vendorToCreate = req.body;
try {
// hashing password
const hashedPassword = await bcrypt.hash(req.body.password, 10);
// replacing password with hashed password
vendorToCreate.password = hashedPassword;
const newVendor = await Vendor.create(vendorToCreate);
res.json(newVendor);
} catch {
res.status(500).send();
}
// req.body should be the vendor object
});
Example of a PUT request to update an existing vendor:
router.put('/:id/edit', async (req, res) => {
// req.body should look like this: { field: field being edited e.g.'email', value: '[email protected]' }
const vendorToUpdate = await Vendor.findByPk(req.params.id);
vendorToUpdate[req.body.field] = req.body.value;
vendorToUpdate.save();
return res.json(vendorToUpdate);
});
- Trouble connecting front and back ends - moved CORS up above Express in the index.js to fix
- 'createdAt' & 'updatedAt' keys were rendering twice in the local host. The reason for this was because we were not seeding/migrating our data properly.
- Image upload with Amazon Web Service(AWS)
- Seqelize Docs
- Express Docs
- General Assembly AWS Repository
- Robin Wieruch Blog
- JD Tadlock Youtube Channel
- Traversy Media Youtube Channel
Additional documentation can be found in the frontend repository Click here