Documentation
¶
Index ¶
- Variables
- func IsValidationError(err error) bool
- type PostgresRepository
- func (r *PostgresRepository) Create(ctx context.Context, sub *Subscription) error
- func (r *PostgresRepository) Delete(ctx context.Context, id string) error
- func (r *PostgresRepository) GetByAssetAndUser(ctx context.Context, assetID, userID string) (*Subscription, error)
- func (r *PostgresRepository) GetByID(ctx context.Context, id string) (*Subscription, error)
- func (r *PostgresRepository) GetSubscribersForAsset(ctx context.Context, assetID string, notificationType string) ([]string, error)
- func (r *PostgresRepository) ListByUser(ctx context.Context, userID string) ([]*SubscriptionWithAsset, error)
- func (r *PostgresRepository) Update(ctx context.Context, id string, types []string) (*Subscription, error)
- type Repository
- type Service
- func (s *Service) Create(ctx context.Context, assetID, userID string, types []string) (*Subscription, error)
- func (s *Service) Delete(ctx context.Context, id, userID string) error
- func (s *Service) GetByAssetAndUser(ctx context.Context, assetID, userID string) (*Subscription, error)
- func (s *Service) GetSubscribersForAsset(ctx context.Context, assetID string, notificationType string) ([]string, error)
- func (s *Service) ListByUser(ctx context.Context, userID string) ([]*SubscriptionWithAsset, error)
- func (s *Service) Update(ctx context.Context, id, userID string, types []string) (*Subscription, error)
- type Subscription
- type SubscriptionWithAsset
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrNotFound = errors.New("subscription not found") ErrAlreadyExists = errors.New("subscription already exists for this asset") )
Functions ¶
func IsValidationError ¶
IsValidationError reports whether err is a user-facing validation error.
Types ¶
type PostgresRepository ¶
type PostgresRepository struct {
// contains filtered or unexported fields
}
func (*PostgresRepository) Create ¶
func (r *PostgresRepository) Create(ctx context.Context, sub *Subscription) error
func (*PostgresRepository) Delete ¶
func (r *PostgresRepository) Delete(ctx context.Context, id string) error
func (*PostgresRepository) GetByAssetAndUser ¶
func (r *PostgresRepository) GetByAssetAndUser(ctx context.Context, assetID, userID string) (*Subscription, error)
func (*PostgresRepository) GetByID ¶
func (r *PostgresRepository) GetByID(ctx context.Context, id string) (*Subscription, error)
func (*PostgresRepository) GetSubscribersForAsset ¶
func (*PostgresRepository) ListByUser ¶
func (r *PostgresRepository) ListByUser(ctx context.Context, userID string) ([]*SubscriptionWithAsset, error)
func (*PostgresRepository) Update ¶
func (r *PostgresRepository) Update(ctx context.Context, id string, types []string) (*Subscription, error)
type Repository ¶
type Repository interface {
Create(ctx context.Context, sub *Subscription) error
Update(ctx context.Context, id string, types []string) (*Subscription, error)
Delete(ctx context.Context, id string) error
GetByID(ctx context.Context, id string) (*Subscription, error)
GetByAssetAndUser(ctx context.Context, assetID, userID string) (*Subscription, error)
ListByUser(ctx context.Context, userID string) ([]*SubscriptionWithAsset, error)
GetSubscribersForAsset(ctx context.Context, assetID string, notificationType string) ([]string, error)
}
Repository defines the subscription data access interface.
func NewPostgresRepository ¶
func NewPostgresRepository(db *pgxpool.Pool) Repository
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func NewService(repo Repository) *Service
func (*Service) GetByAssetAndUser ¶
func (*Service) GetSubscribersForAsset ¶
func (*Service) ListByUser ¶
type Subscription ¶
type Subscription struct {
ID string `json:"id"`
AssetID string `json:"asset_id"`
UserID string `json:"user_id"`
NotificationTypes []string `json:"notification_types"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Subscription represents a user's subscription to notifications for a specific asset.
type SubscriptionWithAsset ¶
type SubscriptionWithAsset struct {
Subscription
AssetName string `json:"asset_name"`
AssetMRN string `json:"asset_mrn"`
AssetType string `json:"asset_type"`
}
SubscriptionWithAsset extends Subscription with denormalized asset metadata.
type ValidationError ¶
type ValidationError struct {
Message string
}
ValidationError represents a user-facing validation failure.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
Click to show internal directories.
Click to hide internal directories.