mirror of
https://github.com/ilri/dspace-statistics-api.git
synced 2025-07-01 12:11:58 +02:00
dspace_statistics_api: Add support for date ranges to /items
You can now POST a JSON request to /items with a list of items and a date range. This allows the possibility to get view and download statistics for arbitrary items and arbitrary date ranges. The JSON request should be in the following format: { "limit": 100, "page": 0, "dateFrom": "2020-01-01T00:00:00Z", "dateTo": "2020-09-09T00:00:00Z", "items": [ "f44cf173-2344-4eb2-8f00-ee55df32c76f", "2324aa41-e9de-4a2b-bc36-16241464683e", "8542f9da-9ce1-4614-abf4-f2e3fdb4b305", "0fe573e7-042a-4240-a4d9-753b61233908" ] } The limit, page, and date parameters are all optional. By default it will use a limit of 100, page 0, and [* TO *] Solr date range.
This commit is contained in:
@ -51,3 +51,20 @@ def get_statistics_shards():
|
||||
# seem to mind if the shards query parameter is empty and I haven't seen
|
||||
# any negative performance impact so this should be fine.
|
||||
return shards
|
||||
|
||||
|
||||
def is_valid_date(date):
|
||||
import datetime
|
||||
import falcon
|
||||
|
||||
try:
|
||||
# Solr date format is: 2020-01-01T00:00:00Z
|
||||
# See: https://docs.python.org/3/library/datetime.html#strftime-strptime-behavior
|
||||
datetime.datetime.strptime(date, "%Y-%m-%dT%H:%M:%SZ")
|
||||
|
||||
return True
|
||||
except ValueError:
|
||||
raise falcon.HTTPBadRequest(
|
||||
title="Invalid parameter",
|
||||
description=f"Invalid date format: {date}. The value must be in format: 2020-01-01T00:00:00Z.",
|
||||
)
|
||||
|
Reference in New Issue
Block a user