generated from mrz1836/go-template
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(SPV-848): notifiactions & webhook notifier * feat(SVP-848): notifications manager * feat(SPV-848): notifications unit tests * feat(SPV-848): package notification moved to engine * feat(SPV-848): webhook_notifier tests * feat(SPV-848): webhook manager tests * feat(SPV-848): fix some tests * feat(SPV-848): call with token & test for ban fcn * feat(SPV-848): webhook subscribtion * feat(SPV-848): fix deadlock * feat(SPV-848): update webhook info * feat(SPV-848): blocking select instead of with-default Sleep * feat(SPV-848): unsubscribe * feat(SPV-848): event type * feat(SPV-848): event names by reflect::Name * feat(SPV-848): tidy things * fix(SPV-848): fix linter errors * feat(SPV-848): fix lint errors and a unit test; and a swagger comments * feat(SPV-848): regenerate swagger * feat(SPV-848): fix nil ptr exception * feat(SPV-848): fix minor unit tests * feat(SPV-848): adjust to self-review * feat(SPV-848): events defined in models package * feat(SPV-848): wrong log placement * feat(SPV-848): adjust to new ExtendedError approach * feat(SPV-848): adjust to review * feat(SVP-848): typo * feat(SPV-848): update swagger * feat(SPV-848): reimplement webhook model-repository logic * feat(SPV-848): webhooks errors and minor changes * feat(SPV-848): lint errors * feat(SPV-848): update swagger * feat(SPV-848): one empty file removed * feat(SPV-848): adjust to minor comments * feat(SPV-848): BanUntil * feat(SPV-848): remove mocked notifications
- Loading branch information
1 parent
ac3ad4e
commit 9814cfb
Showing
38 changed files
with
1,819 additions
and
475 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package admin | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/bitcoin-sv/spv-wallet/engine/spverrors" | ||
"github.com/bitcoin-sv/spv-wallet/models" | ||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
// subscribeWebhook will subscribe to a webhook to receive notifications | ||
// @Summary Subscribe to a webhook | ||
// @Description Subscribe to a webhook to receive notifications | ||
// @Tags Admin | ||
// @Produce json | ||
// @Param SubscribeRequestBody body models.SubscribeRequestBody false "URL to subscribe to and optional token header and value" | ||
// @Success 200 {boolean} bool "Success response" | ||
// @Failure 500 "Internal server error - Error while subscribing to the webhook" | ||
// @Router /v1/admin/webhooks/subscriptions [post] | ||
// @Security x-auth-xpub | ||
func (a *Action) subscribeWebhook(c *gin.Context) { | ||
requestBody := models.SubscribeRequestBody{} | ||
if err := c.Bind(&requestBody); err != nil { | ||
c.JSON(http.StatusBadRequest, err.Error()) | ||
return | ||
} | ||
|
||
err := a.Services.SpvWalletEngine.SubscribeWebhook(c.Request.Context(), requestBody.URL, requestBody.TokenHeader, requestBody.TokenValue) | ||
if err != nil { | ||
spverrors.ErrorResponse(c, err, a.Services.Logger) | ||
return | ||
} | ||
|
||
c.JSON(http.StatusOK, true) | ||
} | ||
|
||
// unsubscribeWebhook will unsubscribe to a webhook to receive notifications | ||
// @Summary Unsubscribe to a webhook | ||
// @Description Unsubscribe to a webhook to stop receiving notifications | ||
// @Tags Admin | ||
// @Produce json | ||
// @Param UnsubscribeRequestBody body models.UnsubscribeRequestBody false "URL to unsubscribe from" | ||
// @Success 200 {boolean} bool "Success response" | ||
// @Failure 500 "Internal server error - Error while unsubscribing to the webhook" | ||
// @Router /v1/admin/webhooks/subscriptions [delete] | ||
// @Security x-auth-xpub | ||
func (a *Action) unsubscribeWebhook(c *gin.Context) { | ||
requestModel := models.UnsubscribeRequestBody{} | ||
if err := c.Bind(&requestModel); err != nil { | ||
c.JSON(http.StatusBadRequest, err.Error()) | ||
return | ||
} | ||
|
||
err := a.Services.SpvWalletEngine.UnsubscribeWebhook(c.Request.Context(), requestModel.URL) | ||
if err != nil { | ||
spverrors.ErrorResponse(c, err, a.Services.Logger) | ||
return | ||
} | ||
|
||
c.JSON(http.StatusOK, true) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.