Skip to content

Commit

Permalink
image tracking works
Browse files Browse the repository at this point in the history
  • Loading branch information
theresa-cy-ngo committed Mar 30, 2016
1 parent 9e31b13 commit 11d7605
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 4 deletions.
10 changes: 9 additions & 1 deletion app/display/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,17 @@ angular.module("myApp.display", ["ngRoute", "LocalStorageModule", "myApp.display
}

$scope.showImageDetails = function (selectedImage){
//UPDATE IMAGE TRACKING HERE
$scope.selected = selectedImage;
currentImage = selectedImage;
displayHandler.checkTracking(usernameFromStorage, currentImage.id, function(result){
if (!result.data.results[0]) {
displayHandler.updateTracking(usernameFromStorage, currentImage.id, function(result){
console.log("Update complete");
});
} else {
console.log("Data is already in the system");
};
});
};


Expand Down
28 changes: 28 additions & 0 deletions app/display/displayHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,32 @@ angular.module("myApp.display.displayHandler", [])
});
};

this.checkTracking = function (username, photo_id, callback) {
$http({
url: SERVICE_BASE_URL + "checkTracking",
method: "POST",
params: {userName: username, photo_id: photo_id}
})
.then(function(result) {
return callback(result);
},
function(result) {
return callback(result);
});
};

this.updateTracking = function (username, photo_id, callback) {
$http({
url: SERVICE_BASE_URL + "updateTracking",
method: "POST",
params: {userName: username, photo_id: photo_id}
})
.then(function(result) {
return callback(result);
},
function(result) {
return callback(result);
});
};

});
14 changes: 11 additions & 3 deletions app/search/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,17 @@ angular.module("myApp.search", ["ngRoute", "LocalStorageModule", "myApp.search.s
};

$scope.showImageDetails = function (selectedImage){
//UPDATE IMAGE TRACKING HERE
$scope.selected = selectedImage;
currentImage = selectedImage;
$scope.selected = selectedImage;
currentImage = selectedImage;
searchHandler.checkTracking(usernameFromStorage, currentImage.id, function(result){
if (!result.data.results[0]) {
searchHandler.updateTracking(usernameFromStorage, currentImage.id, function(result){
console.log("Update complete");
});
} else {
console.log("Data is already in the system");
};
});
};

displayResults = function (photoResults, rowResults) {
Expand Down
29 changes: 29 additions & 0 deletions app/search/searchHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,33 @@ angular.module("myApp.search.searchHandler", [])
return callback(result);
});
};

this.checkTracking = function (username, photo_id, callback) {
$http({
url: SERVICE_BASE_URL + "checkTracking",
method: "POST",
params: {userName: username, photo_id: photo_id}
})
.then(function(result) {
return callback(result);
},
function(result) {
return callback(result);
});
};

this.updateTracking = function (username, photo_id, callback) {
$http({
url: SERVICE_BASE_URL + "updateTracking",
method: "POST",
params: {userName: username, photo_id: photo_id}
})
.then(function(result) {
return callback(result);
},
function(result) {
return callback(result);
});
};

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

// Checks if the username already has tracking for the image in the database
app.post("/checkTracking", function(req, res){
var DBQueryString =
"SELECT * " +
"FROM image_tracking " +
"WHERE photo_id = :photo_id AND user_name = :userName" ,
DBQueryParam = {userName: req.query.userName, photo_id: req.query.photo_id};

console.log(DBQueryString);
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 {
res.send({success: true, results: result.rows});
}
doRelease(connection);
}
);
});
});

// Inserts a new image tracking into the database
app.post("/updateTracking", function(req, res){
var DBQueryString =
"INSERT INTO image_tracking " +
"(PHOTO_ID, USER_NAME) " +
"VALUES (:photo_id, :userName)" ,
DBQueryParam = {userName: req.query.userName, photo_id: req.query.photo_id};

console.log(DBQueryString);
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 {
res.send({success: true, results: result.rows});
}
doRelease(connection);
}
);
});
});

//Disconnect from Oracle
function doRelease(connection)
{
Expand Down

0 comments on commit 11d7605

Please sign in to comment.