Skip to content

Commit 3ab3fb0

Browse files
authored
Merge pull request #263 from UW-Macrostrat/internal-consistency
Internal consistency
2 parents 3a79137 + 092f6c2 commit 3ab3fb0

File tree

7 files changed

+60
-31
lines changed

7 files changed

+60
-31
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@macrostrat/api-v2",
3-
"version": "2.1.6",
3+
"version": "2.1.7",
44
"description": "An API for stratigraphic and geological information (Version 2).",
55
"main": "server.js",
66
"repository": {

v2/CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,22 @@
11
# Macrostrat API v2 Changelog
22

3+
## [2.1.7] - 2025-11-19
4+
5+
- Allow multiple `status_code` values in `/columns` route
6+
- Add `status_code` filter option to
7+
8+
9+
## [2.1.5] - 2025-11-07
10+
11+
- Add `t_units` and `t_sections` summary parameters to short `/columns` output
12+
13+
## [2.x.x] Series - 2024 to 2025
14+
15+
Moved the entire API to be based on PostgreSQL instead of a mix of PostgreSQL
16+
and MariaDB.
17+
18+
--------
19+
320
## tl;dr
421

522
- Added `?sample` to every route (except `/mobile`), which returns 5 records.

v2/columns.ts

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -148,48 +148,50 @@ module.exports = function (req, res, next, callback) {
148148
}
149149

150150
var geo = "";
151-
var params = [
152-
Object.keys(new_cols).map(function (d) {
153-
return parseInt(d);
154-
}),
155-
];
151+
152+
const col_ids = Object.keys(new_cols).map(function (d) {
153+
return parseInt(d);
154+
});
155+
156+
let params = {
157+
col_ids,
158+
};
156159

157160
var limit = "sample" in req.query ? " LIMIT 5" : "";
158161
var groupBy = "";
159-
var orderby = "";
162+
let orderBy = "";
160163

161164
if (req.query.status_code) {
162-
params.push(decodeURI(req.query.status_code));
165+
params["status_code"] = larkin.parseMultipleStrings(
166+
decodeURI(req.query.status_code),
167+
);
163168
} else {
164-
params.push("active");
169+
params["status_code"] = ["active"];
165170
}
166171

167172
if (req.query.format && api.acceptedFormats.geo[req.query.format]) {
168173
if (req.query.shape) {
169174
geo =
170-
", ST_AsGeoJSON(ST_Intersection(col_areas.col_area, ST_MakeValid($3))) geojson";
171-
params.push(req.query.shape);
175+
", ST_AsGeoJSON(ST_Intersection(col_areas.col_area, ST_MakeValid(:shape))) geojson";
176+
params["shape"] = req.query.shape;
172177
} else {
173178
geo = ", ST_AsGeoJSON(col_areas.col_area) geojson";
174179
}
175180
groupBy = ", col_areas.col_area";
176181
}
177182

178183
if (req.query.lat && req.query.lng && req.query.adjacents) {
179-
orderby =
180-
"ORDER BY ST_Distance(ST_SetSRID(col_areas.col_area, 4326), ST_GeometryFromText($3, 4326))";
181-
params.push(
182-
"POINT(" +
183-
larkin.normalizeLng(req.query.lng) +
184-
" " +
185-
req.query.lat +
186-
")",
187-
);
184+
orderBy =
185+
"ORDER BY ST_Distance(ST_SetSRID(col_areas.col_area, 4326), ST_GeometryFromText(ST_MakePoint(:lng, :lat), 4326))";
186+
params["lat"] = req.query.lat;
187+
params["lng"] = larkin.normalizeLng(req.query.lng);
188188
groupBy = ", col_areas.col_area";
189189
} else if (req.query.col_id && req.query.adjacents) {
190-
orderby =
191-
"ORDER BY ST_Distance(ST_Centroid(col_areas.col_area), (SELECT ST_Centroid(col_area) FROM macrostrat.col_areas WHERE col_id = $3))";
192-
params.push(req.query.col_id);
190+
orderBy = `ORDER BY ST_Distance(
191+
ST_Centroid(col_areas.col_area),
192+
(SELECT ST_Centroid(col_area) FROM macrostrat.col_areas WHERE col_id = :col_id)
193+
)`;
194+
params["col_id"] = req.query.col_id;
193195
groupBy = ", col_areas.col_area";
194196
}
195197

@@ -215,10 +217,10 @@ module.exports = function (req, res, next, callback) {
215217
LEFT JOIN macrostrat.col_areas on col_areas.col_id = cols.id
216218
LEFT JOIN macrostrat.col_groups ON col_groups.id = cols.col_group_id
217219
LEFT JOIN macrostrat.col_refs ON cols.id = col_refs.col_id
218-
WHERE cols.status_code = $2
219-
AND cols.id = ANY($1)
220+
WHERE cols.status_code = ANY(:status_code)
221+
AND cols.id = ANY(:col_ids)
220222
GROUP BY col_areas.col_id, cols.id, col_groups.col_group, col_groups.id ${groupBy}
221-
${orderby}
223+
${orderBy}
222224
${limit}
223225
`,
224226
params,

v2/definitions/columns.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,13 @@ module.exports = function (req, res, next, cb) {
4848
where.push("cols.project_id = ANY(:project_id)");
4949
params["project_id"] = larkin.parseMultipleIds(req.query.project_id);
5050
}
51-
if (req.query.status) {
52-
where.push("status_code = :status");
53-
params["status"] = req.query.status;
51+
if (req.query.status_code || req.query.status) {
52+
// `status` parameter still works but has been superseded by `status_code`
53+
// multiple status codes can be provided
54+
where.push("status_code = ANY(:status_code)");
55+
params["status_code"] = larkin.parseMultipleIds(
56+
req.query.status_code ?? req.query.status,
57+
);
5458
}
5559

5660
if (where.length) {

v2/defs.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
const statusCodeExplanation =
2+
"string, column status codes, values 'active','in process','obsolete'. Defaults to 'active'";
3+
14
(function () {
25
const sharedUnitFilters = {
36
unit_id: "integer, a valid unit id",
@@ -42,6 +45,7 @@
4245
adjacents:
4346
"boolean, if lat/lng or col_id is specified, optionally return all units in columns that touch the polygon containing the supplied lat/lng",
4447
project_id: "a Macrostrat project ID",
48+
status_code: statusCodeExplanation,
4549
response: "Any available response_type. Default is short.",
4650
format: "string, desired output format",
4751
};
@@ -455,8 +459,8 @@
455459
col_group_id: "integer, one or more column group ids",
456460
col_name: "string, column name",
457461
project_id: "integer, one or more project ids",
458-
status:
459-
"string, status of column, values 'active','in process','obsolete'",
462+
status_code: statusCodeExplanation,
463+
status: "same as status_code (deprecated signature)",
460464
all: "Return all column definitions",
461465
format: "Desired output format",
462466
},

v2/fossils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ module.exports = function (req, res, next) {
3333
req.query.col_group_id ||
3434
req.query.strat_name_id ||
3535
req.query.strat_name_concept_id ||
36+
req.query.project_id ||
3637
"sample" in req.query
3738
) {
3839
callback(null, {

v2/units.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ module.exports = function (req, res, next, cb) {
121121
}
122122
});
123123
} else if (req.query.col_id && req.query.adjacents) {
124+
/** TODO: this can probably be improved with a spatial join instead of a subquery */
124125
var col_ids = larkin.parseMultipleIds(req.query.col_id),
125126
placeholders = col_ids.map(function (d, i) {
126127
return "$" + (i + 1);

0 commit comments

Comments
 (0)