Support status
in bulk subscriber list update API. Closes #604.
This commit is contained in:
parent
251c1ea64f
commit
48ef3dcb14
2 changed files with 5 additions and 4 deletions
|
@ -31,6 +31,7 @@ type subQueryReq struct {
|
||||||
TargetListIDs pq.Int64Array `json:"target_list_ids"`
|
TargetListIDs pq.Int64Array `json:"target_list_ids"`
|
||||||
SubscriberIDs pq.Int64Array `json:"ids"`
|
SubscriberIDs pq.Int64Array `json:"ids"`
|
||||||
Action string `json:"action"`
|
Action string `json:"action"`
|
||||||
|
Status string `json:"status"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type subsWrap struct {
|
type subsWrap struct {
|
||||||
|
@ -476,7 +477,7 @@ func handleManageSubscriberLists(c echo.Context) error {
|
||||||
var err error
|
var err error
|
||||||
switch req.Action {
|
switch req.Action {
|
||||||
case "add":
|
case "add":
|
||||||
_, err = app.queries.AddSubscribersToLists.Exec(IDs, req.TargetListIDs)
|
_, err = app.queries.AddSubscribersToLists.Exec(IDs, req.TargetListIDs, req.Status)
|
||||||
case "remove":
|
case "remove":
|
||||||
_, err = app.queries.DeleteSubscriptions.Exec(IDs, req.TargetListIDs)
|
_, err = app.queries.DeleteSubscriptions.Exec(IDs, req.TargetListIDs)
|
||||||
case "unsubscribe":
|
case "unsubscribe":
|
||||||
|
|
|
@ -156,9 +156,9 @@ UPDATE subscriber_lists SET status='unsubscribed', updated_at=NOW()
|
||||||
WHERE subscriber_id = ANY($1::INT[]);
|
WHERE subscriber_id = ANY($1::INT[]);
|
||||||
|
|
||||||
-- name: add-subscribers-to-lists
|
-- name: add-subscribers-to-lists
|
||||||
INSERT INTO subscriber_lists (subscriber_id, list_id)
|
INSERT INTO subscriber_lists (subscriber_id, list_id, status)
|
||||||
(SELECT a, b FROM UNNEST($1::INT[]) a, UNNEST($2::INT[]) b)
|
(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 NOTHING;
|
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
|
-- name: delete-subscriptions
|
||||||
DELETE FROM subscriber_lists
|
DELETE FROM subscriber_lists
|
||||||
|
|
Loading…
Reference in a new issue