Update an entities.Webhook
(ctx context.Context, params *WebhookUpdateParams)
| 155 | |
| 156 | // Update an entities.Webhook |
| 157 | func (service *WebhookService) Update(ctx context.Context, params *WebhookUpdateParams) (*entities.Webhook, error) { |
| 158 | ctx, span, ctxLogger := service.tracer.StartWithLogger(ctx, service.logger) |
| 159 | defer span.End() |
| 160 | |
| 161 | webhook, err := service.repository.Load(ctx, params.UserID, params.WebhookID) |
| 162 | if err != nil { |
| 163 | msg := fmt.Sprintf("cannot load webhook with userID [%s] and phoneID [%s]", params.UserID, params.WebhookID) |
| 164 | return nil, service.tracer.WrapErrorSpan(span, stacktrace.PropagateWithCode(err, stacktrace.GetCode(err), msg)) |
| 165 | } |
| 166 | |
| 167 | webhook.URL = params.URL |
| 168 | webhook.SigningKey = params.SigningKey |
| 169 | webhook.Events = params.Events |
| 170 | webhook.PhoneNumbers = params.PhoneNumbers |
| 171 | |
| 172 | if err = service.repository.Save(ctx, webhook); err != nil { |
| 173 | msg := fmt.Sprintf("cannot save webhook with id [%s] after update", webhook.ID) |
| 174 | return nil, service.tracer.WrapErrorSpan(span, stacktrace.Propagate(err, msg)) |
| 175 | } |
| 176 | |
| 177 | ctxLogger.Info(fmt.Sprintf("webhook updated with id [%s] in the [%T]", webhook.ID, service.repository)) |
| 178 | return webhook, nil |
| 179 | } |
| 180 | |
| 181 | // Send an event to a subscribed webhook |
| 182 | func (service *WebhookService) Send(ctx context.Context, userID entities.UserID, event cloudevents.Event, phoneNumber string) error { |
nothing calls this directly
no test coverage detected