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

Updated Readme to include links to Backend and Frontend #39

Open
wants to merge 49 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
5ca1c98
skeleton
Aug 16, 2022
f262410
Merge pull request #1 from CharlieMoran/Charlie-Moran
CharlieMoran Aug 16, 2022
4d5802c
Trello board added
Aug 16, 2022
586a4fc
Merge pull request #2 from CharlieMoran/Charlie-Moran
CharlieMoran Aug 16, 2022
6a55035
NavBar added
Aug 16, 2022
0c46f87
Merge pull request #3 from CharlieMoran/Charlie-Moran
CharlieMoran Aug 16, 2022
fb94067
wireframes
Aug 16, 2022
e40e5d7
Merge pull request #4 from CharlieMoran/Charlie-Moran
CharlieMoran Aug 16, 2022
2dfab8d
ERD
Aug 16, 2022
e06e54e
Merge pull request #5 from CharlieMoran/Charlie-Moran
CharlieMoran Aug 16, 2022
dc1ede0
Push of doom
Aug 17, 2022
e7ccbaf
Back-end-routing update
HC-Guerrero Aug 17, 2022
37b29fc
Updated SnackController, 4 tests passed, 17 failed.
HC-Guerrero Aug 19, 2022
c9ac6a2
Added production sql files
HC-Guerrero Aug 19, 2022
d1f60f1
No clue what is wrong
Aug 19, 2022
d155c7d
edits
Aug 19, 2022
fdd1dae
back-end edit
Aug 19, 2022
9ea751c
Updated front end to work
HC-Guerrero Aug 19, 2022
1da060f
Merge pull request #7 from CharlieMoran/HermanVersion
CharlieMoran Aug 19, 2022
0496fcf
Merge pull request #8 from CharlieMoran/HermanVersion
CharlieMoran Aug 19, 2022
15b2430
Merge branch 'joinpursuit:main' into HermanVersion
HC-Guerrero Aug 19, 2022
9c648c9
Heroku 2nd deployment
HC-Guerrero Aug 19, 2022
f4e1d85
added validation and capitalize
Aug 19, 2022
2577615
Validation edit
Aug 19, 2022
e21becb
2 new tests passed for back end, 6 total pass
HC-Guerrero Aug 19, 2022
a334859
Merge to commit for new passing tests
HC-Guerrero Aug 19, 2022
b29b29a
Merge pull request #9 from CharlieMoran/HermanVersion
CharlieMoran Aug 19, 2022
f641a56
Update before heroku deployment 3rd
HC-Guerrero Aug 20, 2022
323b39d
Post Heroku deployment 8-19-22 Tranquil-Lowlands
HC-Guerrero Aug 20, 2022
a1ce273
12 tests pass, 9 fail
HC-Guerrero Aug 20, 2022
f36fa1b
all tests pass
HC-Guerrero Aug 20, 2022
ff1d28d
Added Show and Index to front end
HC-Guerrero Aug 20, 2022
7876c47
Merge pull request #11 from CharlieMoran/HermanVersion
CharlieMoran Aug 20, 2022
b64e6fc
Fixed error in pathing for createSnack
HC-Guerrero Aug 21, 2022
0417248
Fixed createSnack Navbar pathing
HC-Guerrero Aug 21, 2022
fb96aad
Snacks.js references fixed
HC-Guerrero Aug 21, 2022
9ccf640
Heroku deploy
HC-Guerrero Aug 22, 2022
2d59e7f
Commit before heroku deployment
HC-Guerrero Aug 22, 2022
4327489
Added images for Gallery and Individual View
HC-Guerrero Aug 22, 2022
32226be
Added deletion and Edit buttons and functionality in individual page,…
HC-Guerrero Aug 22, 2022
1446e92
Presentation Commit
HC-Guerrero Aug 22, 2022
1f1d455
refactored front end
HC-Guerrero Aug 22, 2022
8b84545
corrected validation casing
HC-Guerrero Aug 25, 2022
32a9c36
validation casing changes for Heroku
HC-Guerrero Aug 25, 2022
e660613
Deleted validation files, renamed .js file to valid.js
HC-Guerrero Aug 25, 2022
d4ecdf8
Removed validation to test backend deployment
HC-Guerrero Aug 25, 2022
c080a49
Added back validations
HC-Guerrero Aug 25, 2022
4149437
Snack changes
HC-Guerrero Aug 25, 2022
c4e315e
Updated Readme.md
HC-Guerrero Aug 29, 2022
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
Binary file added .DS_Store
Binary file not shown.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# Full Stack Application Pair Project

## Helpful Links
*You and your partner should include links or images of the following resources in this section:*

- Trello Board
- Wireframes
- ERDs
_You and your partner should include links or images of the following resources in this section:_

- [Trello Board](https://trello.com/b/7gD0SD4z/snack-a-log)
- [Wireframes](https://wireframe.cc/O22dps)
- [ERDs](https://miro.com/app/board/uXjVPe1UJRw=/?share_link_id=275986048292)
- [Backend] (https://fierce-badlands-55970.herokuapp.com/snacks)
- [Frontend(Broken)] (https://iridescent-ganache-912b37.netlify.app/)

## Snack-a-log

Expand All @@ -24,7 +27,7 @@ For this project there are 40 features or functionality to build. To pass this p
## Expecatations

- Each partner should commit and push their work at least once per day (for days we have class)
- You should edit the *Helpful Links* section of this readme to include links for your relevant project planning resources
- You should edit the _Helpful Links_ section of this readme to include links for your relevant project planning resources

## Submitting Your Work

Expand Down
Binary file added assets/SnackError.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added back-end/.DS_Store
Binary file not shown.
18 changes: 12 additions & 6 deletions back-end/app.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
// DEPENDENCIES
const express = require('express');
const cors = require('cors');

const express = require("express");
const snacksController = require('./controllers/snackController');

// CONFIGURATION
const app = express();
app.use(cors());
app.use(express.json());

// MIDDLEWARE
app.use('/snacks', snacksController);

// ROUTES
app.get('/', (request, response) => {
response.status(200).send("Get Snack'n at Snack-a-log!");
});
app.get('*', (request, response) => {
response.status(404).send('Oops, something went wrong getting your snacks!');
});

// EXPORT
module.exports = app;
17 changes: 16 additions & 1 deletion back-end/confirmHealth.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
const confirmHealth = (snack) => {};
const confirmHealth = (snack) => {
const { fiber, added_sugar, protein } = snack;
if (protein === null || added_sugar === null || fiber === null) {
return null;
}

if (added_sugar <= 5) {
if (protein >= 5 || fiber >= 5) {
return true;
} else {
return false;
}
} else {
return false;
}
};

module.exports = confirmHealth;
88 changes: 88 additions & 0 deletions back-end/controllers/snackController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
const express = require('express');
const {
getAllSnacks,
getSnack,
updateSnack,
createSnack,
deleteSnack,
} = require('../queries/snacks');
const snackController = express.Router();

snackController.get('/', async (request, response) => {
const allSnacks = await getAllSnacks();
if (allSnacks[0]) {
response.status(200).json({
success: true,
payload: allSnacks,
});
} else {
response.status(500).json();
}
});

snackController.get('/:id', async (request, response) => {
const { id } = request.params;
const snack = await getSnack(id);
if (snack.id) {
response.status(200).json({
success: true,
payload: snack,
});
} else {
response.status(404).json({
success: false,
id: id,
payload: `not found: no snack is listed at id${id}`,
});
}
});

snackController.delete('/:id', async (request, response) => {
const { id } = request.params;
const deletedSnack = await deleteSnack(id);
if (deletedSnack) {
if (deletedSnack.id) {
response.status(200).json({
success: true,
payload: deletedSnack,
});
} else {
response.status(404).json({
success: false,
payload: deletedSnack,
});
}
} else {
response.status(500).json({
success: false,
payload: deletedSnack,
});
}
});

snackController.post('/', async (request, response) => {
try {
const snack = await createSnack(request.body);
response.json({
success: true,
payload: snack,
});
} catch (error) {
return error;
}
});

snackController.put('/:id', async (request, response) => {
try {
const { id } = request.params;
const snacks = await updateSnack(id, request.body);
response.json({
success: true,
payload: snacks,
});
} catch (error) {
return error;
}
});

module.exports = snackController;
4 changes: 2 additions & 2 deletions back-end/db/dbConfig.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// http://vitaly-t.github.io/pg-promise/module-pg-promise.html
const pgp = require("pg-promise")();
require("dotenv").config();
const pgp = require('pg-promise')();
require('dotenv').config();

const { DATABASE_URL, PG_HOST, PG_PORT, PG_DATABASE, PG_USER } = process.env;
// https://github.com/vitaly-t/pg-promise/wiki/Connection-Syntax#configuration-object
Expand Down
6 changes: 6 additions & 0 deletions back-end/db/prod_schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
\c d4i3qdruuhh30p;

DROP TABLE IF EXISTS snacks;

CREATE TABLE snacks (id SERIAL PRIMARY KEY, name TEXT NOT NULL, fiber INT,
protein INT, added_sugar INT, is_healthy BOOLEAN, image TEXT );
9 changes: 9 additions & 0 deletions back-end/db/prod_seed.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
\c d4i3qdruuhh30p;

INSERT INTO snacks (name, fiber, protein, added_sugar, is_healthy, image) VALUES
('Strawberries', 20, 10, 0, true, 'https://picsum.photos/id/1080/300/300'),
('Raspberries', 16, 4, 0, true, 'https://picsum.photos/id/102/300/300'),
('Honey Covered Granola', 30, 12, 22, false, 'https://picsum.photos/id/312/300/300'),
('New Wave Nuts', 11, 55, 9, true, 'https://picsum.photos/id/139/300/300'),
('Raw Onions & Turnips', 11, 9, 9, true, 'https://picsum.photos/id/292/300/300'),
('Healthy Birthday Cake Square', 4, 8, 19, false, 'https://content.nutrisystem.com/images/products/alc/large/BirthdayCakeSquare_L.jpg');
9 changes: 7 additions & 2 deletions back-end/db/schema.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@

DROP DATABASE IF EXISTS snack_a_log;
CREATE DATABASE snack_a_log;

\c snack_a_log;
CREATE DATABASE snack_a_log;

\c snack_a_log;

DROP TABLE IF EXISTS snacks;

CREATE TABLE snacks (id SERIAL PRIMARY KEY, name TEXT NOT NULL, fiber INT,
protein INT, added_sugar INT, is_healthy BOOLEAN, image TEXT );
7 changes: 2 additions & 5 deletions back-end/db/seed.sql
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
\c snack_a_log;
\c snack_a_log;

INSERT INTO snacks (name, fiber, protein, added_sugar, is_healthy, image) VALUES
('Strawberries', 20, 10, 0, true, 'https://picsum.photos/id/1080/300/300'),
('Raspberries', 16, 4, 0, true, 'https://picsum.photos/id/102/300/300'),
('Honey Covered Granola', 30, 12, 22, false, 'https://picsum.photos/id/312/300/300'),
('New Wave Nuts', 11, 55, 9, true, 'https://picsum.photos/id/139/300/300'),
('Raw Onions & Turnips', 11, 9, 9, true, 'https://picsum.photos/id/292/300/300'),
('Healthy Birthday Cake Square', 4, 8, 19, false, 'https://content.nutrisystem.com/images/products/alc/large/BirthdayCakeSquare_L.jpg');

-- use advanced image search to choose images that are square (aspect ratio)
-- https://www.google.com/advanced_image_search
('Healthy Birthday Cake Square', 4, 8, 19, false, 'https://content.nutrisystem.com/images/products/alc/large/BirthdayCakeSquare_L.jpg');
4 changes: 2 additions & 2 deletions back-end/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion back-end/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "bookmarks",
"name": "snack-a-log",
"version": "1.0.0",
"description": "",
"main": "server.js",
Expand Down
80 changes: 78 additions & 2 deletions back-end/queries/snacks.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,79 @@
const db = require("../db/dbConfig.js");
const db = require('../db/dbConfig.js');
const nameFormatter = require('../validation/valid');

module.exports = {};
//GET all
const getAllSnacks = async () => {
try {
const allSnacks = await db.any('SELECT * FROM snacks');
return allSnacks;
} catch (error) {
return error;
}
};

//GET /:id
const getSnack = async (id) => {
try {
const snack = await db.one('SELECT * FROM snacks WHERE id=$1', id);
return snack;
} catch (error) {
return error;
}
};

//CREATE
const createSnack = async (snack) => {
try {
let { name, fiber, protein, added_sugar, is_healthy, image } = snack;
name = nameFormatter(name);
if (!image) {
image = `https://dummyimage.com/400x400/6e6c6e/e9e9f5.png&text=No+Image`;
}
if (isNaN(fiber)) {
fiber = 0;
}
if (isNaN(protein)) {
protein = 0;
}
if (isNaN(added_sugar)) {
added_sugar = 0;
}
return await db.one(
'INSERT INTO snacks (name, fiber, protein, added_sugar, is_healthy, image) VALUES($1, $2, $3, $4, $5, $6) RETURNING *',
[name, fiber, protein, added_sugar, is_healthy, image],
);
} catch (error) {
return error;
}
};

//DELETE
const deleteSnack = async (id) => {
try {
return await db.one('DELETE FROM snacks WHERE id=$1 RETURNING *', id);
} catch (error) {
return error;
}
};

//UPDATE
const updateSnack = async (
id,
{ name, fiber, protein, added_sugar, is_healthy, image },
) => {
try {
return await db.one(
'UPDATE snacks SET name=$1, fiber=$2, protein=$3, added_sugar=$4, is_healthy=$5, image=$6 WHERE id=$7 RETURNING *',
[name, fiber, protein, added_sugar, is_healthy, image, id],
);
} catch (error) {
return error;
}
};
module.exports = {
getAllSnacks,
getSnack,
createSnack,
deleteSnack,
updateSnack,
};
9 changes: 6 additions & 3 deletions back-end/server.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// DEPENDENCIES
const app = require("./app.js");

const app = require('./app.js');
const express = require('express');
const cors = require('cors');
// CONFIGURATION
require("dotenv").config();
require('dotenv').config();

const PORT = process.env.PORT;
const PORT = process.env.PORT || 3333;

// LISTEN
app.use(cors());
app.listen(PORT, () => {
console.log(`🥤 🍿 Snackin' on port ${PORT} 🥨 🌰 `);
});
22 changes: 22 additions & 0 deletions back-end/validation/valid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const nameFormatter = (name) => {
name = name.split(' ');
for (let i = 0; i < name.length; i++) {
if (name[i].length > 2) {
name[i] = capitalizeWord(name[i]);
}
}
name = name.join(' ');
return name;
};

const capitalizeWord = (word) => {
word = word.split('');
word[0] = word[0].toUpperCase();
for (let i = 1; i < word.length; i++) {
word[i] = word[i].toLowerCase();
}
word = word.join('');
return word;
};

module.exports = nameFormatter;
Loading