Skip to content
This repository was archived by the owner on Jan 22, 2020. It is now read-only.

Change the Sample Tuna Catch Application to use POST requests #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions LFS171x/fabric-material/tuna-app/client/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ app.controller('appController', function($scope, appFactory){
$("#success_create").hide();
$("#error_holder").hide();
$("#error_query").hide();

$scope.queryAllTuna = function(){

appFactory.queryAllTuna(function(data){
Expand Down Expand Up @@ -70,7 +70,7 @@ app.controller('appController', function($scope, appFactory){

// Angular Factory
app.factory('appFactory', function($http){

var factory = {};

factory.queryAllTuna = function(callback){
Expand All @@ -90,18 +90,27 @@ app.factory('appFactory', function($http){

data.location = data.longitude + ", "+ data.latitude;

var tuna = data.id + "-" + data.location + "-" + data.timestamp + "-" + data.holder + "-" + data.vessel;
var tuna = {
id: data.id,
location: data.location,
timestamp: data.timestamp,
holder: data.holder,
vessel: data.vessel
};

$http.get('/add_tuna/'+tuna).success(function(output){
$http.post('/add_tuna', tuna).success(function(output){
callback(output)
});
}

factory.changeHolder = function(data, callback){

var holder = data.id + "-" + data.name;
var holder = {
id: data.id,
name: data.name
};

$http.get('/change_holder/'+holder).success(function(output){
$http.post('/change_holder', holder).success(function(output){
callback(output)
});
}
Expand Down
26 changes: 13 additions & 13 deletions LFS171x/fabric-material/tuna-app/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ return{
add_tuna: function(req, res){
console.log("submit recording of a tuna catch: ");

var array = req.params.tuna.split("-");
console.log(array);
var tunaReq = req.body;
console.log(tunaReq);

var key = array[0]
var timestamp = array[2]
var location = array[1]
var vessel = array[4]
var holder = array[3]
var key = tunaReq.id
var timestamp = tunaReq.timestamp
var location = tunaReq.location
var vessel = tunaReq.vessel
var holder = tunaReq.holder


var fabric_client = new Fabric_Client();
Expand Down Expand Up @@ -137,7 +137,7 @@ return{
tx_id = fabric_client.newTransactionID();
console.log("Assigning transaction_id: ", tx_id._transaction_id);

// recordTuna - requires 5 args, ID, vessel, location, timestamp,holder - ex: args: ['10', 'Hound', '-12.021, 28.012', '1504054225', 'Hansel'],
// recordTuna - requires 5 args, ID, vessel, location, timestamp,holder - ex: args: ['10', 'Hound', '-12.021, 28.012', '1504054225', 'Hansel'],
// send proposal to endorser
const request = {
//targets : --- letting this default to the peers assigned to the channel
Expand Down Expand Up @@ -298,7 +298,7 @@ return{
if (query_responses[0] instanceof Error) {
console.error("error from query = ", query_responses[0]);
res.send("Could not locate tuna")

} else {
console.log("Response is ", query_responses[0].toString());
res.send(query_responses[0].toString())
Expand All @@ -315,9 +315,9 @@ return{
change_holder: function(req, res){
console.log("changing holder of tuna catch: ");

var array = req.params.holder.split("-");
var key = array[0]
var holder = array[1];
var holderReq = req.body;
var key = holderReq.id;
var holder = holderReq.name;

var fabric_client = new Fabric_Client();

Expand Down Expand Up @@ -471,4 +471,4 @@ return{
}

}
})();
})();
4 changes: 2 additions & 2 deletions LFS171x/fabric-material/tuna-app/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ module.exports = function(app){
app.get('/get_tuna/:id', function(req, res){
tuna.get_tuna(req, res);
});
app.get('/add_tuna/:tuna', function(req, res){
app.post('/add_tuna', function(req, res){
tuna.add_tuna(req, res);
});
app.get('/get_all_tuna', function(req, res){
tuna.get_all_tuna(req, res);
});
app.get('/change_holder/:holder', function(req, res){
app.post('/change_holder', function(req, res){
tuna.change_holder(req, res);
});
}
3 changes: 0 additions & 3 deletions LFS171x/fabric-material/tuna-app/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ var os = require('os');
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

// instantiate the app
var app = express();

// this line requires and runs the code from our routes.js file and passes it app
require('./routes.js')(app);

Expand Down