From 6d3ae4cc733fb601168cca5d1697164e01c04f4c Mon Sep 17 00:00:00 2001 From: Romain Date: Wed, 9 Nov 2022 17:10:11 +0100 Subject: [PATCH] Add subscription created_at, updated_at when listing subscribers list (#1018) --- models/models.go | 4 +++- queries.sql | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/models/models.go b/models/models.go index 832b061d7..166f56b4a 100644 --- a/models/models.go +++ b/models/models.go @@ -220,7 +220,9 @@ type List struct { SubscriberID int `db:"subscriber_id" json:"-"` // This is only relevant when querying the lists of a subscriber. - SubscriptionStatus string `db:"subscription_status" json:"subscription_status,omitempty"` + SubscriptionStatus string `db:"subscription_status" json:"subscription_status,omitempty"` + SubscriptionCreatedAt null.Time `db:"subscription_created_at" json:"subscription_created_at,omitempty"` + SubscriptionUpdatedAt null.Time `db:"subscription_updated_at" json:"subscription_updated_at,omitempty"` // Pseudofield for getting the total number of subscribers // in searches and queries. diff --git a/queries.sql b/queries.sql index d1641f3d6..750e90586 100644 --- a/queries.sql +++ b/queries.sql @@ -38,7 +38,13 @@ SELECT * FROM lists WITH subs AS ( SELECT subscriber_id, JSON_AGG( ROW_TO_JSON( - (SELECT l FROM (SELECT subscriber_lists.status AS subscription_status, lists.*) l) + (SELECT l FROM ( + SELECT + subscriber_lists.status AS subscription_status, + subscriber_lists.created_at AS subscription_created_at, + subscriber_lists.updated_at AS subscription_updated_at, + lists.* + ) l) ) ) AS lists FROM lists LEFT JOIN subscriber_lists ON (subscriber_lists.list_id = lists.id)