add more ways to slice time, update swagger to match

This commit is contained in:
Ben West
2015-08-30 19:34:51 -07:00
parent 7c11847033
commit 05eff3f604
2 changed files with 161 additions and 9 deletions
+32 -9
View File
@@ -194,7 +194,8 @@ function configure (app, wares, ctx) {
query.count = 10;
}
ctx.entries.list(query, function(err, entries) {
var storage = req.storage || ctx.entries;
storage.list(query, function(err, entries) {
res.entries = entries;
res.entries_err = err;
return next( );
@@ -259,27 +260,49 @@ function configure (app, wares, ctx) {
var matches = pattern.map(function iter (pat) {
return new RegExp(pat);
});
var query = {
dateString: {
var field = req.patternField;
var query = { };
query[field] = {
$in: matches
}
};
if (req.query.find) {
if (req.query.find.dateString) {
req.query.find.dateString.$in = query.dateString.$in;
if (req.query.find[field]) {
req.query.find[field].$in = query[field].$in;
} else {
req.query.find.dateString = query.dateString;
req.query.find[field] = query[field];
}
} else {
req.query.find = query;
}
if (req.params.type) {
req.query.find.type = req.params.type;
}
next( );
}
api.get('/times/echo/:prefix?/:regex?', prep_patterns, function (req, res, next) {
function prep_pattern_field (req, res, next) {
if (req.params.field) {
req.patternField = req.params.field;
} else {
req.patternField = 'dateString';
}
next( );
}
function prep_storage (req, res, next) {
if (req.params.storage) {
req.storage = ctx[req.params.storage];
} else {
req.storage = ctx.entries;
}
next( );
}
api.get('/times/echo/:prefix?/:regex?', prep_storage, prep_pattern_field, prep_patterns, prep_patterns, function (req, res, next) {
res.json({ req: { params: req.params, query: req.query}, pattern: req.pattern});
});
api.get('/times/:prefix?/:regex?', prep_patterns, query_models, format_entries);
api.get('/times/:prefix?/:regex?', prep_storage, prep_pattern_field, prep_patterns, prep_patterns, query_models, format_entries);
api.get('/slice/:storage/:field/:type?/:prefix?/:regex?', prep_storage, prep_pattern_field, prep_patterns, query_models, format_entries);
// Allow previewing your post content, just echos everything you
// posted back out.
+129
View File
@@ -46,6 +46,135 @@ paths:
schema:
$ref: '#/definitions/Error'
/slice/{storage}/{field}/{type}/{prefix}/{regex}:
get:
summary: All Entries matching query
description: The Entries endpoint returns information about the Nightscout entries.
parameters:
- name: storage
in: path
type: string
description: Prefix to use in constructing a prefix-based regex, default is `entries`.
required: true
- name: field
in: path
type: string
description: Name of the field to use Regex against in query object, default is `dateString`.
required: true
- name: type
in: path
type: string
description: The type field to search against, default is sgv.
required: true
- name: prefix
in: path
type: string
description: Prefix to use in constructing a prefix-based regex.
required: false
- name: regex
in: path
type: string
description: Tail part of regexp to use in expanding/construccting a query object.
required: false
- name: find
in: query
description: The query used to find entries, support nested query syntax, for example `find[dateString][$gte]=2015-08-27`. All find paramertes are interpreted as strings.
required: false
type: string
- name: count
in: query
description: Number of entries to return.
required: false
type: number
tags:
- Entries
responses:
"200":
description: An array of entries
schema:
$ref: '#/definitions/Entries'
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
/times/echo/{prefix}/{regex}:
get:
summary: Echo the query object to be used.
description: Echo debug information about the query object constructed.
parameters:
- name: prefix
in: path
type: string
description: Prefix to use in constructing a prefix-based regex.
required: false
- name: regex
in: path
type: string
description: Tail part of regexp to use in expanding/construccting a query object.
required: false
- name: find
in: query
description: The query used to find entries, support nested query syntax, for example `find[dateString][$gte]=2015-08-27`. All find paramertes are interpreted as strings.
required: false
type: string
- name: count
in: query
description: Number of entries to return.
required: false
type: number
tags:
- Entries
responses:
"200":
description: An array of entries
schema:
$ref: '#/definitions/Entries'
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
/times/{prefix}/{regex}:
get:
summary: All Entries matching query
description: The Entries endpoint returns information about the Nightscout entries.
parameters:
- name: prefix
in: path
type: string
description: Prefix to use in constructing a prefix-based regex.
required: false
- name: regex
in: path
type: string
description: Tail part of regexp to use in expanding/construccting a query object.
required: false
- name: find
in: query
description: The query used to find entries, support nested query syntax, for example `find[dateString][$gte]=2015-08-27`. All find paramertes are interpreted as strings.
required: false
type: string
- name: count
in: query
description: Number of entries to return.
required: false
type: number
tags:
- Entries
responses:
"200":
description: An array of entries
schema:
$ref: '#/definitions/Entries'
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
/entries:
get:
summary: All Entries matching query