-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add test notification endpoint
- Loading branch information
1 parent
1b5e967
commit eb22ae2
Showing
2 changed files
with
44 additions
and
0 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,41 @@ | ||
package notification | ||
|
||
import ( | ||
"net/http" | ||
"time" | ||
|
||
dutyAPI "github.com/flanksource/duty/api" | ||
"github.com/flanksource/duty/context" | ||
"github.com/flanksource/postq" | ||
"github.com/google/uuid" | ||
"github.com/labstack/echo/v4" | ||
) | ||
|
||
func RegisterRoutes(e *echo.Echo) { | ||
apiGroup := e.Group("/notifications") | ||
apiGroup.POST("/test", TestNotification) | ||
} | ||
|
||
func TestNotification(c echo.Context) error { | ||
ctx := c.Request().Context().(context.Context) | ||
|
||
var reqData struct { | ||
ID uuid.UUID `json:"id"` | ||
EventName string `json:"eventName"` | ||
} | ||
if err := c.Bind(&reqData); err != nil { | ||
return dutyAPI.WriteError(c, dutyAPI.Errorf(dutyAPI.EINVALID, "invalid request: %v", err)) | ||
} | ||
|
||
e := postq.Event{ | ||
Name: reqData.EventName, | ||
Properties: map[string]string{"id": reqData.ID.String()}, | ||
CreatedAt: time.Now(), | ||
} | ||
|
||
if err := addNotificationEvent(ctx, e); err != nil { | ||
return dutyAPI.WriteError(c, dutyAPI.Errorf(dutyAPI.EINTERNAL, "unable to create notification event: %v", err)) | ||
} | ||
|
||
return c.JSON(http.StatusOK, dutyAPI.HTTPSuccess{Message: "success"}) | ||
} |