fix: rename title -> event_description
This commit is contained in:
parent
deaf1e2ff7
commit
a38e9d4e6c
|
@ -15,15 +15,15 @@ import (
|
||||||
|
|
||||||
// Webhook model for db
|
// Webhook model for db
|
||||||
type Webhook struct {
|
type Webhook struct {
|
||||||
Key string `json:"_key,omitempty" bson:"_key,omitempty" cql:"_key,omitempty" dynamo:"key,omitempty"` // for arangodb
|
Key string `json:"_key,omitempty" bson:"_key,omitempty" cql:"_key,omitempty" dynamo:"key,omitempty"` // for arangodb
|
||||||
ID string `gorm:"primaryKey;type:char(36)" json:"_id" bson:"_id" cql:"id" dynamo:"id,hash"`
|
ID string `gorm:"primaryKey;type:char(36)" json:"_id" bson:"_id" cql:"id" dynamo:"id,hash"`
|
||||||
EventName string `gorm:"unique" json:"event_name" bson:"event_name" cql:"event_name" dynamo:"event_name" index:"event_name,hash"`
|
EventName string `gorm:"unique" json:"event_name" bson:"event_name" cql:"event_name" dynamo:"event_name" index:"event_name,hash"`
|
||||||
Title string `json:"title" bson:"title" cql:"title" dynamo:"title"`
|
EventDescription string `json:"event_description" bson:"event_description" cql:"event_description" dynamo:"event_description"`
|
||||||
EndPoint string `json:"endpoint" bson:"endpoint" cql:"endpoint" dynamo:"endpoint"`
|
EndPoint string `json:"endpoint" bson:"endpoint" cql:"endpoint" dynamo:"endpoint"`
|
||||||
Headers string `json:"headers" bson:"headers" cql:"headers" dynamo:"headers"`
|
Headers string `json:"headers" bson:"headers" cql:"headers" dynamo:"headers"`
|
||||||
Enabled bool `json:"enabled" bson:"enabled" cql:"enabled" dynamo:"enabled"`
|
Enabled bool `json:"enabled" bson:"enabled" cql:"enabled" dynamo:"enabled"`
|
||||||
CreatedAt int64 `json:"created_at" bson:"created_at" cql:"created_at" dynamo:"created_at"`
|
CreatedAt int64 `json:"created_at" bson:"created_at" cql:"created_at" dynamo:"created_at"`
|
||||||
UpdatedAt int64 `json:"updated_at" bson:"updated_at" cql:"updated_at" dynamo:"updated_at"`
|
UpdatedAt int64 `json:"updated_at" bson:"updated_at" cql:"updated_at" dynamo:"updated_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// AsAPIWebhook to return webhook as graphql response object
|
// AsAPIWebhook to return webhook as graphql response object
|
||||||
|
@ -40,12 +40,12 @@ func (w *Webhook) AsAPIWebhook() *model.Webhook {
|
||||||
w.EventName = splitData[0]
|
w.EventName = splitData[0]
|
||||||
}
|
}
|
||||||
// set default title to event name without dot(.)
|
// set default title to event name without dot(.)
|
||||||
if w.Title == "" {
|
if w.EventDescription == "" {
|
||||||
w.Title = strings.Join(strings.Split(w.EventName, "."), " ")
|
w.EventDescription = strings.Join(strings.Split(w.EventName, "."), " ")
|
||||||
}
|
}
|
||||||
return &model.Webhook{
|
return &model.Webhook{
|
||||||
ID: id,
|
ID: id,
|
||||||
Title: refs.NewStringRef(w.Title),
|
// Title: refs.NewStringRef(w.EventDescription),
|
||||||
EventName: refs.NewStringRef(w.EventName),
|
EventName: refs.NewStringRef(w.EventName),
|
||||||
Endpoint: refs.NewStringRef(w.EndPoint),
|
Endpoint: refs.NewStringRef(w.EndPoint),
|
||||||
Headers: headersMap,
|
Headers: headersMap,
|
||||||
|
|
|
@ -20,8 +20,8 @@ func (p *provider) AddWebhook(ctx context.Context, webhook models.Webhook) (*mod
|
||||||
webhook.Key = webhook.ID
|
webhook.Key = webhook.ID
|
||||||
}
|
}
|
||||||
webhook.Key = webhook.ID
|
webhook.Key = webhook.ID
|
||||||
if webhook.Title == "" {
|
if webhook.EventDescription == "" {
|
||||||
webhook.Title = strings.Join(strings.Split(webhook.EventName, "."), " ")
|
webhook.EventDescription = strings.Join(strings.Split(webhook.EventName, "."), " ")
|
||||||
}
|
}
|
||||||
// Add timestamp to make event name unique for legacy version
|
// Add timestamp to make event name unique for legacy version
|
||||||
webhook.EventName = fmt.Sprintf("%s-%d", webhook.EventName, time.Now().Unix())
|
webhook.EventName = fmt.Sprintf("%s-%d", webhook.EventName, time.Now().Unix())
|
||||||
|
|
|
@ -22,12 +22,12 @@ func (p *provider) AddWebhook(ctx context.Context, webhook models.Webhook) (*mod
|
||||||
webhook.Key = webhook.ID
|
webhook.Key = webhook.ID
|
||||||
webhook.CreatedAt = time.Now().Unix()
|
webhook.CreatedAt = time.Now().Unix()
|
||||||
webhook.UpdatedAt = time.Now().Unix()
|
webhook.UpdatedAt = time.Now().Unix()
|
||||||
if webhook.Title == "" {
|
if webhook.EventDescription == "" {
|
||||||
webhook.Title = strings.Join(strings.Split(webhook.EventName, "."), " ")
|
webhook.EventDescription = strings.Join(strings.Split(webhook.EventName, "."), " ")
|
||||||
}
|
}
|
||||||
// Add timestamp to make event name unique for legacy version
|
// Add timestamp to make event name unique for legacy version
|
||||||
webhook.EventName = fmt.Sprintf("%s-%d", webhook.EventName, time.Now().Unix())
|
webhook.EventName = fmt.Sprintf("%s-%d", webhook.EventName, time.Now().Unix())
|
||||||
insertQuery := fmt.Sprintf("INSERT INTO %s (id, title, event_name, endpoint, headers, enabled, created_at, updated_at) VALUES ('%s', '%s', '%s', '%s', '%s', %t, %d, %d)", KeySpace+"."+models.Collections.Webhook, webhook.ID, webhook.Title, webhook.EventName, webhook.EndPoint, webhook.Headers, webhook.Enabled, webhook.CreatedAt, webhook.UpdatedAt)
|
insertQuery := fmt.Sprintf("INSERT INTO %s (id, event_description, event_name, endpoint, headers, enabled, created_at, updated_at) VALUES ('%s', '%s', '%s', '%s', '%s', %t, %d, %d)", KeySpace+"."+models.Collections.Webhook, webhook.ID, webhook.EventDescription, webhook.EventName, webhook.EndPoint, webhook.Headers, webhook.Enabled, webhook.CreatedAt, webhook.UpdatedAt)
|
||||||
err := p.db.Query(insertQuery).Exec()
|
err := p.db.Query(insertQuery).Exec()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -95,13 +95,13 @@ func (p *provider) ListWebhook(ctx context.Context, pagination model.Pagination)
|
||||||
// there is no offset in cassandra
|
// there is no offset in cassandra
|
||||||
// so we fetch till limit + offset
|
// so we fetch till limit + offset
|
||||||
// and return the results from offset to limit
|
// and return the results from offset to limit
|
||||||
query := fmt.Sprintf("SELECT id, title, event_name, endpoint, headers, enabled, created_at, updated_at FROM %s LIMIT %d", KeySpace+"."+models.Collections.Webhook, pagination.Limit+pagination.Offset)
|
query := fmt.Sprintf("SELECT id, event_description, event_name, endpoint, headers, enabled, created_at, updated_at FROM %s LIMIT %d", KeySpace+"."+models.Collections.Webhook, pagination.Limit+pagination.Offset)
|
||||||
scanner := p.db.Query(query).Iter().Scanner()
|
scanner := p.db.Query(query).Iter().Scanner()
|
||||||
counter := int64(0)
|
counter := int64(0)
|
||||||
for scanner.Next() {
|
for scanner.Next() {
|
||||||
if counter >= pagination.Offset {
|
if counter >= pagination.Offset {
|
||||||
var webhook models.Webhook
|
var webhook models.Webhook
|
||||||
err := scanner.Scan(&webhook.ID, &webhook.Title, &webhook.EventName, &webhook.EndPoint, &webhook.Headers, &webhook.Enabled, &webhook.CreatedAt, &webhook.UpdatedAt)
|
err := scanner.Scan(&webhook.ID, &webhook.EventDescription, &webhook.EventName, &webhook.EndPoint, &webhook.Headers, &webhook.Enabled, &webhook.CreatedAt, &webhook.UpdatedAt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -119,8 +119,8 @@ func (p *provider) ListWebhook(ctx context.Context, pagination model.Pagination)
|
||||||
// GetWebhookByID to get webhook by id
|
// GetWebhookByID to get webhook by id
|
||||||
func (p *provider) GetWebhookByID(ctx context.Context, webhookID string) (*model.Webhook, error) {
|
func (p *provider) GetWebhookByID(ctx context.Context, webhookID string) (*model.Webhook, error) {
|
||||||
var webhook models.Webhook
|
var webhook models.Webhook
|
||||||
query := fmt.Sprintf(`SELECT id, title, event_name, endpoint, headers, enabled, created_at, updated_at FROM %s WHERE id = '%s' LIMIT 1`, KeySpace+"."+models.Collections.Webhook, webhookID)
|
query := fmt.Sprintf(`SELECT id, event_description, event_name, endpoint, headers, enabled, created_at, updated_at FROM %s WHERE id = '%s' LIMIT 1`, KeySpace+"."+models.Collections.Webhook, webhookID)
|
||||||
err := p.db.Query(query).Consistency(gocql.One).Scan(&webhook.ID, &webhook.Title, &webhook.EventName, &webhook.EndPoint, &webhook.Headers, &webhook.Enabled, &webhook.CreatedAt, &webhook.UpdatedAt)
|
err := p.db.Query(query).Consistency(gocql.One).Scan(&webhook.ID, &webhook.EventDescription, &webhook.EventName, &webhook.EndPoint, &webhook.Headers, &webhook.Enabled, &webhook.CreatedAt, &webhook.UpdatedAt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -129,12 +129,12 @@ func (p *provider) GetWebhookByID(ctx context.Context, webhookID string) (*model
|
||||||
|
|
||||||
// GetWebhookByEventName to get webhook by event_name
|
// GetWebhookByEventName to get webhook by event_name
|
||||||
func (p *provider) GetWebhookByEventName(ctx context.Context, eventName string) ([]*model.Webhook, error) {
|
func (p *provider) GetWebhookByEventName(ctx context.Context, eventName string) ([]*model.Webhook, error) {
|
||||||
query := fmt.Sprintf(`SELECT id, title, event_name, endpoint, headers, enabled, created_at, updated_at FROM %s WHERE event_name LIKE '%s' ALLOW FILTERING`, KeySpace+"."+models.Collections.Webhook, eventName+"%s")
|
query := fmt.Sprintf(`SELECT id, event_description, event_name, endpoint, headers, enabled, created_at, updated_at FROM %s WHERE event_name LIKE '%s' ALLOW FILTERING`, KeySpace+"."+models.Collections.Webhook, eventName+"%s")
|
||||||
scanner := p.db.Query(query).Iter().Scanner()
|
scanner := p.db.Query(query).Iter().Scanner()
|
||||||
webhooks := []*model.Webhook{}
|
webhooks := []*model.Webhook{}
|
||||||
for scanner.Next() {
|
for scanner.Next() {
|
||||||
var webhook models.Webhook
|
var webhook models.Webhook
|
||||||
err := scanner.Scan(&webhook.ID, &webhook.Title, &webhook.EventName, &webhook.EndPoint, &webhook.Headers, &webhook.Enabled, &webhook.CreatedAt, &webhook.UpdatedAt)
|
err := scanner.Scan(&webhook.ID, &webhook.EventDescription, &webhook.EventName, &webhook.EndPoint, &webhook.Headers, &webhook.Enabled, &webhook.CreatedAt, &webhook.UpdatedAt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,8 @@ func (p *provider) AddWebhook(ctx context.Context, webhook models.Webhook) (*mod
|
||||||
webhook.Key = webhook.ID
|
webhook.Key = webhook.ID
|
||||||
webhook.CreatedAt = time.Now().Unix()
|
webhook.CreatedAt = time.Now().Unix()
|
||||||
webhook.UpdatedAt = time.Now().Unix()
|
webhook.UpdatedAt = time.Now().Unix()
|
||||||
if webhook.Title == "" {
|
if webhook.EventDescription == "" {
|
||||||
webhook.Title = strings.Join(strings.Split(webhook.EventName, "."), " ")
|
webhook.EventDescription = strings.Join(strings.Split(webhook.EventName, "."), " ")
|
||||||
}
|
}
|
||||||
// Add timestamp to make event name unique for legacy version
|
// Add timestamp to make event name unique for legacy version
|
||||||
webhook.EventName = fmt.Sprintf("%s-%d", webhook.EventName, time.Now().Unix())
|
webhook.EventName = fmt.Sprintf("%s-%d", webhook.EventName, time.Now().Unix())
|
||||||
|
@ -82,7 +82,7 @@ func (p *provider) ListWebhook(ctx context.Context, pagination model.Pagination)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
paginationClone.Total = total
|
paginationClone.Total = total
|
||||||
query := fmt.Sprintf("SELECT _id, title, event_name, endpoint, headers, enabled, created_at, updated_at FROM %s.%s OFFSET $offset LIMIT $limit", p.scopeName, models.Collections.Webhook)
|
query := fmt.Sprintf("SELECT _id, event_description, event_name, endpoint, headers, enabled, created_at, updated_at FROM %s.%s OFFSET $offset LIMIT $limit", p.scopeName, models.Collections.Webhook)
|
||||||
queryResult, err := p.db.Query(query, &gocb.QueryOptions{
|
queryResult, err := p.db.Query(query, &gocb.QueryOptions{
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
ScanConsistency: gocb.QueryScanConsistencyRequestPlus,
|
ScanConsistency: gocb.QueryScanConsistencyRequestPlus,
|
||||||
|
@ -112,7 +112,7 @@ func (p *provider) GetWebhookByID(ctx context.Context, webhookID string) (*model
|
||||||
var webhook models.Webhook
|
var webhook models.Webhook
|
||||||
params := make(map[string]interface{}, 1)
|
params := make(map[string]interface{}, 1)
|
||||||
params["_id"] = webhookID
|
params["_id"] = webhookID
|
||||||
query := fmt.Sprintf(`SELECT _id, title, event_name, endpoint, headers, enabled, created_at, updated_at FROM %s.%s WHERE _id=$_id LIMIT 1`, p.scopeName, models.Collections.Webhook)
|
query := fmt.Sprintf(`SELECT _id, event_description, event_name, endpoint, headers, enabled, created_at, updated_at FROM %s.%s WHERE _id=$_id LIMIT 1`, p.scopeName, models.Collections.Webhook)
|
||||||
q, err := p.db.Query(query, &gocb.QueryOptions{
|
q, err := p.db.Query(query, &gocb.QueryOptions{
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
ScanConsistency: gocb.QueryScanConsistencyRequestPlus,
|
ScanConsistency: gocb.QueryScanConsistencyRequestPlus,
|
||||||
|
@ -132,7 +132,7 @@ func (p *provider) GetWebhookByID(ctx context.Context, webhookID string) (*model
|
||||||
func (p *provider) GetWebhookByEventName(ctx context.Context, eventName string) ([]*model.Webhook, error) {
|
func (p *provider) GetWebhookByEventName(ctx context.Context, eventName string) ([]*model.Webhook, error) {
|
||||||
params := make(map[string]interface{}, 1)
|
params := make(map[string]interface{}, 1)
|
||||||
params["event_name"] = eventName + "%"
|
params["event_name"] = eventName + "%"
|
||||||
query := fmt.Sprintf(`SELECT _id, title, event_name, endpoint, headers, enabled, created_at, updated_at FROM %s.%s WHERE event_name LIKE $event_name`, p.scopeName, models.Collections.Webhook)
|
query := fmt.Sprintf(`SELECT _id, event_description, event_name, endpoint, headers, enabled, created_at, updated_at FROM %s.%s WHERE event_name LIKE $event_name`, p.scopeName, models.Collections.Webhook)
|
||||||
queryResult, err := p.db.Query(query, &gocb.QueryOptions{
|
queryResult, err := p.db.Query(query, &gocb.QueryOptions{
|
||||||
Context: ctx,
|
Context: ctx,
|
||||||
ScanConsistency: gocb.QueryScanConsistencyRequestPlus,
|
ScanConsistency: gocb.QueryScanConsistencyRequestPlus,
|
||||||
|
|
|
@ -23,8 +23,8 @@ func (p *provider) AddWebhook(ctx context.Context, webhook models.Webhook) (*mod
|
||||||
webhook.Key = webhook.ID
|
webhook.Key = webhook.ID
|
||||||
webhook.CreatedAt = time.Now().Unix()
|
webhook.CreatedAt = time.Now().Unix()
|
||||||
webhook.UpdatedAt = time.Now().Unix()
|
webhook.UpdatedAt = time.Now().Unix()
|
||||||
if webhook.Title == "" {
|
if webhook.EventDescription == "" {
|
||||||
webhook.Title = strings.Join(strings.Split(webhook.EventName, "."), " ")
|
webhook.EventDescription = strings.Join(strings.Split(webhook.EventName, "."), " ")
|
||||||
}
|
}
|
||||||
// Add timestamp to make event name unique for legacy version
|
// Add timestamp to make event name unique for legacy version
|
||||||
webhook.EventName = fmt.Sprintf("%s-%d", webhook.EventName, time.Now().Unix())
|
webhook.EventName = fmt.Sprintf("%s-%d", webhook.EventName, time.Now().Unix())
|
||||||
|
|
|
@ -21,8 +21,8 @@ func (p *provider) AddWebhook(ctx context.Context, webhook models.Webhook) (*mod
|
||||||
webhook.Key = webhook.ID
|
webhook.Key = webhook.ID
|
||||||
webhook.CreatedAt = time.Now().Unix()
|
webhook.CreatedAt = time.Now().Unix()
|
||||||
webhook.UpdatedAt = time.Now().Unix()
|
webhook.UpdatedAt = time.Now().Unix()
|
||||||
if webhook.Title == "" {
|
if webhook.EventDescription == "" {
|
||||||
webhook.Title = strings.Join(strings.Split(webhook.EventName, "."), " ")
|
webhook.EventDescription = strings.Join(strings.Split(webhook.EventName, "."), " ")
|
||||||
}
|
}
|
||||||
// Add timestamp to make event name unique for legacy version
|
// Add timestamp to make event name unique for legacy version
|
||||||
webhook.EventName = fmt.Sprintf("%s-%d", webhook.EventName, time.Now().Unix())
|
webhook.EventName = fmt.Sprintf("%s-%d", webhook.EventName, time.Now().Unix())
|
||||||
|
|
|
@ -19,8 +19,8 @@ func (p *provider) AddWebhook(ctx context.Context, webhook models.Webhook) (*mod
|
||||||
webhook.Key = webhook.ID
|
webhook.Key = webhook.ID
|
||||||
webhook.CreatedAt = time.Now().Unix()
|
webhook.CreatedAt = time.Now().Unix()
|
||||||
webhook.UpdatedAt = time.Now().Unix()
|
webhook.UpdatedAt = time.Now().Unix()
|
||||||
if webhook.Title == "" {
|
if webhook.EventDescription == "" {
|
||||||
webhook.Title = strings.Join(strings.Split(webhook.EventName, "."), " ")
|
webhook.EventDescription = strings.Join(strings.Split(webhook.EventName, "."), " ")
|
||||||
}
|
}
|
||||||
// Add timestamp to make event name unique for legacy version
|
// Add timestamp to make event name unique for legacy version
|
||||||
webhook.EventName = fmt.Sprintf("%s-%d", webhook.EventName, time.Now().Unix())
|
webhook.EventName = fmt.Sprintf("%s-%d", webhook.EventName, time.Now().Unix())
|
||||||
|
|
|
@ -19,8 +19,8 @@ func (p *provider) AddWebhook(ctx context.Context, webhook models.Webhook) (*mod
|
||||||
webhook.Key = webhook.ID
|
webhook.Key = webhook.ID
|
||||||
webhook.CreatedAt = time.Now().Unix()
|
webhook.CreatedAt = time.Now().Unix()
|
||||||
webhook.UpdatedAt = time.Now().Unix()
|
webhook.UpdatedAt = time.Now().Unix()
|
||||||
if webhook.Title == "" {
|
if webhook.EventDescription == "" {
|
||||||
webhook.Title = strings.Join(strings.Split(webhook.EventName, "."), " ")
|
webhook.EventDescription = strings.Join(strings.Split(webhook.EventName, "."), " ")
|
||||||
}
|
}
|
||||||
// Add timestamp to make event name unique for legacy version
|
// Add timestamp to make event name unique for legacy version
|
||||||
webhook.EventName = fmt.Sprintf("%s-%d", webhook.EventName, time.Now().Unix())
|
webhook.EventName = fmt.Sprintf("%s-%d", webhook.EventName, time.Now().Unix())
|
||||||
|
|
|
@ -275,14 +275,14 @@ type ComplexityRoot struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
Webhook struct {
|
Webhook struct {
|
||||||
CreatedAt func(childComplexity int) int
|
CreatedAt func(childComplexity int) int
|
||||||
Enabled func(childComplexity int) int
|
Enabled func(childComplexity int) int
|
||||||
Endpoint func(childComplexity int) int
|
Endpoint func(childComplexity int) int
|
||||||
EventName func(childComplexity int) int
|
EventDescription func(childComplexity int) int
|
||||||
Headers func(childComplexity int) int
|
EventName func(childComplexity int) int
|
||||||
ID func(childComplexity int) int
|
Headers func(childComplexity int) int
|
||||||
Title func(childComplexity int) int
|
ID func(childComplexity int) int
|
||||||
UpdatedAt func(childComplexity int) int
|
UpdatedAt func(childComplexity int) int
|
||||||
}
|
}
|
||||||
|
|
||||||
WebhookLog struct {
|
WebhookLog struct {
|
||||||
|
@ -1834,6 +1834,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
|
||||||
|
|
||||||
return e.complexity.Webhook.Endpoint(childComplexity), true
|
return e.complexity.Webhook.Endpoint(childComplexity), true
|
||||||
|
|
||||||
|
case "Webhook.event_description":
|
||||||
|
if e.complexity.Webhook.EventDescription == nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
return e.complexity.Webhook.EventDescription(childComplexity), true
|
||||||
|
|
||||||
case "Webhook.event_name":
|
case "Webhook.event_name":
|
||||||
if e.complexity.Webhook.EventName == nil {
|
if e.complexity.Webhook.EventName == nil {
|
||||||
break
|
break
|
||||||
|
@ -1855,13 +1862,6 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in
|
||||||
|
|
||||||
return e.complexity.Webhook.ID(childComplexity), true
|
return e.complexity.Webhook.ID(childComplexity), true
|
||||||
|
|
||||||
case "Webhook.title":
|
|
||||||
if e.complexity.Webhook.Title == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
return e.complexity.Webhook.Title(childComplexity), true
|
|
||||||
|
|
||||||
case "Webhook.updated_at":
|
case "Webhook.updated_at":
|
||||||
if e.complexity.Webhook.UpdatedAt == nil {
|
if e.complexity.Webhook.UpdatedAt == nil {
|
||||||
break
|
break
|
||||||
|
@ -2218,8 +2218,8 @@ type GenerateJWTKeysResponse {
|
||||||
|
|
||||||
type Webhook {
|
type Webhook {
|
||||||
id: ID!
|
id: ID!
|
||||||
title: String
|
|
||||||
event_name: String
|
event_name: String
|
||||||
|
event_description: String
|
||||||
endpoint: String
|
endpoint: String
|
||||||
enabled: Boolean
|
enabled: Boolean
|
||||||
headers: Map
|
headers: Map
|
||||||
|
@ -2509,8 +2509,8 @@ input ListWebhookLogRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
input AddWebhookRequest {
|
input AddWebhookRequest {
|
||||||
title: String!
|
|
||||||
event_name: String!
|
event_name: String!
|
||||||
|
event_description: String
|
||||||
endpoint: String!
|
endpoint: String!
|
||||||
enabled: Boolean!
|
enabled: Boolean!
|
||||||
headers: Map
|
headers: Map
|
||||||
|
@ -2518,8 +2518,8 @@ input AddWebhookRequest {
|
||||||
|
|
||||||
input UpdateWebhookRequest {
|
input UpdateWebhookRequest {
|
||||||
id: ID!
|
id: ID!
|
||||||
title: String
|
|
||||||
event_name: String
|
event_name: String
|
||||||
|
event_description: String
|
||||||
endpoint: String
|
endpoint: String
|
||||||
enabled: Boolean
|
enabled: Boolean
|
||||||
headers: Map
|
headers: Map
|
||||||
|
@ -10152,10 +10152,10 @@ func (ec *executionContext) fieldContext_Query__webhook(ctx context.Context, fie
|
||||||
switch field.Name {
|
switch field.Name {
|
||||||
case "id":
|
case "id":
|
||||||
return ec.fieldContext_Webhook_id(ctx, field)
|
return ec.fieldContext_Webhook_id(ctx, field)
|
||||||
case "title":
|
|
||||||
return ec.fieldContext_Webhook_title(ctx, field)
|
|
||||||
case "event_name":
|
case "event_name":
|
||||||
return ec.fieldContext_Webhook_event_name(ctx, field)
|
return ec.fieldContext_Webhook_event_name(ctx, field)
|
||||||
|
case "event_description":
|
||||||
|
return ec.fieldContext_Webhook_event_description(ctx, field)
|
||||||
case "endpoint":
|
case "endpoint":
|
||||||
return ec.fieldContext_Webhook_endpoint(ctx, field)
|
return ec.fieldContext_Webhook_endpoint(ctx, field)
|
||||||
case "enabled":
|
case "enabled":
|
||||||
|
@ -12173,47 +12173,6 @@ func (ec *executionContext) fieldContext_Webhook_id(ctx context.Context, field g
|
||||||
return fc, nil
|
return fc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ec *executionContext) _Webhook_title(ctx context.Context, field graphql.CollectedField, obj *model.Webhook) (ret graphql.Marshaler) {
|
|
||||||
fc, err := ec.fieldContext_Webhook_title(ctx, field)
|
|
||||||
if err != nil {
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
ctx = graphql.WithFieldContext(ctx, fc)
|
|
||||||
defer func() {
|
|
||||||
if r := recover(); r != nil {
|
|
||||||
ec.Error(ctx, ec.Recover(ctx, r))
|
|
||||||
ret = graphql.Null
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
|
||||||
ctx = rctx // use context from middleware stack in children
|
|
||||||
return obj.Title, nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
ec.Error(ctx, err)
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
if resTmp == nil {
|
|
||||||
return graphql.Null
|
|
||||||
}
|
|
||||||
res := resTmp.(*string)
|
|
||||||
fc.Result = res
|
|
||||||
return ec.marshalOString2ᚖstring(ctx, field.Selections, res)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ec *executionContext) fieldContext_Webhook_title(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
|
|
||||||
fc = &graphql.FieldContext{
|
|
||||||
Object: "Webhook",
|
|
||||||
Field: field,
|
|
||||||
IsMethod: false,
|
|
||||||
IsResolver: false,
|
|
||||||
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
|
|
||||||
return nil, errors.New("field of type String does not have child fields")
|
|
||||||
},
|
|
||||||
}
|
|
||||||
return fc, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (ec *executionContext) _Webhook_event_name(ctx context.Context, field graphql.CollectedField, obj *model.Webhook) (ret graphql.Marshaler) {
|
func (ec *executionContext) _Webhook_event_name(ctx context.Context, field graphql.CollectedField, obj *model.Webhook) (ret graphql.Marshaler) {
|
||||||
fc, err := ec.fieldContext_Webhook_event_name(ctx, field)
|
fc, err := ec.fieldContext_Webhook_event_name(ctx, field)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -12255,6 +12214,47 @@ func (ec *executionContext) fieldContext_Webhook_event_name(ctx context.Context,
|
||||||
return fc, nil
|
return fc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ec *executionContext) _Webhook_event_description(ctx context.Context, field graphql.CollectedField, obj *model.Webhook) (ret graphql.Marshaler) {
|
||||||
|
fc, err := ec.fieldContext_Webhook_event_description(ctx, field)
|
||||||
|
if err != nil {
|
||||||
|
return graphql.Null
|
||||||
|
}
|
||||||
|
ctx = graphql.WithFieldContext(ctx, fc)
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
ec.Error(ctx, ec.Recover(ctx, r))
|
||||||
|
ret = graphql.Null
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) {
|
||||||
|
ctx = rctx // use context from middleware stack in children
|
||||||
|
return obj.EventDescription, nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
ec.Error(ctx, err)
|
||||||
|
return graphql.Null
|
||||||
|
}
|
||||||
|
if resTmp == nil {
|
||||||
|
return graphql.Null
|
||||||
|
}
|
||||||
|
res := resTmp.(*string)
|
||||||
|
fc.Result = res
|
||||||
|
return ec.marshalOString2ᚖstring(ctx, field.Selections, res)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ec *executionContext) fieldContext_Webhook_event_description(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) {
|
||||||
|
fc = &graphql.FieldContext{
|
||||||
|
Object: "Webhook",
|
||||||
|
Field: field,
|
||||||
|
IsMethod: false,
|
||||||
|
IsResolver: false,
|
||||||
|
Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) {
|
||||||
|
return nil, errors.New("field of type String does not have child fields")
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return fc, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (ec *executionContext) _Webhook_endpoint(ctx context.Context, field graphql.CollectedField, obj *model.Webhook) (ret graphql.Marshaler) {
|
func (ec *executionContext) _Webhook_endpoint(ctx context.Context, field graphql.CollectedField, obj *model.Webhook) (ret graphql.Marshaler) {
|
||||||
fc, err := ec.fieldContext_Webhook_endpoint(ctx, field)
|
fc, err := ec.fieldContext_Webhook_endpoint(ctx, field)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -12959,10 +12959,10 @@ func (ec *executionContext) fieldContext_Webhooks_webhooks(ctx context.Context,
|
||||||
switch field.Name {
|
switch field.Name {
|
||||||
case "id":
|
case "id":
|
||||||
return ec.fieldContext_Webhook_id(ctx, field)
|
return ec.fieldContext_Webhook_id(ctx, field)
|
||||||
case "title":
|
|
||||||
return ec.fieldContext_Webhook_title(ctx, field)
|
|
||||||
case "event_name":
|
case "event_name":
|
||||||
return ec.fieldContext_Webhook_event_name(ctx, field)
|
return ec.fieldContext_Webhook_event_name(ctx, field)
|
||||||
|
case "event_description":
|
||||||
|
return ec.fieldContext_Webhook_event_description(ctx, field)
|
||||||
case "endpoint":
|
case "endpoint":
|
||||||
return ec.fieldContext_Webhook_endpoint(ctx, field)
|
return ec.fieldContext_Webhook_endpoint(ctx, field)
|
||||||
case "enabled":
|
case "enabled":
|
||||||
|
@ -14812,21 +14812,13 @@ func (ec *executionContext) unmarshalInputAddWebhookRequest(ctx context.Context,
|
||||||
asMap[k] = v
|
asMap[k] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
fieldsInOrder := [...]string{"title", "event_name", "endpoint", "enabled", "headers"}
|
fieldsInOrder := [...]string{"event_name", "event_description", "endpoint", "enabled", "headers"}
|
||||||
for _, k := range fieldsInOrder {
|
for _, k := range fieldsInOrder {
|
||||||
v, ok := asMap[k]
|
v, ok := asMap[k]
|
||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
switch k {
|
switch k {
|
||||||
case "title":
|
|
||||||
var err error
|
|
||||||
|
|
||||||
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("title"))
|
|
||||||
it.Title, err = ec.unmarshalNString2string(ctx, v)
|
|
||||||
if err != nil {
|
|
||||||
return it, err
|
|
||||||
}
|
|
||||||
case "event_name":
|
case "event_name":
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
@ -14835,6 +14827,14 @@ func (ec *executionContext) unmarshalInputAddWebhookRequest(ctx context.Context,
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return it, err
|
return it, err
|
||||||
}
|
}
|
||||||
|
case "event_description":
|
||||||
|
var err error
|
||||||
|
|
||||||
|
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("event_description"))
|
||||||
|
it.EventDescription, err = ec.unmarshalOString2ᚖstring(ctx, v)
|
||||||
|
if err != nil {
|
||||||
|
return it, err
|
||||||
|
}
|
||||||
case "endpoint":
|
case "endpoint":
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
@ -16676,7 +16676,7 @@ func (ec *executionContext) unmarshalInputUpdateWebhookRequest(ctx context.Conte
|
||||||
asMap[k] = v
|
asMap[k] = v
|
||||||
}
|
}
|
||||||
|
|
||||||
fieldsInOrder := [...]string{"id", "title", "event_name", "endpoint", "enabled", "headers"}
|
fieldsInOrder := [...]string{"id", "event_name", "event_description", "endpoint", "enabled", "headers"}
|
||||||
for _, k := range fieldsInOrder {
|
for _, k := range fieldsInOrder {
|
||||||
v, ok := asMap[k]
|
v, ok := asMap[k]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -16691,14 +16691,6 @@ func (ec *executionContext) unmarshalInputUpdateWebhookRequest(ctx context.Conte
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return it, err
|
return it, err
|
||||||
}
|
}
|
||||||
case "title":
|
|
||||||
var err error
|
|
||||||
|
|
||||||
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("title"))
|
|
||||||
it.Title, err = ec.unmarshalOString2ᚖstring(ctx, v)
|
|
||||||
if err != nil {
|
|
||||||
return it, err
|
|
||||||
}
|
|
||||||
case "event_name":
|
case "event_name":
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
@ -16707,6 +16699,14 @@ func (ec *executionContext) unmarshalInputUpdateWebhookRequest(ctx context.Conte
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return it, err
|
return it, err
|
||||||
}
|
}
|
||||||
|
case "event_description":
|
||||||
|
var err error
|
||||||
|
|
||||||
|
ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("event_description"))
|
||||||
|
it.EventDescription, err = ec.unmarshalOString2ᚖstring(ctx, v)
|
||||||
|
if err != nil {
|
||||||
|
return it, err
|
||||||
|
}
|
||||||
case "endpoint":
|
case "endpoint":
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
@ -18581,14 +18581,14 @@ func (ec *executionContext) _Webhook(ctx context.Context, sel ast.SelectionSet,
|
||||||
if out.Values[i] == graphql.Null {
|
if out.Values[i] == graphql.Null {
|
||||||
invalids++
|
invalids++
|
||||||
}
|
}
|
||||||
case "title":
|
|
||||||
|
|
||||||
out.Values[i] = ec._Webhook_title(ctx, field, obj)
|
|
||||||
|
|
||||||
case "event_name":
|
case "event_name":
|
||||||
|
|
||||||
out.Values[i] = ec._Webhook_event_name(ctx, field, obj)
|
out.Values[i] = ec._Webhook_event_name(ctx, field, obj)
|
||||||
|
|
||||||
|
case "event_description":
|
||||||
|
|
||||||
|
out.Values[i] = ec._Webhook_event_description(ctx, field, obj)
|
||||||
|
|
||||||
case "endpoint":
|
case "endpoint":
|
||||||
|
|
||||||
out.Values[i] = ec._Webhook_endpoint(ctx, field, obj)
|
out.Values[i] = ec._Webhook_endpoint(ctx, field, obj)
|
||||||
|
|
|
@ -10,11 +10,11 @@ type AddEmailTemplateRequest struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type AddWebhookRequest struct {
|
type AddWebhookRequest struct {
|
||||||
Title string `json:"title"`
|
EventName string `json:"event_name"`
|
||||||
EventName string `json:"event_name"`
|
EventDescription *string `json:"event_description"`
|
||||||
Endpoint string `json:"endpoint"`
|
Endpoint string `json:"endpoint"`
|
||||||
Enabled bool `json:"enabled"`
|
Enabled bool `json:"enabled"`
|
||||||
Headers map[string]interface{} `json:"headers"`
|
Headers map[string]interface{} `json:"headers"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AdminLoginInput struct {
|
type AdminLoginInput struct {
|
||||||
|
@ -388,12 +388,12 @@ type UpdateUserInput struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdateWebhookRequest struct {
|
type UpdateWebhookRequest struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Title *string `json:"title"`
|
EventName *string `json:"event_name"`
|
||||||
EventName *string `json:"event_name"`
|
EventDescription *string `json:"event_description"`
|
||||||
Endpoint *string `json:"endpoint"`
|
Endpoint *string `json:"endpoint"`
|
||||||
Enabled *bool `json:"enabled"`
|
Enabled *bool `json:"enabled"`
|
||||||
Headers map[string]interface{} `json:"headers"`
|
Headers map[string]interface{} `json:"headers"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
|
@ -463,14 +463,14 @@ type VerifyOTPRequest struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Webhook struct {
|
type Webhook struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Title *string `json:"title"`
|
EventName *string `json:"event_name"`
|
||||||
EventName *string `json:"event_name"`
|
EventDescription *string `json:"event_description"`
|
||||||
Endpoint *string `json:"endpoint"`
|
Endpoint *string `json:"endpoint"`
|
||||||
Enabled *bool `json:"enabled"`
|
Enabled *bool `json:"enabled"`
|
||||||
Headers map[string]interface{} `json:"headers"`
|
Headers map[string]interface{} `json:"headers"`
|
||||||
CreatedAt *int64 `json:"created_at"`
|
CreatedAt *int64 `json:"created_at"`
|
||||||
UpdatedAt *int64 `json:"updated_at"`
|
UpdatedAt *int64 `json:"updated_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type WebhookLog struct {
|
type WebhookLog struct {
|
||||||
|
|
|
@ -168,8 +168,8 @@ type GenerateJWTKeysResponse {
|
||||||
|
|
||||||
type Webhook {
|
type Webhook {
|
||||||
id: ID!
|
id: ID!
|
||||||
title: String
|
|
||||||
event_name: String
|
event_name: String
|
||||||
|
event_description: String
|
||||||
endpoint: String
|
endpoint: String
|
||||||
enabled: Boolean
|
enabled: Boolean
|
||||||
headers: Map
|
headers: Map
|
||||||
|
@ -459,8 +459,8 @@ input ListWebhookLogRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
input AddWebhookRequest {
|
input AddWebhookRequest {
|
||||||
title: String!
|
|
||||||
event_name: String!
|
event_name: String!
|
||||||
|
event_description: String
|
||||||
endpoint: String!
|
endpoint: String!
|
||||||
enabled: Boolean!
|
enabled: Boolean!
|
||||||
headers: Map
|
headers: Map
|
||||||
|
@ -468,8 +468,8 @@ input AddWebhookRequest {
|
||||||
|
|
||||||
input UpdateWebhookRequest {
|
input UpdateWebhookRequest {
|
||||||
id: ID!
|
id: ID!
|
||||||
title: String
|
|
||||||
event_name: String
|
event_name: String
|
||||||
|
event_description: String
|
||||||
endpoint: String
|
endpoint: String
|
||||||
enabled: Boolean
|
enabled: Boolean
|
||||||
headers: Map
|
headers: Map
|
||||||
|
|
|
@ -2,7 +2,7 @@ package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/99designs/gqlgen/graphql/handler"
|
"github.com/99designs/gqlgen/graphql/handler"
|
||||||
graph "github.com/authorizerdev/authorizer/server/graph"
|
"github.com/authorizerdev/authorizer/server/graph"
|
||||||
"github.com/authorizerdev/authorizer/server/graph/generated"
|
"github.com/authorizerdev/authorizer/server/graph/generated"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"github.com/authorizerdev/authorizer/server/db"
|
"github.com/authorizerdev/authorizer/server/db"
|
||||||
"github.com/authorizerdev/authorizer/server/db/models"
|
"github.com/authorizerdev/authorizer/server/db/models"
|
||||||
"github.com/authorizerdev/authorizer/server/graph/model"
|
"github.com/authorizerdev/authorizer/server/graph/model"
|
||||||
|
"github.com/authorizerdev/authorizer/server/refs"
|
||||||
"github.com/authorizerdev/authorizer/server/token"
|
"github.com/authorizerdev/authorizer/server/token"
|
||||||
"github.com/authorizerdev/authorizer/server/utils"
|
"github.com/authorizerdev/authorizer/server/utils"
|
||||||
"github.com/authorizerdev/authorizer/server/validators"
|
"github.com/authorizerdev/authorizer/server/validators"
|
||||||
|
@ -44,10 +45,11 @@ func AddWebhookResolver(ctx context.Context, params model.AddWebhookRequest) (*m
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = db.Provider.AddWebhook(ctx, models.Webhook{
|
_, err = db.Provider.AddWebhook(ctx, models.Webhook{
|
||||||
EventName: params.EventName,
|
EventDescription: refs.StringValue(params.EventDescription),
|
||||||
EndPoint: params.Endpoint,
|
EventName: params.EventName,
|
||||||
Enabled: params.Enabled,
|
EndPoint: params.Endpoint,
|
||||||
Headers: string(headerBytes),
|
Enabled: params.Enabled,
|
||||||
|
Headers: string(headerBytes),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("Failed to add webhook: ", err)
|
log.Debug("Failed to add webhook: ", err)
|
||||||
|
|
|
@ -19,6 +19,7 @@ import (
|
||||||
func RegisterEvent(ctx context.Context, eventName string, authRecipe string, user models.User) error {
|
func RegisterEvent(ctx context.Context, eventName string, authRecipe string, user models.User) error {
|
||||||
webhooks, err := db.Provider.GetWebhookByEventName(ctx, eventName)
|
webhooks, err := db.Provider.GetWebhookByEventName(ctx, eventName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Debug("Error getting webhook: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
for _, webhook := range webhooks {
|
for _, webhook := range webhooks {
|
||||||
|
@ -38,6 +39,7 @@ func RegisterEvent(ctx context.Context, eventName string, authRecipe string, use
|
||||||
}
|
}
|
||||||
|
|
||||||
reqBody := map[string]interface{}{
|
reqBody := map[string]interface{}{
|
||||||
|
"webhook_id": webhook.ID,
|
||||||
"event_name": eventName,
|
"event_name": eventName,
|
||||||
"user": userMap,
|
"user": userMap,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user