Code base

master
sundowndev 2018-11-12 16:26:10 +01:00
parent 43517a8df8
commit 28b08095a3
13 changed files with 1208 additions and 0 deletions

9
app/models/note.js Normal file
View File

@ -0,0 +1,9 @@
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var NoteSchema = new Schema({
title: String,
text: String
});
module.exports = mongoose.model('Note', NoteSchema);

11
app/models/user.js Normal file
View File

@ -0,0 +1,11 @@
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var UserSchema = new Schema({
firstname: String,
lastname: String,
username: String,
password: String
});
module.exports = mongoose.model('User', UserSchema);

26
app/routes/index.js Normal file
View File

@ -0,0 +1,26 @@
const routes = require('express').Router();
const bodyParser = require('body-parser');
// Require routes
const user = require('./user');
const note = require('./note');
// configure app to use bodyParser()
// this will let us get the data from a POST
routes.use(bodyParser.urlencoded({ extended: true }));
routes.use(bodyParser.json());
routes.use((req, res, next) => {
// do logging
console.log('Something is happening.');
next(); // make sure we go to the next routes and don't stop here
});
routes.get('/', (req, res) => {
res.status(200).json({ message: 'Hello world!' });
});
routes.use('/user', user);
routes.use('/note', note);
module.exports = routes;

5
app/routes/note/all.js Normal file
View File

@ -0,0 +1,5 @@
module.exports = (req, res) => {
const users = [];
res.status(200).json({ users });
};

33
app/routes/note/index.js Normal file
View File

@ -0,0 +1,33 @@
const note = require('express').Router();
const all = require('./all');
const single = require('./single');
//const create = require('./create');
//const update = require('./update');
//const delete = require('./delete');
/**
* @api {get} /note Request all notes
* @apiName GetNotes
* @apiGroup Note
*
* @apiSuccess {Array} Array Array of Note objects.
*/
note.get('/', all);
/**
* @api {get} /note/:id Request Note information
* @apiName GetNotes
* @apiGroup Note
*
* @apiParam {Number} id Notes unique ID.
*
* @apiSuccess {string} title Title of the note.
* @apiSuccess {string} text Text of the note.
*/
note.get('/:noteId', single);
//note.post('/', create)
//note.post('/:noteId', update)
//note.post('/:noteId', delete)
module.exports = note;

View File

@ -0,0 +1,5 @@
module.exports = (req, res) => {
const user = req.model;
res.status(200).json({ user });
};

5
app/routes/user/all.js Normal file
View File

@ -0,0 +1,5 @@
module.exports = (req, res) => {
const users = [];
res.status(200).json({ users });
};

36
app/routes/user/index.js Normal file
View File

@ -0,0 +1,36 @@
const user = require('express').Router();
const all = require('./all');
const single = require('./single');
//const create = require('./create');
//const update = require('./update');
//const delete = require('./delete');
/**
* @api {get} /user Request all Users information
* @apiName GetUsers
* @apiGroup User
*
* @apiParam {Number} id Users unique ID.
*
* @apiSuccess {Array} Array Array of User objects.
*/
user.get('/', all);
/**
* @api {get} /user/:id Request User information
* @apiName GetUser
* @apiGroup User
*
* @apiParam {Number} id Users unique ID.
*
* @apiSuccess {String} firstname Firstname of the User.
* @apiSuccess {String} lastname Lastname of the User.
* @apiSuccess {String} username Username of the User.
*/
user.get('/:userId', single);
//user.post('/', create)
//user.post('/:userId', update)
//user.post('/:userId', delete)
module.exports = user;

View File

@ -0,0 +1,5 @@
module.exports = (req, res) => {
const user = req.model;
res.status(200).json({ user });
};

5
app/server.js Normal file
View File

@ -0,0 +1,5 @@
var mongoose = require('mongoose');
mongoose.connect('mongodb://node:node@novus.modulusmongo.net:27017/Iganiq8o');
var User = require('./app/models/user');

12
index.js Normal file
View File

@ -0,0 +1,12 @@
const express = require('express');
const routes = require('./app/routes');
const app = express();
const port = process.env.PORT || 8080; // set our port
app.use('/', routes);
// Start the server
app.listen(port);
console.log('Server started on port ' + port);

1024
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

32
package.json Normal file
View File

@ -0,0 +1,32 @@
{
"name": "api-js-mooc",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"body-parser": "^1.18.3",
"express": "^4.16.4",
"mongoose": "^5.3.11"
},
"devDependencies": {
"apidoc": "^0.17.7"
},
"apidoc": {
"title": "Mooc API"
},
"scripts": {
"doc":"apidoc -i ./app/routes",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/sundowndev/api-js-mooc.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/sundowndev/api-js-mooc/issues"
},
"homepage": "https://github.com/sundowndev/api-js-mooc#readme"
}