Skip to content
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
4a594dc
scaffolding
jmpaik Dec 15, 2016
5c20099
dependencies and start server
jmpaik Dec 15, 2016
c696d43
parse json
jmpaik Dec 15, 2016
d6c1066
parse url
jmpaik Dec 15, 2016
362afd5
router
jmpaik Dec 15, 2016
ba3fb10
storage
jmpaik Dec 15, 2016
c59ee7a
node uuid in note.js
jmpaik Dec 15, 2016
7288d90
router GET
jmpaik Dec 15, 2016
acff9f4
router POST
jmpaik Dec 15, 2016
4984d43
router DELETE
jmpaik Dec 15, 2016
8740660
add DELETE method in server and storage
jmpaik Dec 15, 2016
9123260
minor edit in server and started testing
jmpaik Dec 15, 2016
4f146b6
add bluebird and testing branch PR
jmpaik Dec 16, 2016
90ce984
changed note properties and finished testing
jmpaik Dec 16, 2016
7878110
refactoring route responses
jmpaik Dec 16, 2016
e4c40a4
response refactor complete
jmpaik Dec 16, 2016
495b740
refactoring storage
jmpaik Dec 16, 2016
591e1a5
completed storage refactor
jmpaik Dec 16, 2016
95c454e
major debugging
jmpaik Dec 19, 2016
012fd19
weird DS store
jmpaik Dec 19, 2016
0ccd393
finished readme
jmpaik Dec 19, 2016
248664f
syntax error fix in storage
jmpaik Dec 19, 2016
f389ae3
fixed syntax error in tests
jmpaik Dec 19, 2016
0d9baa6
edit README file
jmpaik Dec 19, 2016
2812292
begin express refactor
jmpaik Dec 19, 2016
a9e2ba5
refactor restaurant file
jmpaik Dec 19, 2016
9e8a1fd
added create and fectch method in restaurant file
jmpaik Dec 19, 2016
4248f42
build POST in server file
jmpaik Dec 19, 2016
da3911a
debug createError in storage
jmpaik Dec 20, 2016
db96422
added delete to storage with debug
jmpaik Dec 20, 2016
7fb9b82
debugging delete in server.js
jmpaik Dec 20, 2016
0ef2fba
fixed delete function in server
jmpaik Dec 20, 2016
621363b
debugged tests to comply with express messaging
jmpaik Dec 20, 2016
f82811d
deleted const storage in server
jmpaik Dec 20, 2016
3c91311
refactoring express api
jmpaik Dec 20, 2016
5fdb083
delete corpse code
jmpaik Dec 20, 2016
1dd273d
added test and debug files with linter errors
jmpaik Dec 21, 2016
d2c35ad
debugging tests
jmpaik Dec 21, 2016
e5ac626
setup server for mongo demo
jmpaik Dec 21, 2016
00318ab
beginning code for mongodb refactor
jmpaik Dec 21, 2016
ebadc8f
debug and writing more tests
jmpaik Dec 22, 2016
0425121
completed writing tests
jmpaik Dec 22, 2016
ec6199d
debugging
jmpaik Dec 27, 2016
d2349af
debugged list model
jmpaik Dec 27, 2016
3df7c93
writing more tests
jmpaik Dec 27, 2016
c5c3bde
ds store remove
jmpaik Dec 27, 2016
dadadae
debug testing and other files
jmpaik Dec 30, 2016
e932cd5
completed debugging list tests
jmpaik Dec 30, 2016
f53e691
finished writing test and debugging
jmpaik Dec 31, 2016
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
21 changes: 21 additions & 0 deletions lab-jinho/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"rules": {
"no-console": "off",
"indent": [ "error", 2 ],
"quotes": [ "error", "single" ],
"semi": ["error", "always"],
"linebreak-style": [ "error", "unix" ]
},
"env": {
"es6": true,
"node": true,
"mocha": true,
"jasmine": true
},
"ecmaFeatures": {
"modules": true,
"experimentalObjectRestSpread": true,
"impliedStrict": true
},
"extends": "eslint:recommended"
}
146 changes: 146 additions & 0 deletions lab-jinho/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
Skip to content
This repository
Search
Pull requests
Issues
Gist
@jmpaik
Watch 5
Star 1
Fork 8 codefellows/seattle-javascript-401d12
Code Issues 0 Pull requests 0 Projects 0 Wiki Pulse Graphs
Branch: master Find file Copy pathseattle-javascript-401d12/06-tcp_servers/demo/chat-server/.gitignore
78ba337 a day ago
@bnates bnates added lecture 06
1 contributor
RawBlameHistory
128 lines (94 sloc) 1.85 KB
# Created by https://www.gitignore.io/api/node,vim,macos,linux,windows

node_modules/

### Node ###
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity



### Vim ###
# swap
[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
# session
Session.vim
# temporary
.netrwhist
*~
# auto-generated tag files
tags


### macOS ###
*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk


### Linux ###

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*


### Windows ###
# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk
Contact GitHub API Training Shop Blog About
© 2016 GitHub, Inc. Terms Privacy Security Status Help
93 changes: 93 additions & 0 deletions lab-jinho/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Vanilla-REST-API
=============

structures :
- data
- restaurant
- random item
- lib
- parse-json.js
- parse-url.js
- response.js
- router.js
- storage.js
- model
- restaurant.js
- test
- restaurant-route-test.js
- root
- server.js
- gulpfile.js
- .gitignore
- .eslintrc
- README.md

## Getting Started
- In terminal enter : node server.js
- also you can run gulp
- for tests in terminal enter:
- gulp OR mocha


### Prerequisities

- dependencies:

```
npm install -S node-uuid
npm install -S superagent

```

- devDependencies:

```
npm install -D gulp-eslint
npm install -D gulp-mocha
npm install -D mocha
npm install -D gulp
npm install -D chai

```

## Running

- In your root server, type in the command **"node server.js"** in your terminal.
- OR in terminal type: gulp


- GET request:
```http localhost:3000/api/restaurant?id=selectedId ```

- POST request:
```http POST localhost:3000/api/restaurant restaurantname="name of restaurant" address="location address" ```

- DELETE request:
```http DELETE localhost:3000/api/person?id=selectedId ```

## Testing:
- we have 5 tests for GET and POST requests :
- test to ensure that API returns a status code of 404 for routes that have not been registered
- tests to ensure that **/api/restaurant** endpoint responds as described for each condition below:
- GET - test 404, responds with 'not found' for valid request made with an id that was not found
- GET - test 400, responds with 'bad request' if no id was provided in the request
- GET - test 200, response body like {<data>} for a request made with a valid id
- POST - test 400, responds with 'bad request' for if no body provided or invalid body
- POST - test 200, response body like {<data>} for a post request with a valid body

## Built With:

* Nodejs
* JavaScript

## Versioning

Not Applicable

## Authors

* **BlueToad** - [Github](https://github.com/jmpaik)

## License

None.
23 changes: 23 additions & 0 deletions lab-jinho/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

const gulp = require('gulp');
const eslint = require('gulp-eslint');
const mocha = require('gulp-mocha');

gulp.task('test', function(){
gulp.src('./test/*-test.js', {read: false})
.pipe(mocha({reporter: 'spec'}));
});

gulp.task('lint', function(){
return gulp.src(['**/*.js','!node_modules/**'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});

gulp.task('dev', function(){
gulp.watch(['**/*.js','!node_modules/**'], ['lint', 'test']);
});

gulp.task('default', ['dev']);
28 changes: 28 additions & 0 deletions lab-jinho/lib/error-middleware.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

const createError = require('http-errors');
const debug = require('debug')('restaurant:error-middleware');

module.exports = function(err, req, res, next) {
debug('error middleware');

console.error('msg:', err.message);
console.error('name:', err.name);

if (err.status) {
res.status(err.status).send(err.name);
next();
return;
}

if (err.name === 'ValidationError') {
err = createError(400, err.message);
res.status(err.status).send(err.name);
next();
return;
}

err = createError(500, err.message);
res.status(err.status).send(err.name);
next();
};
36 changes: 36 additions & 0 deletions lab-jinho/model/list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

const mongoose = require('mongoose');
const createError = require('http-errors');
const debug = require('debug')('restaurant:list');
const Schema = mongoose.Schema;

const Restaurant = require('./restaurant.js');

const listSchema = Schema({
name: { type: String, required: true },
timestamp: { type: Date, required: true },
restaurants: [{ type: Schema.Types.ObjectId, ref: 'restaurant' }]
});

const List = module.exports = mongoose.model('list', listSchema);

List.findByIdAndAddRestaurant = function(id, restaurant) {
debug('findByIdAndAddRestaurant');

return List.findById(id)
.catch( err => Promise.reject(createError(404, err.message)))
.then( list => {
restaurant.listID = list._id;
this.tempList = list;
return new Restaurant(restaurant).save();
})
.then( restaurant => {
this.tempList.restaurants.push(restaurant._id);
this.tempRestaurant = restaurant;
return this.tempList.save();
})
.then ( () => {
return this.tempRestaurant;
});
};
12 changes: 12 additions & 0 deletions lab-jinho/model/restaurant.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const restaurantSchema = Schema({
restaurantname: { type: String, required: true },
address: { type: String, required: true },
listID: { type: Schema.Types.ObjectId, required: true }
});

module.exports = mongoose.model('restaurant', restaurantSchema);
33 changes: 33 additions & 0 deletions lab-jinho/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "lab-jinho",
"version": "1.0.0",
"description": "",
"main": "gulpfile.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "DEBUG='restaurant*' mocha",
"start": "DEBUG='restaurant*' node server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"Express": "^3.0.1",
"bluebird": "^3.4.6",
"body-parser": "^1.15.2",
"cors": "^2.8.1",
"debug": "^2.4.5",
"express": "^4.14.0",
"http-errors": "^1.5.1",
"mongoose": "^4.7.4",
"morgan": "^1.7.0",
"node-uuid": "^1.4.7"
},
"devDependencies": {
"chai": "^3.5.0",
"mocha": "^3.2.0",
"superagent": "^3.3.0"
}
}
Loading