Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Graghav committed Sep 2, 2015
0 parents commit 973ce40
Show file tree
Hide file tree
Showing 375 changed files with 55,294 additions and 0 deletions.
19 changes: 19 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var express = require('express');
var server = express();
var path = require('path');

var router = require('./url');

var bodyParser = require('body-parser');

server.use(bodyParser.urlencoded({ extended: true }));
server.use(bodyParser.json());

server.use(express.static(path.join(__dirname, 'public')));

server.use('/v1',router(express));

server.listen(3000, function(){
console.log('Server started and listening at Port 3000');
});

Binary file added app.zip
Binary file not shown.
38 changes: 38 additions & 0 deletions controller/status.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
var _ = require('underscore');
var uuid = require('node-uuid');

var statuses = [];

exports.createStatus = function(req,res) {
var time = req.body.time || req.query.time;
var status = req.body.status || req.query.status;
var username = req.body.username || req.query.username;
var id = uuid.v1();

statuses.push({
id: id,
time: time,
content: status,
username: username
});

res.status(200);

res.json({
status: "created successfully",
data : statuses
});
}

exports.getStatus = function(req,res) {
if(statuses.length) {
res.status(200);
res.json(statuses)
}
else {
res.status(404);
res.json({
error: "No Status posted"
})
}
}
69 changes: 69 additions & 0 deletions controller/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
var users = [];

var _ = require('underscore');

exports.createAccount = function(req,res) {

var user = {};

user.username = req.query.username || req.body.username;

user.fullName = req.query.name || req.body.name;

user.age = req.query.age || req.body.age;

users.push(user);

res.status(200);

res.json({
status: "created successfully",
user : user
});
}

exports.getAccountInfo = function(req,res) {

var username = req.query.username || req.body.username;

var user = _.where(users, { username: username });

if(username == "all") {
res.status(200);
res.json(users);
}
else if(user.length) {
res.status(200);
res.json(user);
}
else {
res.status(404);
res.json({ error: "User not found" });
}
}

exports.deleteAccount = function(req,res) {
var username = req.query.username || req.body.username;

if(username) {
var isFound = _.findWhere(users, { username : username }) || false;

if(isFound) {
users = _.reject(users, function(u){
return u.username == username;
});
res.status(200);
res.json({
status: "Deleted successfully"
})
}
else {
res.status(404);
res.json({ error: "User not found "});
}
}
else {
res.status(400);
res.json({ error: "Missing Parameter: username"})
}
}
1 change: 1 addition & 0 deletions node_modules/.bin/uuid

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions node_modules/.bin/uuid.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

217 changes: 217 additions & 0 deletions node_modules/body-parser/HISTORY.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions node_modules/body-parser/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 973ce40

Please sign in to comment.