-
Notifications
You must be signed in to change notification settings - Fork 145
/
sns_create.go
39 lines (29 loc) · 1.05 KB
/
sns_create.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package ingestors
import (
"github.com/labstack/echo/v4"
"github.com/hatchet-dev/hatchet/api/v1/server/oas/gen"
"github.com/hatchet-dev/hatchet/api/v1/server/oas/transformers"
"github.com/hatchet-dev/hatchet/internal/repository"
"github.com/hatchet-dev/hatchet/internal/repository/prisma/db"
)
func (i *IngestorsService) SnsCreate(ctx echo.Context, req gen.SnsCreateRequestObject) (gen.SnsCreateResponseObject, error) {
tenant := ctx.Get("tenant").(*db.TenantModel)
// validate the request
if apiErrors, err := i.config.Validator.ValidateAPI(req.Body); err != nil {
return nil, err
} else if apiErrors != nil {
return gen.SnsCreate400JSONResponse(*apiErrors), nil
}
opts := &repository.CreateSNSIntegrationOpts{
TopicArn: req.Body.TopicArn,
}
// create the SNS integration
snsIntegration, err := i.config.APIRepository.SNS().CreateSNSIntegration(tenant.ID, opts)
if err != nil {
return nil, err
}
resp := transformers.ToSNSIntegration(snsIntegration, i.config.Runtime.ServerURL)
return gen.SnsCreate201JSONResponse(
*resp,
), nil
}