From 9d0a159b773980aba373f1dde9f87de0978d48f7 Mon Sep 17 00:00:00 2001 From: Elliot Metsger Date: Thu, 9 Sep 2021 10:30:58 -0600 Subject: [PATCH] Add support for CreatedDate and ChangedDate for all Drupal nodes, and provide a layout for parsing the values. (#9) --- drupal/model/model.go | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/drupal/model/model.go b/drupal/model/model.go index 6885b57..602cd3e 100644 --- a/drupal/model/model.go +++ b/drupal/model/model.go @@ -41,6 +41,8 @@ const ( Fits = "fits_technical_metadata" // Constant for the Remote Video media bundle RemoteVideo = "remote_video" + // Layout for timestamps appearing in JsonApiNodeAttributes + TsLayout = "2006-01-02T15:04:05-07:00" ) // Minimally models the elements present in a JSON API data element @@ -51,6 +53,16 @@ type JsonApiData struct { Id string } +// Encapsulates common attributes of Drupal Nodes (collections, objects, media files) as presented by the JSONAPI +type JsonApiNodeAttributes struct { + // Node creation timestamp (managed by Drupal) + // example value: '2021-09-08T20:06:18+00:00' + CreatedDate string `json:"created"` + // Node updated timestamp (managed by Drupal) + // example value: '2021-09-08T20:06:18+00:00' + ChangedDate string `json:"changed"` +} + // Resolve the reference of the data object, useful for references appearing within JSON API `relationships`. This // function formulates a JSON API query based on the type, bundle, and unique identifier of the object, and returns // exactly one resource. @@ -233,6 +245,7 @@ type JsonApiCollection struct { Type jsonapi.DrupalType Id string JsonApiAttributes struct { + JsonApiNodeAttributes Title string UniqueId string `json:"field_unique_id"` Description struct { @@ -283,6 +296,7 @@ type JsonApiIslandoraObj struct { Type jsonapi.DrupalType Id string JsonApiAttributes struct { + JsonApiNodeAttributes Title string UniqueId string `json:"field_unique_id"` CollectionNumber []string `json:"field_collection_number"` @@ -679,6 +693,7 @@ type JsonApiImageMedia struct { Type jsonapi.DrupalType Id string JsonApiAttributes struct { + JsonApiNodeAttributes JsonApiMediaAttributes JsonApiImageMediaAttributes } `json:"attributes"` @@ -722,6 +737,7 @@ type JsonApiDocumentMedia struct { Type jsonapi.DrupalType Id string JsonApiAttributes struct { + JsonApiNodeAttributes JsonApiMediaAttributes } `json:"attributes"` JsonApiRelationships struct { @@ -738,6 +754,7 @@ type JsonApiAudioMedia struct { Type jsonapi.DrupalType Id string JsonApiAttributes struct { + JsonApiNodeAttributes JsonApiMediaAttributes } `json:"attributes"` JsonApiRelationships struct { @@ -754,6 +771,7 @@ type JsonApiExtractedTextMedia struct { Type jsonapi.DrupalType Id string JsonApiAttributes struct { + JsonApiNodeAttributes JsonApiMediaAttributes JsonApiExtractedTextMediaAttributes } `json:"attributes"` @@ -779,6 +797,7 @@ type JsonApiGenericFileMedia struct { Type jsonapi.DrupalType Id string JsonApiAttributes struct { + JsonApiNodeAttributes JsonApiMediaAttributes } `json:"attributes"` JsonApiRelationships struct { @@ -795,6 +814,7 @@ type JsonApiRemoteVideoMedia struct { Type jsonapi.DrupalType Id string JsonApiAttributes struct { + JsonApiNodeAttributes Name string EmbedUrl string `json:"field_media_oembed_video"` RestrictedAccess bool `json:"field_restricted_access"` @@ -811,6 +831,7 @@ type JsonApiVideoMedia struct { Type jsonapi.DrupalType Id string JsonApiAttributes struct { + JsonApiNodeAttributes JsonApiMediaAttributes } `json:"attributes"` JsonApiRelationships struct { @@ -827,15 +848,14 @@ type JsonApiFile struct { Type jsonapi.DrupalType Id string JsonApiAttributes struct { + JsonApiNodeAttributes Filename string Uri struct { Url string Value string } - MimeType string `json:"filemime"` - FileSize int - CreatedDate string `json:"created"` - ChangedDate string `json:"changed"` + MimeType string `json:"filemime"` + FileSize int } `json:"attributes"` } `json:"data"` } @@ -866,6 +886,7 @@ type JsonApiFitsMedia struct { Type jsonapi.DrupalType Id string JsonApiAttributes struct { + JsonApiNodeAttributes JsonApiMediaAttributes } `json:"attributes"` JsonApiRelationships struct {