MCPcopy Create free account
hub / github.com/authorizerdev/authorizer / UpdateWebhook

Method UpdateWebhook

internal/storage/db/couchbase/webhook.go:39–70  ·  view source on GitHub ↗

UpdateWebhook to update webhook

(ctx context.Context, webhook *schemas.Webhook)

Source from the content-addressed store, hash-verified

37
38// UpdateWebhook to update webhook
39func (p *provider) UpdateWebhook(ctx context.Context, webhook *schemas.Webhook) (*schemas.Webhook, error) {
40 webhook.UpdatedAt = time.Now().Unix()
41 // Event is changed
42 if !strings.Contains(webhook.EventName, "-") {
43 webhook.EventName = fmt.Sprintf("%s-%d", webhook.EventName, time.Now().Unix())
44 }
45 bytes, err := json.Marshal(webhook)
46 if err != nil {
47 return nil, err
48 }
49 // use decoder instead of json.Unmarshall, because it converts int64 -> float64 after unmarshalling
50 decoder := json.NewDecoder(strings.NewReader(string(bytes)))
51 decoder.UseNumber()
52 webhookMap := map[string]interface{}{}
53 err = decoder.Decode(&webhookMap)
54 if err != nil {
55 return nil, err
56 }
57 updateFields, params := GetSetFields(webhookMap)
58 params["_id"] = webhook.ID
59 query := fmt.Sprintf(`UPDATE %s.%s SET %s WHERE _id=$_id`, p.scopeName, schemas.Collections.Webhook, updateFields)
60 _, err = p.db.Query(query, &gocb.QueryOptions{
61 Context: ctx,
62 ScanConsistency: gocb.QueryScanConsistencyRequestPlus,
63 NamedParameters: params,
64 })
65 if err != nil {
66 return nil, err
67 }
68
69 return webhook, nil
70}
71
72// ListWebhooks to list webhook
73func (p *provider) ListWebhook(ctx context.Context, pagination *model.Pagination) ([]*schemas.Webhook, *model.Pagination, error) {

Callers

nothing calls this directly

Calls 2

GetSetFieldsFunction · 0.85
QueryMethod · 0.65

Tested by

no test coverage detected