Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrInvalidEvent = errors.New("invalid event")
)
Functions ¶
func IsValidationError ¶
Types ¶
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
func NewRepository ¶
func NewRepository(db *gorm.DB) *Repository
func (*Repository) Delete ¶
func (r *Repository) Delete(filters ...SelectFilter) error
func (*Repository) Replace ¶
func (r *Repository) Replace(webhook *Webhook) error
func (*Repository) Select ¶
func (r *Repository) Select(filters ...SelectFilter) ([]*Webhook, error)
type SelectFilter ¶
type SelectFilter func(*selectFilter)
func WithDeviceID ¶ added in v1.22.0
func WithDeviceID(deviceID string, exact bool) SelectFilter
WithDeviceID creates a SelectFilter that filters by device ID. If exact is true, only records with the exact device ID are matched. If exact is false, records with the device ID or with a null device ID are matched.
func WithExtID ¶
func WithExtID(extID string) SelectFilter
func WithUserID ¶
func WithUserID(userID string) SelectFilter
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func NewService(params ServiceParams) *Service
func (*Service) Delete ¶
func (s *Service) Delete(userID string, filters ...SelectFilter) error
Delete removes webhooks for a specific user that match the provided filters. It ensures that the filter includes the user's ID.
func (*Service) Replace ¶
func (s *Service) Replace(userID string, webhook *smsgateway.Webhook) error
Replace creates or updates a webhook for a given user. After replacing the webhook, it asynchronously notifies all the user's devices. Returns an error if the operation fails.
func (*Service) Select ¶
func (s *Service) Select(userID string, filters ...SelectFilter) ([]smsgateway.Webhook, error)
Select returns a list of webhooks for a specific user that match the provided filters. It ensures that the filter includes the user's ID.
type ServiceParams ¶
type ValidationError ¶
func (ValidationError) Error ¶
func (e ValidationError) Error() string
func (ValidationError) Unwrap ¶
func (e ValidationError) Unwrap() error
type Webhook ¶
type Webhook struct {
models.SoftDeletableModel
ID uint64 `json:"-" gorm:"->;primaryKey;type:BIGINT UNSIGNED;autoIncrement"`
ExtID string `json:"id" gorm:"not null;type:varchar(36);uniqueIndex:unq_webhooks_user_extid,priority:2"`
UserID string `json:"-" gorm:"<-:create;not null;type:varchar(32);uniqueIndex:unq_webhooks_user_extid,priority:1"`
DeviceID *string `json:"device_id,omitempty" gorm:"type:varchar(21);index:idx_webhooks_device"`
URL string `json:"url" validate:"required,http_url" gorm:"not null;type:varchar(256)"`
Event smsgateway.WebhookEvent `json:"event" gorm:"not null;type:varchar(32)"`
User users.User `gorm:"foreignKey:UserID;constraint:OnDelete:CASCADE"`
Device *models.Device `gorm:"foreignKey:DeviceID;constraint:OnDelete:CASCADE"`
}
Click to show internal directories.
Click to hide internal directories.