Files
Stefan Jacobi c9994bdc3a fix(review): fix review findings
* admin api: make email primary when user has no emails
* utils: move get updated user and webhook trigger to utils to reduce duplicated code
* events: remove unused user and email event - Check is replaced with string variant
* remove unused dtos
* fix tests after changes
* webhook tests: switch to test.Suite instead of TestPersister -> added deprecation annotation to test.NewPersister
* Email Verification: Fix trigger of webhook when email verification is enabled and a email is created but not validated

Closes: #692, #1051
2024-01-25 13:20:56 +01:00

38 lines
1.4 KiB
Go

package models
import (
"github.com/gobuffalo/validate/v3/validators"
"time"
"github.com/gobuffalo/pop/v6"
"github.com/gobuffalo/validate/v3"
"github.com/gofrs/uuid"
)
// Webhook is used by pop to map your webhooks database table to your go code.
type Webhook struct {
ID uuid.UUID `json:"id" db:"id"`
Callback string `json:"callback" db:"callback"`
Enabled bool `json:"enabled" db:"enabled"`
Failures int `json:"failures" db:"failures"`
ExpiresAt time.Time `json:"expires_at" db:"expires_at"`
WebhookEvents WebhookEvents `json:"events" has_many:"webhook_events"`
CreatedAt time.Time `json:"created_at" db:"created_at"`
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
}
// Webhooks are not required by pop and may be deleted
type Webhooks []Webhook
// Validate gets run every time you call a "pop.Validate*" (pop.ValidateAndSave, pop.ValidateAndCreate, pop.ValidateAndUpdate) method.
// This method is not required and may be deleted.
func (w *Webhook) Validate(tx *pop.Connection) (*validate.Errors, error) {
return validate.Validate(
&validators.UUIDIsPresent{Name: "ID", Field: w.ID},
&validators.StringIsPresent{Name: "Callback", Field: w.Callback},
&validators.TimeIsPresent{Name: "ExpiresAt", Field: w.ExpiresAt},
&validators.TimeIsPresent{Name: "UpdatedAt", Field: w.UpdatedAt},
&validators.TimeIsPresent{Name: "CreatedAt", Field: w.CreatedAt},
), nil
}