Skip to content

Commit

Permalink
Add maxDaysAgo option to queries for a specific commodity in a system
Browse files Browse the repository at this point in the history
Should improve relvance of results as some of the data can be old if left unbounded  - this is not a performance improvement, just a usability improvement.

The resutls are also sorted in a more meaningful way.
  • Loading branch information
iaincollins committed Nov 9, 2024
1 parent a86c48e commit c87604d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ Get all buy/sell orders for a commodity in a system.

e.g. https://api.ardent-industry.com/v1/system/name/Sol/commodity/name/gold

##### Supported query parameters

* maxDaysAgo (int); default 30

#### Get a list of nearby importers of a commodity

Get a list of nearby places that importing a commodity close to the specified
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ardent-api",
"version": "4.7.0",
"version": "4.8.0",
"description": "Ardent API provides access to data submitted to EDDN",
"main": "index.js",
"scripts": {
Expand Down
8 changes: 7 additions & 1 deletion router/api/systems.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ module.exports = (router) => {
})

router.get('/api/v1/system/name/:systemName/commodity/name/:commodityName', async (ctx, next) => {
const { systemName, commodityName } = ctx.params
const {
systemName,
commodityName,
maxDaysAgo = DEFAULT_MAX_RESULTS_AGE
} = ctx.params

// Validate system name
const system = await getSystemByName(systemName)
Expand Down Expand Up @@ -215,6 +219,8 @@ module.exports = (router) => {
LEFT JOIN stations.stations s ON c.marketId = s.marketId
WHERE c.systemName = @systemName
AND c.commodityName = @commodityName
AND c.updatedAtDay > '${getISOTimestamp(`-${maxDaysAgo}`).split('T')[0]}'
ORDER BY c.stationName
`, { systemName, commodityName })

ctx.body = commodities
Expand Down

0 comments on commit c87604d

Please sign in to comment.