From c795a969b99df336621bbaa7fe22b073d2224f62 Mon Sep 17 00:00:00 2001 From: jploewen Date: Tue, 12 Jul 2016 08:17:46 -0400 Subject: [PATCH 01/10] Add explicit buildpack name to manifest.yml --- manifest.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/manifest.yml b/manifest.yml index 37eea6a..4afc7c3 100644 --- a/manifest.yml +++ b/manifest.yml @@ -1,5 +1,6 @@ applications: - disk_quota: 1024M + buildpack: nodejs_buildpack host: devops-tutorial name: devops-tutorial command: node app.js From fbb5328bc44f29763f08719dfc13ed73b40d078f Mon Sep 17 00:00:00 2001 From: Joe Loewengruber Date: Sat, 23 Jul 2016 18:41:58 -0500 Subject: [PATCH 02/10] readme update --- .cfignore | 2 ++ config/README.md | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 .cfignore diff --git a/.cfignore b/.cfignore new file mode 100644 index 0000000..56aec12 --- /dev/null +++ b/.cfignore @@ -0,0 +1,2 @@ +launchConfigurations/ +.git/ diff --git a/config/README.md b/config/README.md index d0535bd..f43440b 100755 --- a/config/README.md +++ b/config/README.md @@ -1 +1 @@ -Place configuration files in this directory. +Place configuration my files in this directory. From 985926266705aca963d457080cdfbe655a7ade8c Mon Sep 17 00:00:00 2001 From: Joe Loewengruber Date: Wed, 27 Jul 2016 20:14:05 -0500 Subject: [PATCH 03/10] Hello there --- api/controllers/hello_world.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api/controllers/hello_world.js b/api/controllers/hello_world.js index cd665db..96cbfc3 100755 --- a/api/controllers/hello_world.js +++ b/api/controllers/hello_world.js @@ -38,7 +38,8 @@ module.exports = { function hello(req, res) { // variables defined in the Swagger document can be referenced using req.swagger.params.{parameter_name} var name = req.swagger.params.name.value || 'stranger'; - var helloname = util.format('Hello, %s!', name); + // 'Hello there' was 'Hello' + var helloname = util.format('Hello there, %s!', name); // this sends back a JSON response which is a single string res.json(helloname); From a97f4f3765a13e4a7982fa6e6188c105d35962f3 Mon Sep 17 00:00:00 2001 From: Joe Loewengruber Date: Wed, 27 Jul 2016 20:21:08 -0500 Subject: [PATCH 04/10] update unit tests --- test/api/controllers/hello_world.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/api/controllers/hello_world.js b/test/api/controllers/hello_world.js index c5c4652..44dbe0e 100755 --- a/test/api/controllers/hello_world.js +++ b/test/api/controllers/hello_world.js @@ -20,7 +20,7 @@ describe('controllers', function() { .end(function(err, res) { should.not.exist(err); - res.body.should.eql('Hello, stranger!'); + res.body.should.eql('Hello there, stranger!'); done(); }); @@ -39,7 +39,7 @@ describe('controllers', function() { .end(function(err, res) { should.not.exist(err); - res.body.should.eql('Hello, Scott!'); + res.body.should.eql('Hello there, Scott!'); done(); }); From 900144f7be99cb641f43ca495c8eb3604a666695 Mon Sep 17 00:00:00 2001 From: Joe Loewengruber Date: Sat, 6 Aug 2016 16:51:31 -0400 Subject: [PATCH 05/10] add garage method --- api/controllers/garages.js | 22 ++++++++++++++++ api/models/garage.js | 51 ++++++++++++++++++++++++++++++++++++++ api/swagger/swagger.yaml | 25 +++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 api/controllers/garages.js create mode 100644 api/models/garage.js diff --git a/api/controllers/garages.js b/api/controllers/garages.js new file mode 100644 index 0000000..495e0c9 --- /dev/null +++ b/api/controllers/garages.js @@ -0,0 +1,22 @@ +/*jslint node: true */ +'use strict'; + +var garageModel = require ('../models/garage'); + +module.exports = { + garages: garages, +}; + +/* return a list of garages (garage objects) */ +function garages(req, res) { + // variables defined in the Swagger document can be referenced using req.swagger.params.{parameter_name} + if (req.swagger.params && req.swagger.params.garageId) { + var garageId = req.swagger.params.garageId.value; + var garageData = garageModel.getGarageById(garageId); + + res.json(garageData); + } else { + var garages = garageModel.getAllGarages(); + res.json(garages); + } +} diff --git a/api/models/garage.js b/api/models/garage.js new file mode 100644 index 0000000..f70e191 --- /dev/null +++ b/api/models/garage.js @@ -0,0 +1,51 @@ +/*jslint node: true */ +'use strict'; + +module.exports = { + getGarageById: getGarageById, + getAllGarages: getAllGarages, +}; + +/* return a single Garage object */ +function getGarageById(garageId) { + var foundApp = {}; + for (var i = 0; i < GARAGES.length; i++) { + if (GARAGES[i].id == garageId) { + foundApp = GARAGES[i]; + } + } + + return foundApp; +} + +function getAllGarages() { + return GARAGES; +} + +// sample data +var GARAGES = [{ + id: 6212, + name: 'Main door home', + lastUpdated: '2016-07-10T14:48:00', + desiredState: 'open', + status: 'open', +}, { + id: 6213, + name: 'Main door home', + lastUpdated: '2016-07-10T17:48:00', + desiredState: 'closed', + status: 'open', +}, { + id: 6214, + name: 'Main door home', + lastUpdated: '2016-07-10T17:48:00', + desiredState: 'closed', + status: 'closed', +}, { + id: 6215, + name: 'Main door home', + lastUpdated: '2016-07-10T17:48:00', + desiredState: 'open', + status: 'closed', +}, +}]; diff --git a/api/swagger/swagger.yaml b/api/swagger/swagger.yaml index fdf275e..e94138d 100755 --- a/api/swagger/swagger.yaml +++ b/api/swagger/swagger.yaml @@ -65,6 +65,31 @@ paths: description: Error schema: $ref: "#/definitions/ErrorResponse" + /garages/{garageId}: + # Use the house address as the garageId + # binds app logic to a route (api/controllers/garages.js) + x-swagger-router-controller: garages + get: + description: Returns a single garage configurations to the caller + # used as the method name of the controller inside garages.js + operationId: garages + parameters: + - name: garageId + in: path + description: returns a garage object for the given id + # the path params are explicitly required by the spec + required: true + type: string + responses: + "200": + description: Successß + schema: + $ref: "#/definitions/Garage" + # responses may fall through to errors + default: + description: Error + schema: + $ref: "#/definitions/ErrorResponse" /hello: # binds app logic to a route (api/controllers/hello_world.js) x-swagger-router-controller: hello_world From b46c75ad7203269b3b620a06b1a42a0d26955531 Mon Sep 17 00:00:00 2001 From: Joe Loewengruber Date: Sat, 6 Aug 2016 19:26:34 -0400 Subject: [PATCH 06/10] update swagger.yaml --- api/swagger/swagger.yaml | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/api/swagger/swagger.yaml b/api/swagger/swagger.yaml index e94138d..ca8d2d0 100755 --- a/api/swagger/swagger.yaml +++ b/api/swagger/swagger.yaml @@ -65,12 +65,32 @@ paths: description: Error schema: $ref: "#/definitions/ErrorResponse" + /garages: + # binds app logic to a route (api/controllers/applications.js) + x-swagger-router-controller: garages + get: + description: Returns a list of garages to the caller + # used as the method name of the controller inside garages.js + operationId: garages + responses: + "200": + description: Success + schema: + type: array + items: + # a pointer to a definition + $ref: "#/definitions/Garage" + # responses may fall through to errors + default: + description: Error + schema: + $ref: "#/definitions/ErrorResponse" /garages/{garageId}: # Use the house address as the garageId # binds app logic to a route (api/controllers/garages.js) x-swagger-router-controller: garages get: - description: Returns a single garage configurations to the caller + description: Returns a single garage configuration to the caller # used as the method name of the controller inside garages.js operationId: garages parameters: @@ -125,6 +145,18 @@ definitions: type: string status: type: string + Garage: + properties: + garageId: + type: string + name: + type: string + description: + type: string + desiredState: + type: string + status: + type: string ErrorResponse: required: - message From 4ea23e9829ab530a78ebeab7310574f4161db91a Mon Sep 17 00:00:00 2001 From: Joe Loewengruber Date: Sat, 6 Aug 2016 19:45:08 -0400 Subject: [PATCH 07/10] update garage.js --- api/models/garage.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/api/models/garage.js b/api/models/garage.js index f70e191..973b30d 100644 --- a/api/models/garage.js +++ b/api/models/garage.js @@ -46,6 +46,5 @@ var GARAGES = [{ name: 'Main door home', lastUpdated: '2016-07-10T17:48:00', desiredState: 'open', - status: 'closed', -}, + status: 'closed', }]; From 9a0512645363314d88a53e62a92ee2dc9ff4f85b Mon Sep 17 00:00:00 2001 From: Joe Loewengruber Date: Sat, 6 Aug 2016 22:50:41 -0400 Subject: [PATCH 08/10] update views --- views/index.hbs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/views/index.hbs b/views/index.hbs index 2819396..66fb7fb 100644 --- a/views/index.hbs +++ b/views/index.hbs @@ -16,6 +16,8 @@

/hello?name=joe GET request to /hello with a query string parameter of 'name=joe'

/applications GET request to /applications to get all the applications

/applications/1234 GET request to /applications/ with a path parameter of '1234' to get a specific application

+

/garages GET request to /garages to get all the garages

+

/garages/6212/a> GET request to /garages/ with a path parameter of '6212' to get a specific garage



Browse the Swagger UI

From 1503d99ab0ae2402c582e5b55dfa0f4f6ecbea01 Mon Sep 17 00:00:00 2001 From: Joe Loewengruber Date: Sun, 7 Aug 2016 18:59:42 -0400 Subject: [PATCH 09/10] update index.hbs --- views/index.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/index.hbs b/views/index.hbs index 66fb7fb..8ddc497 100644 --- a/views/index.hbs +++ b/views/index.hbs @@ -17,7 +17,7 @@

/applications GET request to /applications to get all the applications

/applications/1234 GET request to /applications/ with a path parameter of '1234' to get a specific application

/garages GET request to /garages to get all the garages

-

/garages/6212/a> GET request to /garages/ with a path parameter of '6212' to get a specific garage

+

/garages/6212 GET request to /garages/ with a path parameter of '6212' to get a specific garage



Browse the Swagger UI

From 57d825124a8c1dd6ae0c28caedfdfa5b9f032c5d Mon Sep 17 00:00:00 2001 From: Joe Loewengruber Date: Wed, 10 Aug 2016 12:42:21 -0400 Subject: [PATCH 10/10] update text --- views/index.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/index.hbs b/views/index.hbs index 8ddc497..b9c1ad5 100644 --- a/views/index.hbs +++ b/views/index.hbs @@ -17,7 +17,7 @@

/applications GET request to /applications to get all the applications

/applications/1234 GET request to /applications/ with a path parameter of '1234' to get a specific application

/garages GET request to /garages to get all the garages

-

/garages/6212 GET request to /garages/ with a path parameter of '6212' to get a specific garage

+

/garages/6212 GET request to /garages/ with a path parameter of '6212' to get a specific garage configuration



Browse the Swagger UI