Resources

pull/1/head
sundowndev 2018-11-12 18:18:58 +01:00
parent 8fcbae1a3d
commit 0220fc745a
15 changed files with 130 additions and 17 deletions

34
app/routes/auth/index.js Normal file
View File

@ -0,0 +1,34 @@
const auth = require('express').Router();
const register = require('./register');
const login = require('./login');
/**
* @api {post} /auth/register Register
* @apiName Register
* @apiGroup Auth
*
* @apiParam {String} firstname Firstname of the user.
* @apiParam {String} lastname Lastname of the user.
* @apiParam {String} username username of the user.
* @apiParam {String} password password of the user.
*
* @apiSuccess {Array} Array Array of Note objects.
*/
auth.post('/register', register);
/**
* @api {post} /auth/login Request JWT token
* @apiName Login
* @apiGroup Auth
*
* @apiParam {String} username username of the user.
* @apiParam {String} password password of the user.
*
* @apiSuccess {string} jwt JWT token.
*/
auth.post('/login', login);
//note.post('/rester-password', reset)
module.exports = auth;

5
app/routes/auth/login.js Normal file
View File

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

View File

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

View File

@ -2,6 +2,7 @@ const routes = require('express').Router();
const bodyParser = require('body-parser'); const bodyParser = require('body-parser');
// Require routes // Require routes
const auth = require('./auth');
const user = require('./user'); const user = require('./user');
const note = require('./note'); const note = require('./note');
@ -12,7 +13,7 @@ routes.use(bodyParser.json());
routes.use((req, res, next) => { routes.use((req, res, next) => {
// do logging // do logging
console.log('Something is happening.'); console.log(`Resource requested: ${req.method} ${req.originalUrl}`);
next(); // make sure we go to the next routes and don't stop here next(); // make sure we go to the next routes and don't stop here
}); });
@ -20,6 +21,7 @@ routes.get('/', (req, res) => {
res.status(200).json({ message: 'Hello world!' }); res.status(200).json({ message: 'Hello world!' });
}); });
routes.use('/auth', auth);
routes.use('/user', user); routes.use('/user', user);
routes.use('/note', note); routes.use('/note', note);

View File

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

View File

View File

View File

@ -1,9 +1,10 @@
const note = require('express').Router(); const note = require('express').Router();
const all = require('./all'); const all = require('./all');
const single = require('./single'); const single = require('./single');
//const create = require('./create'); const create = require('./create');
//const update = require('./update'); const update = require('./update');
//const delete = require('./delete'); const remove = require('./delete');
/** /**
* @api {get} /note Request all notes * @api {get} /note Request all notes
@ -24,10 +25,26 @@ note.get('/', all);
* @apiSuccess {string} title Title of the note. * @apiSuccess {string} title Title of the note.
* @apiSuccess {string} text Text of the note. * @apiSuccess {string} text Text of the note.
*/ */
note.get('/:noteId', single); note.get('/:id', single);
/**
* @api {post} /note Create note
* @apiName CreateNote
* @apiGroup Note
*
* @apiSuccess {Object} Object Created note.
*/
note.post('/', all);
/**
* @api {delete} /note/:id Delete a note
* @apiName DeleteNote
* @apiGroup Note
*/
note.delete('/:id', all);
//note.post('/', create) //note.post('/', create)
//note.post('/:noteId', update) //note.put('/:noteId', update)
//note.post('/:noteId', delete) //note.delete('/:noteId', remove)
module.exports = note; module.exports = note;

View File

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

View File

View File

View File

View File

@ -1,9 +1,11 @@
const user = require('express').Router(); const user = require('express').Router();
const all = require('./all'); const all = require('./all');
const profile = require('./profile');
const single = require('./single'); const single = require('./single');
//const create = require('./create'); const create = require('./create');
//const update = require('./update'); const update = require('./update');
//const delete = require('./delete'); const remove = require('./delete');
/** /**
* @api {get} /user Request all Users information * @api {get} /user Request all Users information
@ -12,7 +14,7 @@ const single = require('./single');
* *
* @apiParam {Number} id Users unique ID. * @apiParam {Number} id Users unique ID.
* *
* @apiSuccess {Array} Array Array of User objects. * @apiSuccess {Array} Array User objects.
*/ */
user.get('/', all); user.get('/', all);
@ -29,8 +31,51 @@ user.get('/', all);
*/ */
user.get('/:userId', single); user.get('/:userId', single);
/**
* @api {get} /user/me Request current account information
* @apiName GetUser
* @apiGroup User
*
* @apiSuccess {String} firstname Firstname of the User.
* @apiSuccess {String} lastname Lastname of the User.
* @apiSuccess {String} username Username of the User.
*/
user.get('/me', profile);
/**
* @api {put} /user/me Update current account information
* @apiName UpdateUser
* @apiGroup User
*
* @apiParam {String} firstname Firstname of the User.
* @apiParam {String} lastname Lastname of the User.
* @apiParam {String} username Username of the User.
*/
user.put('/me', profile);
/**
* @api {delete} /user/me Delete current account
* @apiName DeleteUser
* @apiGroup User
*
* @apiParam {String} firstname Firstname of the User.
* @apiParam {String} lastname Lastname of the User.
* @apiParam {String} username Username of the User.
*/
user.delete('/me', profile);
/**
* @api {get} /user/me/notes Get notes created by this account
* @apiName GetNotes
* @apiGroup User,Note
*
* @apiSuccess {string} title Title of the note.
* @apiSuccess {string} text Text of the note.
*/
user.get('/me/notes', profile);
//user.post('/', create) //user.post('/', create)
//user.post('/:userId', update) //user.put('/:userId', update)
//user.post('/:userId', delete) //user.delete('/:userId', remove)
module.exports = user; module.exports = user;

View File

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

View File