"use strict";

var express = require("express");
var bodyParser = require("body-parser");
var _ = require("lodash");
var Promise = require("bluebird");
var log4js = require("log4js");
var sockjs = require("sockjs")
var log = log4js.getLogger("backend");




function createGroup( req, res ) {
    res.status(201).send();
};

function getUnitsForGroup( req, res ) {
    var groupId = req.params.groupId;
    log.info("Getting units for group %s...", groupId);
    res.status(200).send();
};

function getMarkersForGroup( req, res ) {
    var groupId = req.params.groupId;
    log.info("Getting units for group %s...", groupId);
    res.status(200).send();
};

function addUnitToGroup( req, res ) {
    var groupId = req.params.groupId;
    log.info("Getting units for group %s...", groupId);
    res.status(201).send();
};

function addMarkerToGroup( req, res ) {
    var groupId = req.params.groupId;
    log.info("Getting units for group %s...", groupId);
    res.status(201).send();
};

function updateUnit( res, req ) {
    var groupId = req.params.groupId;
    var unitId = req.params.unitId;
    log.info("Updating unit %s for group %s...", unitId, groupId);
    res.status(201).send();
};

function startWeb() {
    var port = 3000;
    log.info("Starting web server on port %s...", port);
    var server = express();

    server.use( bodyParser.json() );
    server.get( "/api/1.0.0/groups/:groupId/units", getUnitsForGroup );
    server.get( "/api/1.0.0/groups/:groupId/markers", getMarkersForGroup );
    server.post( "/api/1.0.0/groups", createGroup );
    server.post( "/api/1.0.0/groups/:groupId/markers", addMarkerToGroup );
    server.post( "/api/1.0.0/groups/:groupId/units", addUnitToGroup );
    server.put( "/api/1.0.0/groups/:groupId/units/:unitId", updateUnit );
    server.use( "/", express.static(__dirname + "/web"));
    
    var webserver = server.listen(port);
    log.info("done.");
};

function init() {
    startWeb();
    process.on("SIGINT", shutdown);
    process.on("quit", shutdown);
};

function shutdown() {
    log.warn("Shutting down...");
    process.exit(0);
};

init();

@@ -79,24 +79,56 @@
 y-parser%22);%0A
+var crypto = require(%22crypto%22);%0A
 var _ = requ
@@ -281,16 +281,33 @@
 nd%22);%0A%0A%0A
+var groups = %5B%5D;%0A
 %0A%0Afuncti
@@ -338,34 +338,666 @@
  ) %7B
-%0A    res.status(201).send(
+    %0A    var groupCreateRequest = req.body;%0A%0A    log.info(%22Creating group...%22);%0A    var newGroup = %7B%0A        id: crypto.randomBytes(20).toString('hex'),%0A        key: crypto.randomBytes(20).toString('hex')%0A    %7D;%0A    var newGroupJSON = JSON.stringify(newGroup,null,4);%0A    log.info(%22Created group%5Cn%25s%22, newGroupJSON);;%0A    groups.push(newGroup);%0A%0A    res.set(%22Content-type%22, %22application/json%22);%0A    res.status(201).send(newGroupJSON);%0A%7D;%0A%0Afunction getGroups( req, res ) %7B    %0A%0A    log.info(%22Getting groups...%22);%0A    var groupsJSON = JSON.stringify(%7Bgroups:groups%7D,null,4);%0A%0A    res.set(%22Content-type%22, %22application/json%22);%0A    res.status(201).send(groupsJSON
 );%0A%7D
@@ -2176,32 +2176,82 @@
 kersForGroup );%0A
+    server.get( %22/api/1.0.0/groups%22, getGroups );%0A
     server.post(

Add routes for creating and view groups.