Skip to content

Commit

Permalink
Display a user's groups
Browse files Browse the repository at this point in the history
  • Loading branch information
jwoo12 committed Mar 21, 2016
1 parent b92b3d4 commit 7db344f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
15 changes: 12 additions & 3 deletions app/groups/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ angular.module("myApp.groups", ["ngRoute", "LocalStorageModule", "myApp.groups.g
var usernameFromStorage,
storageKey = "user";

$scope.groups = [];

function getItem(key) {
return localStorageService.get(key);
};
Expand All @@ -22,7 +24,14 @@ angular.module("myApp.groups", ["ngRoute", "LocalStorageModule", "myApp.groups.g
usernameFromStorage = getItem(storageKey);
}

$scope.groups = [{"name": "test", "id": 123}];
groupsHandler.getGroups(usernameFromStorage, function(result){
var index = 0;

for(index; index < result.data.results.length; index++){
$scope.groups.push({"name": result.data.results[index][2], "id": result.data.results[index][0]});
}
// console.log(result);
});

$scope.getSelected = function(group) {
console.log(group);
Expand All @@ -37,8 +46,8 @@ angular.module("myApp.groups", ["ngRoute", "LocalStorageModule", "myApp.groups.g
if(result.data.success){
groupsHandler.addGroup(result.data.lastID + 1, $scope.regGroupName, usernameFromStorage, function(){
if(result.data.success){
console.log("added");
// $scope.groups.push({"name": });
// console.log("added");
$scope.groups.push({"name": $scope.regGroupName, "id": result.data.lastID + 1});
}else{
alert("Error adding group. Please try again.");
}
Expand Down
13 changes: 13 additions & 0 deletions app/groups/groupsHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,20 @@ angular.module("myApp.groups.groupsHandler", [])
function(result) { // optional
return callback(result);
});
};

this.getGroups = function (username, callback) {
$http({
url: SERVICE_BASE_URL + "groups",
method: "GET",
params: {userName: username}
})
.then(function(result) {
return callback(result);
},
function(result) { // optional
return callback(result);
});
};

});
27 changes: 27 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,33 @@ app.post("/groupid", function(req, res){
});

app.route("/groups")
.get(function(req, res){
var DBQueryString =
"SELECT * " +
"FROM GROUPS " +
"WHERE GROUPS.USER_NAME = :userName" ,
DBQueryParam = {userName: req.query.userName};

oracledb.getConnection(dbConfig, function (err, connection) {
if (err) {
connectionError(err, res);
return;
}
connection.execute(DBQueryString, DBQueryParam,
{autoCommit: true},
function (err, result) {
if (err) {
executeError(err, res);
} else {
// console.log(util.inspect(result, {showHidden: false, depth: null}));
res.send({success: true, results: result.rows});
}
doRelease(connection);
}
);
});

})
.post(function(req, res){
var DBQueryString =
"BEGIN\n " +
Expand Down

0 comments on commit 7db344f

Please sign in to comment.