forked from FatalBadgers/tikr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(FatalBadgers#1) Display repo information in user search results.
- Loading branch information
1 parent
19de986
commit 85db8ed
Showing
16 changed files
with
231 additions
and
77 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 @@ | ||
'use strict'; | ||
|
||
var express = require('express'); | ||
var controller = require('./skills.controller'); | ||
|
||
var router = express.Router(); | ||
|
||
router.get('/', controller.index); | ||
router.get('/:id', controller.show); | ||
router.post('/', controller.create); | ||
router.put('/:id', controller.update); | ||
router.patch('/:id', controller.update); | ||
router.delete('/:id', controller.destroy); | ||
|
||
module.exports = router; | ||
|
This file contains 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 @@ | ||
'use strict'; | ||
|
||
var mongoose = require('mongoose'), | ||
Schema = mongoose.Schema; | ||
|
||
var SkillSchema = new Schema({ | ||
name: String, | ||
info: String, | ||
active: Boolean | ||
}); | ||
|
||
module.exports = mongoose.model('Skill', SkillSchema); | ||
|
This file contains 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,68 @@ | ||
/** | ||
* Using Rails-like standard naming convention for endpoints. | ||
* GET /skills -> index | ||
* POST /skills -> create | ||
* GET /skills/:id -> show | ||
* PUT /skills/:id -> update | ||
* DELETE /skills/:id -> destroy | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var _ = require('lodash'); | ||
var Skill = require('./skill.model'); | ||
|
||
// Get list of skills | ||
exports.index = function(req, res) { | ||
Skill.find(function (err, skills) { | ||
if(err) { return handleError(res, err); } | ||
return res.json(200, skills); | ||
}); | ||
}; | ||
|
||
// Get a single skill | ||
exports.show = function(req, res) { | ||
Skill.findById(req.params.id, function (err, skill) { | ||
if(err) { return handleError(res, err); } | ||
if(!skill) { return res.send(404); } | ||
return res.json(skill); | ||
}); | ||
}; | ||
|
||
// Creates a new skill in the DB. | ||
exports.create = function(req, res) { | ||
Skill.create(req.body, function(err, skill) { | ||
if(err) { return handleError(res, err); } | ||
return res.json(201, skill); | ||
}); | ||
}; | ||
|
||
// Updates an existing skill in the DB. | ||
exports.update = function(req, res) { | ||
if(req.body._id) { delete req.body._id; } | ||
Skill.findById(req.params.id, function (err, skill) { | ||
if (err) { return handleError(res, err); } | ||
if(!skill) { return res.send(404); } | ||
var updated = _.merge(skill, req.body); | ||
updated.save(function (err) { | ||
if (err) { return handleError(res, err); } | ||
return res.json(200, skill); | ||
}); | ||
}); | ||
}; | ||
|
||
// Deletes a skill from the DB. | ||
exports.destroy = function(req, res) { | ||
Skill.findById(req.params.id, function (err, skill) { | ||
if(err) { return handleError(res, err); } | ||
if(!skill) { return res.send(404); } | ||
skill.remove(function(err) { | ||
if(err) { return handleError(res, err); } | ||
return res.send(204); | ||
}); | ||
}); | ||
}; | ||
|
||
function handleError(res, err) { | ||
return res.send(500, err); | ||
} |
This file contains 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,20 @@ | ||
'use strict'; | ||
|
||
var should = require('should'); | ||
var app = require('../../app'); | ||
var request = require('supertest'); | ||
|
||
describe('GET /api/skills', function() { | ||
|
||
it('should respond with JSON array', function(done) { | ||
request(app) | ||
.get('/api/skills') | ||
.expect(200) | ||
.expect('Content-Type', /json/) | ||
.end(function(err, res) { | ||
if (err) return done(err); | ||
res.body.should.be.instanceof(Array); | ||
done(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.