diff --git a/SPA/index.html b/SPA/index.html
index 81e6f29..a1abf81 100644
--- a/SPA/index.html
+++ b/SPA/index.html
@@ -1,49 +1,48 @@
-
-
-
-
Home
-
{{ message.name }}
{{ message.address }},{{ message.city }}
{{ message.phone }}
+
+
+
{{message.name}}
+
About
+
+
+
+
+
Best Italian Sellers
+
+
+ {{value.name}}
+ Ingredients: {{value.ingredients}}
+ Price: {{value.price}}
+
+
+
+
+
Pizza
+
+
+ {{value.name}}
+
Ingredients: {{value.ingredients}}
+ Price: {{value.price}}
+
+
+
+
+
Pasta
+
+
+ {{value.name}}
+ Ingredients: {{value.ingredients}}
+ Price: {{value.price}}
+
+
+
\ No newline at end of file
diff --git a/SPA/script.js b/SPA/script.js
index ae1f72e..0b5ed4c 100644
--- a/SPA/script.js
+++ b/SPA/script.js
@@ -18,10 +18,10 @@
})
// route for the contact page
- .when('/contact', {
+/* .when('/contact', {
templateUrl : 'SPA/pages/contact.html',
controller : 'contactController'
- });
+ });*/
});
// create the controller and inject Angular's $scope
@@ -39,7 +39,7 @@
});
scotchApp.controller('aboutController', function($scope,$http,$routeParams) {
- $http({method: 'GET', url: 'http://localhost:3412/rest/'+$routeParams.restId}).
+ $http({method: 'GET', url: 'http://localhost:3412/rest/'+ $routeParams.restId}).
success(function(data, status, headers, config) {
$scope.message = data;
@@ -50,7 +50,7 @@
});
});
- scotchApp.controller('contactController', function($scope,$http) {
+/* scotchApp.controller('contactController', function($scope,$http) {
$http({method: 'GET', url: 'http://localhost:3412/rest/1'}).
success(function(data, status, headers, config) {
@@ -60,4 +60,4 @@
error(function(data, status, headers, config) {
});
- });
\ No newline at end of file
+ });*/
\ No newline at end of file
diff --git a/app.js b/app.js
index ec5f38e..ee342ac 100644
--- a/app.js
+++ b/app.js
@@ -1,71 +1,48 @@
var express = require('express');
var app = express();
-
-// Declare variables
-var fs = require('fs'),
- obj
-
-// Read the file and send to the callback
-fs.readFile(__dirname + '/restaurant.json', handleFile)
-
-// Write the callback function
-function handleFile(err, data) {
- if (err) throw err
- obj = JSON.parse(data)
- // You can now play with your datas
-}
+// Introducing Redis
+var _redis = require("redis"),
+redis = _redis.createClient();
+
+var restaurants = '[{"id":0,"name":"Pizza Pronto Restaurant","address":"71A Aripita Avenue Woodbrook","city":"Port of spain","phone":"1","best":[{"name":"Pizza Margherita","ingredients":"tomato sauce, mozzarella","price":"9.00 USD"},{"name":"Penne Alla Siciliana","ingredients":"pasta with aubergines, mozzarella and tomato sauce","price":"8.00 USD"}],"pizza":[{"name":"Pizza Prosciuto","ingredients":"one one one","price":"10.00 USD"},{"name":"Pizza Margherita","ingredients":"sos, mozzarella, rosii, busuioc","price":"less"}],"pasta":[{"name":"Spaghetti All Arabiatello","ingredients":"pasta faina","price":"8.00 USD"}]}]';
+
+redis.select(1, function(err,res){
+ // you'll want to check that the select was successful here
+ if(err) return err;
+ else {
+ redis.setnx('nodejs', restaurants, function(error, result) {
+ if (error) res.send('Error: ' + error);
+ else if (result === 0) console.log('the key already exist');
+ else console.log('saved');
+ });}
+});
app.use("/SPA", express.static(__dirname + '/SPA'));
app.use(express.bodyParser());
app.get('/', function(req,res) {
res.sendfile('SPA/index.html');
- //res.json(obj);
});
app.get('/rest', function(req, res) {
- res.json(obj);
-});
-
-app.get('/rest/random', function(req, res) {
- var id = Math.floor(Math.random() * obj.length);
- var q = obj[id];
- res.json(q);
+ redis.get('nodejs', function(error, result) {
+ if (error) res.send('Error: '+ error);
+ else {
+ json = JSON.parse(result);
+ res.json(json);
+ }
+ });
});
-app.get('/rest/:id', function(req, res) {
- if(obj.length <= req.params.id || req.params.id < 0) {
- res.statusCode = 404;
- return res.send('Error 404: No quote found');
- }
-
- var q = obj[req.params.id];
- res.json(q);
-});
-/*
-app.post('/rest', function(req, res) {
- if(!req.body.hasOwnProperty('author') || !req.body.hasOwnProperty('text')) {
- res.statusCode = 400;
- return res.send('Error 400: Post syntax incorrect.');
- }
-
- var newQuote = {
- author : req.body.author,
- text : req.body.text
- };
-
- quotes.push(newQuote);
- res.json(true);
+app.get('/rest/:no', function(req, res) {
+ redis.get('nodejs', function(error, result) {
+ if (error) res.send('Error: '+ error);
+ else {
+ json = JSON.parse(result);
+ var q = json[req.params.no];
+ res.json(q);
+ }
+ });
});
-app.delete('/quote/:id', function(req, res) {
- if(quotes.length <= req.params.id) {
- res.statusCode = 404;
- return res.send('Error 404: No quote found');
- }
-
- quotes.splice(req.params.id, 1);
- res.json(true);
-});*/
-
app.listen(process.env.PORT || 3412);
\ No newline at end of file
diff --git a/package.json b/package.json
index e64af87..1d06f6e 100644
--- a/package.json
+++ b/package.json
@@ -4,7 +4,8 @@
"private" : true,
"version": "0.0.1",
"dependencies": {
- "express": "3.x"
+ "express": "3.x",
+ "redis": "0.8.x"
},
"main" : "app"
}
\ No newline at end of file
diff --git a/restaurant.json b/restaurant.json
index b27cf59..a664b3a 100644
--- a/restaurant.json
+++ b/restaurant.json
@@ -1,24 +1,40 @@
[
- {
- "id": 0,
- "name": "First Pizza Pronto Restaurant",
- "address": "71A Aripita Avenue Woodbrook",
- "city": "Port of spain",
- "phone": "+40 743 105 932",
- "best": {
- "name":"pizza 1",
- "ingredients":"one, two, three",
- "price":"9.00 USD"
- },
- "pizza": {
- "name":"Pizza Prosciuto",
- "ingredients":"one one one",
- "price":"10.00 USD"
- },
- "pasta": {
- "name": "Spaghetti All Arabiatello",
- "ingredients": "pasta faina",
- "price": "8.00 USD"
- }
- }
+ {
+ "id": 0,
+ "name": "Pizza Pronto Restaurant",
+ "address": "71A Aripita Avenue Woodbrook",
+ "city": "Port of spain",
+ "phone": "+xx xxx xxx xxx",
+ "best": [
+ {
+ "name": "Pizza Margherita",
+ "ingredients": "tomato sauce, mozzarella",
+ "price": "9.00 USD"
+ },
+ {
+ "name": "Penne Alla Siciliana",
+ "ingredients": "pasta with aubergines, mozzarella and tomato sauce",
+ "price": "8.00 USD"
+ }
+ ],
+ "pizza": [
+ {
+ "name": "Pizza Prosciuto",
+ "ingredients": "one one one",
+ "price": "10.00 USD"
+ },
+ {
+ "name":"Pizza Margherita",
+ "ingredients":"sos, mozzarella, rosii, busuioc",
+ "price": "less"
+ }
+ ],
+ "pasta": [
+ {
+ "name": "Spaghetti All Arabiatello",
+ "ingredients": "pasta faina",
+ "price": "8.00 USD"
+ }
+ ]
+ }
]
\ No newline at end of file