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

LisaCee #3

Open
wants to merge 93 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
eb54230
Update README.md
rholdy Mar 8, 2018
c91ed27
Update README.md
rholdy Mar 19, 2018
ab3f853
minor
mixelpixel Mar 30, 2018
f1f5c7f
minor
mixelpixel Mar 30, 2018
ea1dc05
Add a sentence about adding tests for endpoints
seanchen1991 Mar 30, 2018
4cb6e11
More instruction clarifications
seanchen1991 Mar 30, 2018
bbac77f
minor
mixelpixel Mar 31, 2018
c825d2b
added tests to MVP Task List
mixelpixel Apr 2, 2018
57a1d14
idem
mixelpixel Apr 2, 2018
7ab4598
task list update
mixelpixel Apr 3, 2018
7116be4
idem
mixelpixel Apr 3, 2018
4538181
Remove writing tests as a criteria
seanchen1991 Apr 5, 2018
00d3fd8
Add suggested workflow and deployment platforms to README
seanchen1991 Apr 6, 2018
55d3151
Rearrange ordering of README
seanchen1991 Apr 6, 2018
3fb6922
Update README.md
seanchen1991 Apr 6, 2018
f6da9fd
Update README.md
May 25, 2018
4285596
Update README.md
May 25, 2018
505c1ab
updates requirements and stretch
May 25, 2018
281ce6a
Update README.md
Jun 20, 2018
1be8cf8
Update README.md
Jun 20, 2018
edd7bda
initial commit, accidentally forked from wrong branch
LisaCee Jul 17, 2018
9c0b6c1
initial commit, accidentally forked from wrong branch
LisaCee Jul 17, 2018
0a2bce0
trello and heroku links added, setup complete
LisaCee Jul 17, 2018
ee0e83a
trello and heroku links added, setup complete
LisaCee Jul 17, 2018
05e0ea9
playing with server example
LisaCee Jul 18, 2018
76a058f
playing with server example
LisaCee Jul 18, 2018
5a291b9
heroku not working, uninstalled mongoose
LisaCee Jul 18, 2018
d17d95a
heroku not working, uninstalled mongoose
LisaCee Jul 18, 2018
087c10f
updated package.json with engines
LisaCee Jul 18, 2018
b52a9ce
updated package.json with engines
LisaCee Jul 18, 2018
a1e0ed0
mongoose added
LisaCee Jul 18, 2018
73f5903
mongoose added
LisaCee Jul 18, 2018
a44ae65
removed express and added mongoose to index
LisaCee Jul 18, 2018
2ec74a8
removed express and added mongoose to index
LisaCee Jul 18, 2018
b38d78c
installed mongoose
LisaCee Jul 18, 2018
4413d23
installed mongoose
LisaCee Jul 18, 2018
c215917
added mongoose and morgan
LisaCee Jul 18, 2018
3860fdb
added mongoose and morgan
LisaCee Jul 18, 2018
0cfe64b
changed server to app
LisaCee Jul 18, 2018
2b54350
changed server to app
LisaCee Jul 18, 2018
cbdbc62
added server req to index
LisaCee Jul 18, 2018
fc98c80
added server req to index
LisaCee Jul 18, 2018
9e6764f
re-post for heroku
LisaCee Jul 18, 2018
e0b8da3
re-post for heroku
LisaCee Jul 18, 2018
f7cf43b
heroku working again with server
LisaCee Jul 18, 2018
e978bd0
heroku working again with server
LisaCee Jul 18, 2018
18fdb2b
post to db working, showing on mlab
LisaCee Jul 18, 2018
8d62197
post to db working, showing on mlab
LisaCee Jul 18, 2018
ba94eb1
post, get, getbyid working in postman
LisaCee Jul 18, 2018
0db460e
post, get, getbyid working in postman
LisaCee Jul 18, 2018
d714532
added helmet to server
LisaCee Jul 18, 2018
a477d7a
added helmet to server
LisaCee Jul 18, 2018
551af9c
edit note by id working
LisaCee Jul 18, 2018
c8ce657
edit note by id working
LisaCee Jul 18, 2018
cd05644
delete note working
LisaCee Jul 18, 2018
e870a36
delete note working
LisaCee Jul 18, 2018
dd323a0
user schema and bcrypt started
LisaCee Jul 18, 2018
296e15c
user schema and bcrypt started
LisaCee Jul 18, 2018
029a797
3 tests written for note model
LisaCee Jul 18, 2018
d264ccd
3 tests written for note model
LisaCee Jul 18, 2018
5580ddb
broke out noteRoutes into own file
LisaCee Jul 18, 2018
7aee968
broke out noteRoutes into own file
LisaCee Jul 18, 2018
84cd63f
userRoutes and user tests working
LisaCee Jul 19, 2018
b9f341d
userRoutes and user tests working
LisaCee Jul 19, 2018
79ae301
server testing complete, userRoute tests started
LisaCee Jul 19, 2018
4ffce45
server testing complete, userRoute tests started
LisaCee Jul 19, 2018
bef6038
some noteRoute tests written
LisaCee Jul 19, 2018
29b7e1f
some noteRoute tests written
LisaCee Jul 19, 2018
ce51f39
working on .env file
LisaCee Jul 20, 2018
9e47e04
working on .env file
LisaCee Jul 20, 2018
6d7cf4f
no env
LisaCee Jul 20, 2018
7dba7dd
no env
LisaCee Jul 20, 2018
1ad154a
Delete process.env
LisaCee Jul 20, 2018
5dab5e8
deleted process.env
LisaCee Jul 20, 2018
0f76c14
merge conflict
LisaCee Jul 20, 2018
7127e98
fixed testdb password
LisaCee Jul 20, 2018
49a2c2d
connecting to front end tweaks
LisaCee Jul 21, 2018
a6ff56c
changed post note route
LisaCee Jul 24, 2018
6d82f7f
changed post route back
LisaCee Jul 24, 2018
bde2b83
fixed edit route
LisaCee Jul 24, 2018
1722f2e
added api to routes
LisaCee Jul 25, 2018
70491d5
tweaked routes
LisaCee Jul 25, 2018
d6b7f32
routes not working
LisaCee Jul 25, 2018
68b48c7
typo in get
LisaCee Jul 25, 2018
399a803
typo in get
LisaCee Jul 25, 2018
b807593
typo in get
LisaCee Jul 25, 2018
4433a4e
routes fixed
LisaCee Jul 25, 2018
9a267e6
removed async from get
LisaCee Jul 25, 2018
9f12355
tweaked index port
LisaCee Jul 25, 2018
8470a4c
tweaked index port
LisaCee Jul 25, 2018
4f59bdd
tweaked index port
LisaCee Jul 25, 2018
dbd04cd
changed edit route
LisaCee Jul 26, 2018
85e9b6c
edit route
LisaCee Jul 26, 2018
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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
node_modules/

.DS_Store
<<<<<<< HEAD
.env
=======
process.env
>>>>>>> 1ad154acdfed4eabea764fb88ba3d8db2f8f5c47
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: node index.js
65 changes: 30 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
My Trello:
https://trello.com/b/W4TurebI/lambda-notes-back-end-lisacee

My Heroku URL:
https://lambda-notes-back-end.herokuapp.com/

## Trello Set Up:
* [X] Use your existing Trello account from the Front End Project, or create a new one
* [X] Create a new board called "Lambda Notes(Backend) - {Your Name}"
* [X] Create lists titled `backlog`,`To Do`, `In Progress`, and `Done`
* [X] Fill in the `To Do` list with the MVP features listed below
* [X] Fill in the `backlog` list with all the extra features listed below
* [X] Share your board with the project manager that has been assigned to you. If you have not been assigned yet, reach out to your Section Lead for guidance
* [X] Add your Trello URL to your project's README.md file. Commit the change, push it to your repository & submit a pull request

## Backend MVP Features:
* [X] Create a Database for your app
* [X] Design your models for your app. You should have a model for notes and for users. (The users model will come in handy when building out your stretch goals).
* [ ] Deploy your application to the web
* [X] Create a Node app and connect it to your database
* [X] Store Notes in your Database

Build an API Endpoint in your Node App for each of the following, and connect them to your React App. These should all be read from your Database and scoped to the logged in user.
* [X] Display a list of notes
* [X] Create a note with a title and content
* [X] View an existing note
* [X] Edit an existing note
* [X] Delete an existing note
* [ ] Link up your Front End Project to your new and improved backend

# Back End Project Week
This week you will be building a backend for a note taking app called "Lambda Notes."

Expand All @@ -8,15 +38,6 @@ The main objective of this week is to develop a backend to support the LambdaNot
## Git Commits
* You are required to showcase progress with at least 1 commit a day. This will let your project manager know where you are and if you need help. This also allows the client to get progress reports from the company in a real world setting. This also protects you from losing your work if your computer blows up.

## Trello Set Up:
* [ ] Use your existing Trello account from the Front End Project, or create a new one
* [ ] Create a new board called "Lambda Notes(Backend) - {Your Name}"
* [ ] Create lists titled `backlog`,`To Do`, `In Progress`, and `Done`
* [ ] Fill in the `To Do` list with the Backend MVP features listed below
* [ ] Fill in the `backlog` list with all the extra features listed below
* [ ] Share your board with the project manager that has been assigned to you. If you have not been assigned yet, reach out to your Section Lead for guidance
* [ ] Add your Trello URL to your project's README.md file. Commit the change, push it to your repository & submit a pull request

## Backend MVP Features:
It is suggested that you deploy the server and database first, before you undergo implementing the logic. Doing this makes the deployment process much simpler, since there's no code yet to complicate the deployment step. We recommend you deploy your server to [Heroku](https://devcenter.heroku.com/articles/getting-started-with-nodejs#introduction), and your Mongo database to [mlab](https://docs.mlab.com/). The recommended deployment site for the front end is [netlify](https://www.netlify.com/blog/2016/09/29/a-step-by-step-guide-deploying-on-netlify/).

Expand All @@ -36,33 +57,7 @@ Build an API Endpoint for each of the following, and connect it to your React Ap
* [ ] Delete an existing note
* [ ] Link up your Front End Project to your new and improved backend

Upon your first commit, please submit a Pull Request and add _both_ the **Trello Set Up** and **Backend MVP Features** Task lists to your first Pull Request comment:

```markdown
## Trello Set Up:
* [ ] Use your existing Trello account from the Front End Project, or create a new one
* [ ] Create a new board called "Lambda Notes(Backend) - {Your Name}"
* [ ] Create lists titled `backlog`,`To Do`, `In Progress`, and `Done`
* [ ] Fill in the `To Do` list with the MVP features listed below
* [ ] Fill in the `backlog` list with all the extra features listed below
* [ ] Share your board with the project manager that has been assigned to you. If you have not been assigned yet, reach out to your Section Lead for guidance
* [ ] Add your Trello URL to your project's README.md file. Commit the change, push it to your repository & submit a pull request

## Backend MVP Features:
* [ ] Create a Database for your app
* [ ] Design your models for your app. You should have a model for notes and for users. (The users model will come in handy when building out your stretch goals).
* [ ] Deploy your application to the web
* [ ] Create a Node app and connect it to your database
* [ ] Store Notes in your Database

Build an API Endpoint in your Node App for each of the following, and connect them to your React App. These should all be read from your Database and scoped to the logged in user.
* [ ] Display a list of notes
* [ ] Create a note with a title and content
* [ ] View an existing note
* [ ] Edit an existing note
* [ ] Delete an existing note
* [ ] Link up your Front End Project to your new and improved backend
```

***
## Once you have completed the Backend Minimum Viable Product requirements, direct message your project manager for approval. If approved, you may continue working on the Extra Features. Please add the Extra Features to your Task List in the first comment on your PR.
Expand Down
22 changes: 22 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require('dotenv').config();
const PORT = process.env.PORT || 5000;
const mongoose = require('mongoose');
const server = require('./server')

const options = {
user: process.env.DB_USER,
pass: process.env.DB_PASS,
useNewUrlParser: true
}

mongoose
.connect(process.env.DB_HOST, options)
.then(() => {
console.log('Connected to mongodb!!')
server.listen(PORT, () => {
console.log(`Listening on ${PORT}`)
})
})
.catch(err => {
console.log(err);
})
23 changes: 23 additions & 0 deletions models/Note.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const mongoose = require('mongoose');
const { Schema } = mongoose;

const note = {
title: {
type: String,
required: true,
maxlength: 15
},
content: {
type: String,
required: true,
maxlength: 100
}
}

const options = {
timestamps: true,
}

const noteSchema = new mongoose.Schema(note, options);

module.exports = mongoose.model('Note', noteSchema);
33 changes: 33 additions & 0 deletions models/User.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const mongoose = require('mongoose');
const bcrypt = require('bcrypt')

const User = new mongoose.Schema({
email: {
type: String,
required: true,
unique: true
},
username: {
type: String,
required: true,
unique: true
},
password: {
type: String,
required: true,
minlength: 8
}
})

User.pre('save', function (next) {
bcrypt.hash(this.password, 11, (err, hash) => {
if (err) {
return next(err)
} else {
this.password = hash;
return next()
}
})
})

module.exports = mongoose.model('User', User)
36 changes: 36 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "back-end-project-week",
"version": "1.0.0",
"description": "This week you will be building a backend for a note taking app called \"Lambda Notes.\"",
"main": "index.js",
"scripts": {
"test": "jest --watch --verbose",
"start": "nodemon index.js"
},
"jest": {
"testEnvironment": "node"
},
"repository": {
"type": "git",
"url": "git+https://github.com/LisaCee/back-end-project-week.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/LisaCee/back-end-project-week/issues"
},
"homepage": "https://github.com/LisaCee/back-end-project-week#readme",
"dependencies": {
"bcrypt": "^3.0.0",
"cors": "^2.8.4",
"dotenv": "^6.0.0",
"express": "^4.16.3",
"helmet": "^3.12.1",
"jest": "^23.4.1",
"mongoose": "^5.2.4",
"morgan": "^1.9.0",
"nodemon": "^1.18.3",
"supertest": "^3.1.0"
}
}
87 changes: 87 additions & 0 deletions routes/noteRoutes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
const server = require('express').Router();

const Note = require('../models/Note');

server.get('/', (req, res) => {
Note.find()
.then(notes => {
res.status(200).json(notes);
})
.catch(err => {
res
.status(500)
.json({ message: 'There was a problem getting your notes', error: err });
});
});

server.get('/:id', (req, res) => {
const { id } = req.params;

Note.findById(id)
.then(note => {
if (note !== null) {
res.status(200).json(note);
} else {
res.status(404).json({ message: "That not could not be found." })
}
})
.catch(err => {
res
.status(500)
.json({ message: 'There was a problem getting your note', error: err });
});
});

server.post('/', async (req, res) => {
Note.create(req.body)
.then(note => {
res.status(201).json(note);
})
.catch(err => {
res
.status(500)
.json({ message: 'Error saving note to the DB', error: err });
});
});

server.put('/:id/edit', (req, res) => {
const { id } = req.params;
const changes = req.body;
const options = {
new: true,
};

Note.findByIdAndUpdate(id, changes, options)
.then(note => {
if (note) {
res.status(200).json(note);
} else {
res.status(404).json({ message: 'Note not found' });
}
})
.catch(err => {
res
.status(500)
.json({ message: 'There was a problem finding that note', error: err });
});
});

server.delete('/:id', (req, res) => {
const { id } = req.params;

if (!id) {
res.status(422).json({ message: 'You need to give me an ID' });
} else {
Note.findByIdAndRemove(id)
.then(note => {
if (note) {
res.status(204).end();
} else {
res.status(404).json({ message: 'Note not found' });
}
})
.catch(err => res.status(500).json(err));
}
});

module.exports = server;
67 changes: 67 additions & 0 deletions routes/userRoutes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const server = require('express').Router();
const cors = require('cors');
const User = require('../models/User');

server.use(cors());

server.get('/', (req, res) => {
User.find()
.then(users => {
res.status(200).json(users);
})
.catch(err => {
res.status(500)
.json({ message: 'There was a problem getting the users' });
});
});

// server.get('/:id', (req, res) => {
// const { id } = req.params;

// User.findById(id)
// .then(user => {
// if (user !== null) {
// res.status(200).json(user);
// } else {
// res.status(404).json({ message: "That not user could not be found." })
// }
// })
// .catch(err => {
// res
// .status(500)
// .json({ message: 'There was a problem getting that user' });
// });
// });

server.post('/signup', (req, res) => {
User.create(req.body)
.then(user => {
res.status(201).json(user);
})
.catch(err => {
res
.status(500)
.json({ message: 'Error saving that user to the DB' });
});
});


// server.delete('/delete/:id', (req, res) => {
// const { id } = req.params;

// if (!id) {
// res.status(422).json({ message: 'You need to give me an ID' });
// } else {
// User.findByIdAndRemove(id)
// .then(user => {
// if (user) {
// res.status(204).end();
// } else {
// res.status(404).json({ message: 'User not found' });
// }
// })
// .catch(err => res.status(500).json(err));
// }
// });

module.exports = server;
23 changes: 23 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const express = require('express');
const morgan = require('morgan');
const helmet = require('helmet');
const cors = require('cors');

const noteRoutes = require('./routes/noteRoutes');
const userRoutes = require('./routes/userRoutes');

const server = express();

server.use(express.json());
server.use(helmet());
server.use(morgan('combined'));
server.use(cors());

server.get('/', (req, res) => {
res.json({ msg: "Connected" })
});

server.use('/api/notes', noteRoutes);
server.use('/api/user', userRoutes);

module.exports = server;
Loading