Skip to content

Commit

Permalink
Merge pull request #17 from codeforbtv/kelly-davis-dev
Browse files Browse the repository at this point in the history
Kelly davis dev
  • Loading branch information
nfloersch authored Apr 14, 2021
2 parents a66d32b + ca107cc commit 998e864
Show file tree
Hide file tree
Showing 17 changed files with 8,737 additions and 21 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ https://github.com/swagger-api/swagger-node
<ol>
<li>Created New folder and open terminal/cli in that folder</li>
<li>Use newest-ish node: <pre>nvm use 14.15.4</pre></li>
<!-- I use 14.16, should I use newest (15.12.0)? -->
<li>Install swagger-node: <pre>npm install -g swagger</pre></li>
<li>Create project: <mono>swagger project create hsda-cfbtv</mono>
<ul>
Expand All @@ -36,6 +37,7 @@ https://github.com/swagger-api/swagger-node
</li>
<li>Use the OpenReferral YAML to overwrite the hello-world skeleton
<ol>
<!-- Having trouble here -->
<li>Go get the YAML: https://github.com/openreferral/api-specification/blob/master/_data/api-commons/openapi-hsda.yaml</li>
<li>Start the project in edit mode: <pre>swagger project edit</pre>
<ul>
Expand All @@ -56,6 +58,7 @@ https://github.com/swagger-api/swagger-node
<ol>
<li>There is a problem with swagger-node and modern versions of Node (i.e., => 10 ... which is bizarre!)</li>
<li>Fix based on this note -> https://github.com/swagger-api/swagger-node/issues/586#issuecomment-560078107</li>
<!-- Is this supposed to be package.json? -->
<li>Edit ‘hsda-cftbv/project.json’ and change:
<details>
<summary>that</summary>
Expand Down
56 changes: 37 additions & 19 deletions api/controllers/contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,24 @@ module.exports = {
Param 2: a handle to the response object
*/
function listContacts(req, res) {
// console.log(req)
// variables defined in the Swagger document can be referenced using req.swagger.params.{parameter_name}
var query = req.swagger.params.query.value || 'no query given';
var queries = req.swagger.params.queries.value || 'no queries given';
var page = req.swagger.params.page.value || 'no page given';
var per_page = req.swagger.params.per_page.value || 'no per_page given';
var sort_by = req.swagger.params.sort_by.value || 'no sort_by given';
var order = req.swagger.params.order.value || 'no order given';
var outputMessage = [
query,
queries,
page,
per_page,
sort_by,
order
];

// this sends back a JSON response which is a single string
var outputMessage = {
'query': query,
'queries': queries,
'page': page,
'per_page': per_page,
'sort_by': sort_by,
'order': order
};

// this sends back a JSON response
res.json(outputMessage);
}

Expand All @@ -79,12 +80,25 @@ function addContact(req, res) {
}

function listContactsComplete(req, res) {
// This is currently the same as the 'listContacts' method since they appear to have the same definiton in the YAML params
// variables defined in the Swagger document can be referenced using req.swagger.params.{parameter_name}
var name = req.swagger.params.name.value || 'stranger';
var hello = util.format('Hello, %s!', name);
var query = req.swagger.params.query.value || 'no query given';
var queries = req.swagger.params.queries.value || 'no queries given';
var page = req.swagger.params.page.value || 'no page given';
var per_page = req.swagger.params.per_page.value || 'no per_page given';
var sort_by = req.swagger.params.sort_by.value || 'no sort_by given';
var order = req.swagger.params.order.value || 'no order given';
var outputMessage = {
'query': query,
'queries': queries,
'page': page,
'per_page': per_page,
'sort_by': sort_by,
'order': order
};

// this sends back a JSON response which is a single string
res.json(hello);
res.json(outputMessage);
}

function addContactsComplete(req, res) {
Expand All @@ -98,11 +112,13 @@ function addContactsComplete(req, res) {

function getContactComplete(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 hello = util.format('Hello, %s!', name);
var contact_id = req.swagger.params.contact_id.value ? req.swagger.params.contact_id.value : 'stranger';
var outputMessage = {
'contact_id': contact_id,
};

// this sends back a JSON response which is a single string
res.json(hello);
res.json(outputMessage);
}

function updateContactsComplete(req, res) {
Expand All @@ -125,11 +141,13 @@ function deleteContact(req, res) {

function getContact(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 hello = util.format('Hello, %s!', name);
var contact_id = req.swagger.params.contact_id.value ? req.swagger.params.contact_id.value : 'stranger';
var outputMessage = {
'contact_id': contact_id,
};

// this sends back a JSON response which is a single string
res.json(hello);
res.json(outputMessage);
}

function updateContact(req, res) {
Expand Down
34 changes: 34 additions & 0 deletions hdsa-cfbtv/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# IDE files
.idea

# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# Commenting this out is preferred by some people, see
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

# Users Environment Variables
.lock-wscript

# Runtime configuration for swagger app
config/runtime.yaml
1 change: 1 addition & 0 deletions hdsa-cfbtv/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Skeleton project for Swagger
1 change: 1 addition & 0 deletions hdsa-cfbtv/api/controllers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Place your controllers in this directory.
45 changes: 45 additions & 0 deletions hdsa-cfbtv/api/controllers/hello_world.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'use strict';
/*
'use strict' is not required but helpful for turning syntactical errors into true errors in the program flow
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode
*/

/*
Modules make it possible to import JavaScript files into your application. Modules are imported
using 'require' statements that give you a reference to the module.
It is a good idea to list the modules that your application depends on in the package.json in the project root
*/
var util = require('util');

/*
Once you 'require' a module you can reference the things that it exports. These are defined in module.exports.
For a controller in a127 (which this is) you should export the functions referenced in your Swagger document by name.
Either:
- The HTTP Verb of the corresponding operation (get, put, post, delete, etc)
- Or the operationId associated with the operation in your Swagger document
In the starter/skeleton project the 'get' operation on the '/hello' path has an operationId named 'hello'. Here,
we specify that in the exports of this module that 'hello' maps to the function named 'hello'
*/
module.exports = {
hello: hello
};

/*
Functions in a127 controllers used for operations should take two parameters:
Param 1: a handle to the request object
Param 2: a handle to the response object
*/
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';
console.log('res', res)
var hello = util.format('Hello, %s!', name);

// this sends back a JSON response which is a single string
res.json(hello);
}
1 change: 1 addition & 0 deletions hdsa-cfbtv/api/helpers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Place helper files in this directory.
1 change: 1 addition & 0 deletions hdsa-cfbtv/api/mocks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Place controllers for mock mode in this directory.
Loading

0 comments on commit 998e864

Please sign in to comment.