Skip to content

Commit

Permalink
Support status in bulk subscriber list update API. Closes #604.
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Feb 4, 2022
1 parent 251c1ea commit 48ef3dc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion cmd/subscribers.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type subQueryReq struct {
TargetListIDs pq.Int64Array `json:"target_list_ids"`
SubscriberIDs pq.Int64Array `json:"ids"`
Action string `json:"action"`
Status string `json:"status"`
}

type subsWrap struct {
Expand Down Expand Up @@ -476,7 +477,7 @@ func handleManageSubscriberLists(c echo.Context) error {
var err error
switch req.Action {
case "add":
_, err = app.queries.AddSubscribersToLists.Exec(IDs, req.TargetListIDs)
_, err = app.queries.AddSubscribersToLists.Exec(IDs, req.TargetListIDs, req.Status)
case "remove":
_, err = app.queries.DeleteSubscriptions.Exec(IDs, req.TargetListIDs)
case "unsubscribe":
Expand Down
6 changes: 3 additions & 3 deletions queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ UPDATE subscriber_lists SET status='unsubscribed', updated_at=NOW()
WHERE subscriber_id = ANY($1::INT[]);

-- name: add-subscribers-to-lists
INSERT INTO subscriber_lists (subscriber_id, list_id)
(SELECT a, b FROM UNNEST($1::INT[]) a, UNNEST($2::INT[]) b)
ON CONFLICT (subscriber_id, list_id) DO NOTHING;
INSERT INTO subscriber_lists (subscriber_id, list_id, status)
(SELECT a, b, (CASE WHEN $3 != '' THEN $3::subscription_status ELSE 'unconfirmed' END) FROM UNNEST($1::INT[]) a, UNNEST($2::INT[]) b)
ON CONFLICT (subscriber_id, list_id) DO UPDATE SET status=(CASE WHEN $3 != '' THEN $3::subscription_status ELSE subscriber_lists.status END);

-- name: delete-subscriptions
DELETE FROM subscriber_lists
Expand Down

0 comments on commit 48ef3dc

Please sign in to comment.