Skip to content

Commit b12deec

Browse files
committed
feat: add test notification endpoint
1 parent 2ec8d17 commit b12deec

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

echo/serve.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/flanksource/incident-commander/catalog"
1919
"github.com/flanksource/incident-commander/db"
2020
"github.com/flanksource/incident-commander/logs"
21+
"github.com/flanksource/incident-commander/notification"
2122
"github.com/flanksource/incident-commander/playbook"
2223
"github.com/flanksource/incident-commander/rbac"
2324
"github.com/flanksource/incident-commander/snapshot"
@@ -89,6 +90,7 @@ func New(ctx context.Context) *echov4.Echo {
8990
artifacts.RegisterRoutes(e, "artifacts")
9091

9192
playbook.RegisterRoutes(e)
93+
notification.RegisterRoutes(e)
9294

9395
e.POST("/agent/generate", agent.GenerateAgent, rbac.Authorization(rbac.ObjectAgentCreate, rbac.ActionWrite))
9496
e.POST("/logs", logs.LogsHandler)

notification/controllers.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package notification
2+
3+
import (
4+
"net/http"
5+
"time"
6+
7+
dutyAPI "github.com/flanksource/duty/api"
8+
"github.com/flanksource/duty/context"
9+
"github.com/flanksource/postq"
10+
"github.com/google/uuid"
11+
"github.com/labstack/echo/v4"
12+
)
13+
14+
func RegisterRoutes(e *echo.Echo) {
15+
apiGroup := e.Group("/notifications")
16+
apiGroup.POST("/test", TestNotification)
17+
}
18+
19+
func TestNotification(c echo.Context) error {
20+
ctx := c.Request().Context().(context.Context)
21+
22+
var reqData struct {
23+
ID uuid.UUID `json:"id"`
24+
EventName string `json:"eventName"`
25+
}
26+
if err := c.Bind(&reqData); err != nil {
27+
return dutyAPI.WriteError(c, dutyAPI.Errorf(dutyAPI.EINVALID, "invalid request: %v", err))
28+
}
29+
30+
e := postq.Event{
31+
Name: reqData.EventName,
32+
Properties: map[string]string{"id": reqData.ID.String()},
33+
CreatedAt: time.Now(),
34+
}
35+
36+
if err := addNotificationEvent(ctx, e); err != nil {
37+
return dutyAPI.WriteError(c, dutyAPI.Errorf(dutyAPI.EINTERNAL, "unable to create notification event: %v", err))
38+
}
39+
40+
return c.JSON(http.StatusOK, dutyAPI.HTTPSuccess{Message: "success"})
41+
}

0 commit comments

Comments
 (0)