Skip to content

Commit

Permalink
notifier: change DeleteNotification to CollectNotifications
Browse files Browse the repository at this point in the history
This removes the individual per-id delete in favor of a general "delete
extra stuff" method.

Signed-off-by: Hank Donnay <hdonnay@redhat.com>
  • Loading branch information
hdonnay committed Feb 22, 2022
1 parent 4ba6aca commit 0733900
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
36 changes: 15 additions & 21 deletions notifier/mockstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import (

// MockStore implements a mock Store.
type MockStore struct {
Notifications_ func(ctx context.Context, id uuid.UUID, page *Page) ([]Notification, Page, error)
PutNotifications_ func(ctx context.Context, opts PutOpts) error
PutReceipt_ func(ctx context.Context, updater string, r Receipt) error
DeleteNotitfications_ func(ctx context.Context, id uuid.UUID) error
Receipt_ func(ctx context.Context, id uuid.UUID) (Receipt, error)
ReceiptByUOID_ func(ctx context.Context, id uuid.UUID) (Receipt, error)
Created_ func(ctx context.Context) ([]uuid.UUID, error)
Failed_ func(ctx context.Context) ([]uuid.UUID, error)
Deleted_ func(ctx context.Context) ([]uuid.UUID, error)
SetDelivered_ func(ctx context.Context, id uuid.UUID) error
SetDeliveredFailed_ func(ctx context.Context, id uuid.UUID) error
SetDeleted_ func(ctx context.Context, id uuid.UUID) error
Notifications_ func(ctx context.Context, id uuid.UUID, page *Page) ([]Notification, Page, error)
PutNotifications_ func(ctx context.Context, opts PutOpts) error
PutReceipt_ func(ctx context.Context, updater string, r Receipt) error
CollectNotitfications_ func(ctx context.Context) error
Receipt_ func(ctx context.Context, id uuid.UUID) (Receipt, error)
ReceiptByUOID_ func(ctx context.Context, id uuid.UUID) (Receipt, error)
Created_ func(ctx context.Context) ([]uuid.UUID, error)
Failed_ func(ctx context.Context) ([]uuid.UUID, error)
Deleted_ func(ctx context.Context) ([]uuid.UUID, error)
SetDelivered_ func(ctx context.Context, id uuid.UUID) error
SetDeliveredFailed_ func(ctx context.Context, id uuid.UUID) error
SetDeleted_ func(ctx context.Context, id uuid.UUID) error
}

// Notifications retrieves the list of notifications associated with a
Expand Down Expand Up @@ -50,15 +50,9 @@ func (m *MockStore) PutReceipt(ctx context.Context, updater string, r Receipt) e
return m.PutReceipt_(ctx, updater, r)
}

// DeleteNotifications garbage collects all notifications associated
// with a notification id.
//
// Normally Receipter.SetDeleted will be issues first, however
// application logic may decide to gc notifications which have not been
// set deleted after some period of time, thus this condition should not
// be checked.
func (m *MockStore) DeleteNotifications(ctx context.Context, id uuid.UUID) error {
return m.DeleteNotitfications_(ctx, id)
// CollectNotifications garbage collects all notifications.
func (m *MockStore) CollectNotifications(ctx context.Context) error {
return m.CollectNotitfications_(ctx)
}

// Receipt returns the Receipt for a given notification id
Expand Down
5 changes: 5 additions & 0 deletions notifier/postgres/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package postgres

import (
"context"
"errors"
"time"

"github.com/google/uuid"
Expand Down Expand Up @@ -118,3 +119,7 @@ func notifications(ctx context.Context, pool *pgxpool.Pool, id uuid.UUID, page *

return notifications, outPage, nil
}

func (*Store) CollectNotifications(ctx context.Context) error {
return errors.New("unimplemented")
}
5 changes: 2 additions & 3 deletions notifier/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,13 @@ type Notificationer interface {
//
// After this method returns all methods on the Receipter interface must work accordingly.
PutReceipt(ctx context.Context, updater string, r Receipt) error
// DeleteNotifications garbage collects all notifications associated
// with a notification id.
// CollectNotifications garbage collects all notifications.
//
// Normally Receipter.SetDeleted will be issues first, however
// application logic may decide to GC notifications which have not been
// set deleted after some period of time, thus this condition should not
// be checked.
DeleteNotifications(ctx context.Context, id uuid.UUID) error
CollectNotifications(ctx context.Context) error
}

// Receipter implements persistence methods for Receipt models
Expand Down

0 comments on commit 0733900

Please sign in to comment.