-
Notifications
You must be signed in to change notification settings - Fork 446
Mitchell Robles - back-end-project-week #480
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
Open
mitchellr92
wants to merge
16
commits into
bloominstituteoftechnology:master
Choose a base branch
from
mitchellr92:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
edaa8c9
added Trello board
mitchellr92 60e313a
added dependencies and added node modules to git ignore
mitchellr92 e68776c
set up very basic server
mitchellr92 694ec53
Added knex file
mitchellr92 648ea86
Added migration and seed files
mitchellr92 b55bb7f
configured knex in index.js and created get by id functionality. Also…
mitchellr92 a995da8
Created get request for all notes and create note functionality
mitchellr92 0717bc5
Edit and delete functionality created. All basic set up for endpoitns…
mitchellr92 3df25a3
Minor clean up of code
mitchellr92 e19c95b
added dependencies so front end project has access to back end server
mitchellr92 ac20cce
Progress note in index.js
mitchellr92 7324948
continuing to refact front end
mitchellr92 9ba82ba
Front end refactoring is complete!
mitchellr92 52c7959
Put request
mitchellr92 67c9fcb
fixed error
mitchellr92 d64d60d
getting ready to deploy on heroku
mitchellr92 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| .DS_Store | ||
| node_modules/ |
This file contains hidden or 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 @@ | ||
| web: node index.js |
This file contains hidden or 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 hidden or 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,12 @@ | ||
|
|
||
| exports.up = function(knex, Promise) { | ||
| return knex.schema.createTable('notes', table => { | ||
| table.increments(); | ||
| table.string('title').notNullable(); | ||
| table.string('body').notNullable(); | ||
| }) | ||
| }; | ||
|
|
||
| exports.down = function(knex, Promise) { | ||
| return knex.schema.dropTableIfExists('notes'); | ||
| }; |
Binary file not shown.
This file contains hidden or 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,13 @@ | ||
|
|
||
| exports.seed = function(knex, Promise) { | ||
| // Deletes ALL existing entries | ||
| return knex('notes').del() | ||
| .then(function () { | ||
| // Inserts seed entries | ||
| return knex('notes').insert([ | ||
| {id: 1, title: 'Note1', body: 'Body1'}, | ||
| {id: 2, title: 'Note2', body: 'Body2'}, | ||
| {id: 3, title: 'Note3', body: 'Body3'} | ||
| ]); | ||
| }); | ||
| }; |
This file contains hidden or 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,90 @@ | ||
| const express = require('express'); | ||
| const cors = require('cors'); | ||
| const morgan = require('morgan'); | ||
| const helmet = require('helmet'); | ||
| const knex = require('knex'); | ||
| const dbConfig = require('./knexfile.js'); | ||
| const db = knex(dbConfig.development); | ||
|
|
||
| const server = express(); | ||
|
|
||
| server.use(express.json()); | ||
| server.use(cors()); | ||
| server.use(morgan()); | ||
| server.use(helmet()); | ||
|
|
||
|
|
||
| const PORT = process.env.PORT || 2200; | ||
|
|
||
| server.post('/api/notes', (req, res) => { | ||
| const newNote = req.body; | ||
|
|
||
| if (newNote.title && newNote.body) { | ||
| db('notes').insert(newNote) | ||
| .then(noteId => { | ||
| res.status(200).json(noteId); | ||
| }) | ||
| .catch(err => { | ||
| res.status(500).json({ message: 'Failure to create note' }); | ||
| }) | ||
| } else { | ||
| res.status(400).json({ message: 'Missing title or body' }); | ||
| }; | ||
| }); | ||
|
|
||
| server.get('/api/notes', (req, res) => { | ||
| db('notes') | ||
| .then(notes => { | ||
| res.status(200).json(notes); | ||
| }) | ||
| .catch(err => { | ||
| res.status(500).json({ message: 'Failure to load notes' }); | ||
| }); | ||
| }); | ||
|
|
||
| server.get('/api/notes/:id', (req, res) => { | ||
| const { id } = req.params; | ||
|
|
||
| db('notes').where({ id }) | ||
| .then(note => { | ||
| res.status(200).json(note); | ||
| }) | ||
| .catch(err => { | ||
| res.status(500).json({ message: 'Failed to get note' }) | ||
| }) | ||
| }); | ||
|
|
||
| server.put('/api/notes/:id', (req, res) => { | ||
| const { id } = req.params; | ||
| const noteEdit = req.body; | ||
|
|
||
| if (noteEdit.title && noteEdit.body) { | ||
| db('notes').where({ id }).update(noteEdit) | ||
| .then(note => { | ||
| res.status(200).json('Note has been successfully edited!'); | ||
| }) | ||
| .catch(err => { | ||
| res.status(500).json({ message: 'Failure to edit note' }); | ||
| }) | ||
| } else { | ||
| res.status(400).json({ message: 'Missing title or body' }) | ||
| }; | ||
| }); | ||
|
|
||
| server.delete('/api/notes/:id', (req, res) => { | ||
| const { id } = req.params; | ||
|
|
||
| db('notes').where({ id }).del() | ||
| .then(note => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This parameter is called |
||
| res.status(201).json('Note has been deleted'); | ||
| }) | ||
| .catch(err => { | ||
| res.status(500).json({ message: 'Failed to delete note' }); | ||
| }) | ||
| }); | ||
|
|
||
| server.listen(PORT, () => { | ||
| console.log(`Listening on port ${PORT}`) | ||
| }); | ||
|
|
||
| // Front end is now working with back end with complete functionality! | ||
This file contains hidden or 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,16 @@ | ||
| module.exports = { | ||
|
|
||
| development: { | ||
| client: 'sqlite3', | ||
| connection: { | ||
| filename: './data/notes.sqlite3' | ||
| }, | ||
| useNullAsDefault: true, | ||
| migrations: { | ||
| directory: './data/migrations' | ||
| }, | ||
| seeds: { | ||
| directory: './data/seeds' | ||
| } | ||
| } | ||
| }; |
This file contains hidden or 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,22 @@ | ||
| { | ||
| "name": "back-end-project-week", | ||
| "version": "1.0.0", | ||
| "main": "index.js", | ||
| "scripts": { | ||
| "server": "nodemon index.js" | ||
| }, | ||
| "repository": "https://github.com/mitchellr92/back-end-project-week.git", | ||
| "author": "<[email protected]>", | ||
| "license": "MIT", | ||
| "dependencies": { | ||
| "cors": "^2.8.5", | ||
| "express": "^4.16.4", | ||
| "helmet": "^3.15.1", | ||
| "knex": "^0.16.3", | ||
| "morgan": "^1.9.1", | ||
| "sqlite3": "^4.1.1" | ||
| }, | ||
| "devDependencies": { | ||
| "nodemon": "^1.18.10" | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This board is private!