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"`
|
||||
SubscriberIDs pq.Int64Array `json:"ids"`
|
||||
Action string `json:"action"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
type subsWrap struct {
|
||||
|
@ -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":
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue