Skip to content

Commit b2b7f79

Browse files
authored
Merge branch 'master' into Nancy-sprint4
2 parents 378d25d + c39d166 commit b2b7f79

25 files changed

+238
-176
lines changed

README.md

+28-22
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
![Workflow Status](https://github.com/agiledev-students-spring-2023/final-project-what-s-for-dinner/blob/master/.github/workflows/back-end.yml/badge.svg?event=push)
1+
![Workflow Status](https://github.com/agiledev-students-spring-2023/final-project-what-s-for-dinner/actions/workflows/back-end.yml/badge.svg?event=push)
22

3-
![Workflow Status](https://github.com/agiledev-students-spring-2023/final-project-what-s-for-dinner/blob/master/.github/workflows/front-end.yml/badge.svg?event=push)
3+
![Workflow Status](https://github.com/agiledev-students-spring-2023/final-project-what-s-for-dinner/actions/workflows/front-end.yml/badge.svg?event=push)
44

55
## Project Description
66

@@ -34,32 +34,38 @@ Please refer to the [CONTRIBUTING.md](https://github.com/agiledev-students-sprin
3434

3535
**Front-end**
3636

37-
1. run `cd front-end` to navigate to front-end folder
38-
2. first run `npm install --legacy-peer-deps` (please ignore the error for now)
37+
1. first run `cd front-end` to navigate to front-end folder
38+
2. then run `npm install` to install the front-end dependencies
39+
3. create a `.env` file in the front-end directory with the following content:
40+
```
41+
PORT=3001
42+
REACT_APP_SERVER=http://localhost:3000
43+
```
3944

4045
**Back-end**
41-
42-
1. run `cd back-end` to navigate to back-end folder
43-
2. run `npm install`
44-
3. create a `.env` file in the back-end directory with the following information:
45-
> MEAL_DB_API_KEY=9973533
46-
> SPOONACULAR_API_KEY=86b8ac3348974b5ab495921e201be0de
47-
> JWT_SECRET=whats.for.dinner
48-
> JWT_EXP_DAYS=60
49-
> MONGODB_URI=mongodb+srv://dinner:[email protected]/test?retryWrites=true&w=majority
50-
> EMAIL_USERNAME=[email protected]
51-
> EMAIL_PASSWORD=nuzvkswprpbdvozh
52-
53-
*Note: You should go to "https://www.themealdb.com/" to create your own account and replace the value with your own api key. But for demonstrantion simplicity we provide you with the api key for now.*
46+
1. first run `cd back-end` to navigate to back-end folder
47+
2. then run `npm install` to install the back-end dependencies
48+
3. create a `.env` file in the back-end directory with the following content:
49+
```
50+
MEAL_DB_API_KEY=9973533
51+
JWT_SECRET=whats.for.dinner
52+
JWT_EXP_DAYS=60
53+
MONGODB_URI=mongodb+srv://dinner:[email protected]/test?retryWrites=true&w=majority
54+
SPOONACULAR_API_KEY=86b8ac3348974b5ab495921e201be0de
55+
56+
EMAIL_PASSWORD=nuzvkswprpbdvozh
57+
CORS_ORIGIN=http://localhost:3001
58+
```
59+
*Note: For this project, we have provided the following credentials. However, for real projects, please visit "https://www.themealdb.com/" to create an account and replace <MEAL_DB_API_KEY> with your own API key. Similarly, replace <MONGODB_URI> and <SPOONACULAR_API_KEY> with your respective API keys.*
5460

5561
### Running
62+
1. If you are testing either the front-end or back-end, you can run `npm start` in the corresponding folder.
63+
2. If you are running both the front-end and back-end together, run `npm start` separately in each folder and view the app on http://localhost:3001.
64+
3. If you are using a Windows PC, please run `npm run start-pc` instead of `npm start` for the front-end.
5665

57-
1. if you are only running the front-end or back-end for testing purpose, you can simply run `npm start` in the corresponding front-end/back-end folder
58-
2. if you are running both front-end and back-end, please first run `npm start` in the back-end folder and then in the front-end folder. When you encounter the question `Would you like to run the app on another port instead? › (Y/n)`, type "y" to run the front-end on port 3001.
59-
3. if you are working on a Windows PC, please use `npm run start-pc` instead for front-end.
66+
## Deployed front-end
67+
To view our front-end code live on the web, go to https://monkfish-app-fjlpj.ondigitalocean.app/
6068

61-
*Note: some of our pages won't work properly if you run back-end on port 3000 and front-end on port 3001*
62-
4. now you can open [http://localhost:3000](http://localhost:3000) in your browser to view our app.
6369

6470
## Additional Resources
6571

back-end/README.md

+40-24
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,55 @@ To install the back-end dependencies, run the following command in the terminal:
1313

1414
## Running the Server
1515
To start the back-end server, run the following command in the terminal:
16-
`npm start`
17-
Please make sure if you run front-end first before you start the back-end server.
16+
`npm start`.
1817
This will start the server at http://localhost:3000.
1918

2019
API Endpoints
2120
The back-end provides the following API endpoints:
2221

23-
/recipes - GET
24-
/recipes/sort-by-time - GET
25-
/recipes/sort-by-difficulty - GET
26-
/recipes/:id - GET
27-
/search - GET
28-
/random-recipe -GET
29-
/my-ingredients - GET, POST
30-
/search-ingredient - GET
31-
/utensils - GET, POST
32-
33-
## API_KEY/Database Configuration
22+
- POST /auth/signup: sign up a new user account
23+
- POST /auth/login: log in to an existing user account
24+
- POST /auth/logout: log out of an existing user account
25+
- GET /auth/user: get the current user's information
26+
- POST /auth/reset_password: request to reset the user's password
27+
- PUT /auth/reset_password/:token: reset the user's password using a password reset token
28+
- GET /recipes: get all recipes
29+
- GET /recipes/:id: get a single recipe by ID
30+
- POST /recipes: add a new recipe
31+
- PUT /recipes/:id: update an existing recipe by ID
32+
- DELETE /recipes/:id: delete an existing recipe by ID
33+
- GET /ingredients: get all ingredients
34+
- GET /ingredients/:id: get a single ingredient by ID
35+
- POST /ingredients: add a new ingredient
36+
- PUT /ingredients/:id: update an existing ingredient by ID
37+
- DELETE /ingredients/:id: delete an existing ingredient by ID
38+
- GET /utensils: get all utensils
39+
- GET /utensils/:id: get a single utensil by ID
40+
- POST /utensils: add a new utensil
41+
- PUT /utensils/:id: update an existing utensil by ID
42+
- DELETE /utensils/:id: delete an existing utensil by ID
43+
- POST /share-recipes: upload a new recipe
44+
- POST /cookie: set a cookie for the user
45+
- GET /protected: get some protected content that requires authentication
46+
- POST /contact-us: send a message through the contact us form.
47+
48+
## External APIs / Database Configuration
3449
The back-end connects to relevant APIs and a MongoDB database. To configure the database connection, create a .env file in the root directory with the following information:
35-
'''
36-
MEAL_DB_API_KEY=<meal_db_api_key>
37-
DB_HOST=<database_host>
38-
DB_NAME=<database_name>
39-
DB_USERNAME=<database_username>
40-
DB_PASSWORD=<database_password>
41-
'''
42-
Go to "https://www.themealdb.com/" to create an account.
43-
Replace <meal_db_api_key> with your own api key.
44-
Replace <database_host>, <database_name>, <database_username>, and <database_password> with your actual database information.
50+
```
51+
MEAL_DB_API_KEY=9973533
52+
JWT_SECRET=whats.for.dinner
53+
JWT_EXP_DAYS=60
54+
MONGODB_URI=mongodb+srv://dinner:[email protected]/test?retryWrites=true&w=majority
55+
SPOONACULAR_API_KEY=86b8ac3348974b5ab495921e201be0de
56+
57+
EMAIL_PASSWORD=nuzvkswprpbdvozh
58+
CORS_ORIGIN=http://localhost:3001
59+
```
60+
For this project, we have provided the following credentials. However, for real projects, please visit "https://www.themealdb.com/" to create an account and replace <MEAL_DB_API_KEY> with your own API key. Similarly, replace <MONGODB_URI> and <SPOONACULAR_API_KEY> with your respective API keys.
4561

4662
## Unit testing
4763
To run the test suite and generate a code coverage report using Istanbul NYC, you can use the following command:
48-
`npx nyc mocha --exit`
64+
`npm test`
4965

5066
## Contributing
5167
To contribute to the back-end, please follow these steps:

back-end/controllers/RecipeController.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,11 @@ class RecipeController {
158158
rating
159159
};
160160
recipe.Comments.push(newComment);
161-
await recipe.save();
162161
const averageRating = await RecipeController.getAverageRating(recipeId);
163162
recipe.Rating = averageRating;
163+
console.log(recipe.Rating)
164+
await recipe.save();
165+
console.log(recipe.Rating)
164166
res.status(200).json({ message: 'Comment added successfully', averageRating});
165167
} catch (error) {
166168
console.error(error);

back-end/models/recipes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ let recipeSchema = new Schema(
99
Instructions: {type: String},
1010
Image_Name: {type: String},
1111
Cleaned_Ingredients: {type: String},
12-
Rating: {type: Number},
12+
Rating: {type: Number, default: 0},
1313
Comments: {type: Array}
1414
}
1515
)

back-end/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "The back-end of your project will live in this directory.",
55
"main": "index.js",
66
"scripts": {
7-
"test": "nyc mocha test/**/*.js",
7+
"test": "nyc mocha test/**/*.js --exit",
88
"start": "node server.js"
99
},
1010
"keywords": [],

back-end/routes/ingredients.js

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ const express = require('express');
22
const router = express.Router();
33
const IngredientModel = require('../models/ingredients.js');
44
const { body, validationResult } = require('express-validator');
5+
const fetch = (...args) => import('node-fetch')
6+
.then(({default: fetch}) => fetch(...args));
57

68
// Get all ingredients from the database
79
router.get('/my-ingredients', async (req, res) => {

back-end/test/login.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe("Login", () => {
3333
})
3434

3535
describe("POST /auth/login with correct username/password", () => {
36-
const formData = { username: "ginettexu", password: "jmb8dshp" } // mock form data with correct credentials
36+
const formData = { username: "chenyi", password: "123456" } // mock form data with correct credentials
3737
it("it should return a 200 HTTP response code", done => {
3838
chai
3939
.request(server)

back-end/test/share-recipes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ describe('POST /share-recipes', () => {
156156
.end((err, res) => {
157157
expect(err).to.be.null;
158158
expect(res).to.have.status(200);
159-
expect(res.body).to.have.property('message', 'Recipe uploaded successfully.');
159+
expect(res.body).to.have.property('message', 'Recipe successfully uploaded');
160160
done();
161161
});
162162
});

front-end/README.md

+8-68
Original file line numberDiff line numberDiff line change
@@ -2,73 +2,13 @@
22

33
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
44

5-
## Setting up
6-
1. run `npm install`, please ignore the error appeared for now, we will resolve it later.
7-
2. then run `npm i @material-ui/core --force --save`
5+
## Installation
6+
To install the front-end dependencies, run the following command in the terminal:
7+
`npm install`
88

9-
## Available Scripts
9+
## Running the Server
10+
To start the front-end server, run the following command in the terminal:
11+
`npm start`. This will start the server at http://localhost:3001.
1012

11-
In the project directory, you can run:
12-
13-
### `npm start`
14-
**Note**: Please run the front-end first before you start the back-end server.
15-
Runs the app in the development mode.\
16-
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
17-
18-
The page will reload when you make changes.\
19-
You may also see any lint errors in the console.
20-
21-
### `npm test`
22-
23-
Launches the test runner in the interactive watch mode.\
24-
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
25-
26-
### `npm run build`
27-
28-
Builds the app for production to the `build` folder.\
29-
It correctly bundles React in production mode and optimizes the build for the best performance.
30-
31-
The build is minified and the filenames include the hashes.\
32-
Your app is ready to be deployed!
33-
34-
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
35-
36-
### `npm run eject`
37-
38-
**Note: this is a one-way operation. Once you `eject`, you can't go back!**
39-
40-
If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
41-
42-
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
43-
44-
You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
45-
46-
## Learn More
47-
48-
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
49-
50-
To learn React, check out the [React documentation](https://reactjs.org/).
51-
52-
### Code Splitting
53-
54-
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
55-
56-
### Analyzing the Bundle Size
57-
58-
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
59-
60-
### Making a Progressive Web App
61-
62-
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
63-
64-
### Advanced Configuration
65-
66-
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
67-
68-
### Deployment
69-
70-
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
71-
72-
### `npm run build` fails to minify
73-
74-
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
13+
## Deployed front-end
14+
To view our front-end code live on the web, go to https://monkfish-app-fjlpj.ondigitalocean.app/

front-end/package.json

+3-9
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
"web-vitals": "^3.3.1"
1717
},
1818
"scripts": {
19-
"start": "PORT=3001 HOST=0.0.0.0 react-scripts start",
19+
"start": "PORT=3001 react-scripts start",
2020
"start-pc": "set PORT=3001 && react-scripts start",
2121

2222
"build": "react-scripts build",
2323
"test": "react-scripts test",
2424
"eject": "react-scripts eject"
2525
},
26-
"proxy": "https://lobster-app-4dv57.ondigitalocean.app/",
26+
"proxy": "https://lobster-app-4dv57.ondigitalocean.app",
2727
"eslintConfig": {
2828
"extends": [
2929
"react-app",
@@ -41,11 +41,5 @@
4141
"last 1 firefox version",
4242
"last 1 safari version"
4343
]
44-
},
45-
"devServer": {
46-
"allowedHosts": [
47-
"0.0.0.0",
48-
"monkfish-app-fjlpj.ondigitalocean.app"
49-
]
50-
}
44+
}
5145
}

front-end/src/Home.css

+5
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@ nav a {
1414
text-decoration: none;
1515
color: black;
1616
}
17+
18+
h2 {
19+
text-align: center;
20+
font-size: larger;
21+
}

front-end/src/Home.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const Home = (props) => {
3232
<li><Link to="/my-ingredients">My Ingredients</Link></li>
3333
<li><Link to="/utensils">My Utensils</Link></li>
3434
<li><Link to="/saved-recipes">My Saved Recipes</Link></li>
35-
<li><Link to="/recipes">Search Recipes</Link></li>
35+
<li><Link to="/search">Search Recipes</Link></li>
3636
</ul>
3737
</nav>
3838
<div className="RecipeList">

front-end/src/Login.css

+15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
.Login {
2+
width: 100%;
3+
display: flex;
4+
flex-direction: column;
5+
align-items: center;
6+
justify-content: center;
7+
padding: 0;
8+
margin: 0;
29
}
10+
11+
.Login .main-content form {
12+
display: flex;
13+
flex-direction: column;
14+
justify-content: center;
15+
margin-right: 10px;
16+
}
17+
318
.Login .error {
419
margin-left: 20px;
520
color: red;

front-end/src/Login.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ const Login = props => {
8080
// otherwise, if the user has successfully logged-in, redirect them to a different page
8181
// in this example, we simply redirect to the home page, but a real app would redirect
8282
//to a page that shows content only available to logged-in users
83-
else return <Navigate to="/" />
83+
else return <Navigate to="/home" />
8484
}
8585

8686
export default Login

front-end/src/MyIngredients.css

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
.container {
22
margin: 0 auto;
33
width: 80%;
4+
align-items: center;
45
}
56

67
.button-link {
78
color: #ffffff;
89
text-align: center;
910
text-decoration: none;
11+
font-size: medium;
12+
max-width: 200px;
1013
}
1114

12-
h1 {
15+
.h1 {
1316
text-align: center;
17+
font-size: small;
1418
}
1519

1620
.form-container {

0 commit comments

Comments
 (0)