Skip to content

Commit 54511ea

Browse files
authored
Dynamic event api improvements (frain-dev#1884)
* chore: go mod * feat: use flat structure for dynamic event api * fix: fix TestProcessDynamicEventCreation * fix: - fix TestCreateDynamicEventService_Run - remove valid tag from models.DynamicEvent.ProjectID * doc: add swag fmt -d ./api * fix: use endpoint id in title
1 parent 3024f98 commit 54511ea

15 files changed

+131
-837
lines changed

.githooks/pre-commit

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ then
1616
else
1717
# regenerate docs
1818
swag init --generatedTime --parseDependency --parseInternal -g handlers/main.go -d api/ api/*
19+
swag fmt -d ./api
1920
go run v3gen/main.go
2021
git add docs/ # add all files under the generated doc folder to git
2122
fi

api/handlers/event_delivery.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (h *Handler) ResendEventDelivery(w http.ResponseWriter, r *http.Request) {
9393
// @Tags Event Deliveries
9494
// @Accept json
9595
// @Produce json
96-
// @Param projectID path string true "Project ID"
96+
// @Param projectID path string true "Project ID"
9797
// @Param request query models.QueryListEventDelivery false "Query Params"
9898
// @Success 200 {object} util.ServerResponse{data=Stub}
9999
// @Failure 400,401,404 {object} util.ServerResponse{data=Stub}
@@ -140,8 +140,8 @@ func (h *Handler) BatchRetryEventDelivery(w http.ResponseWriter, r *http.Request
140140
// @Tags Event Deliveries
141141
// @Accept json
142142
// @Produce json
143-
// @Param projectID path string true "Project ID"
144-
// @Param deliveryIds body models.IDs true "event delivery ids"
143+
// @Param projectID path string true "Project ID"
144+
// @Param deliveryIds body models.IDs true "event delivery ids"
145145
// @Success 200 {object} util.ServerResponse{data=Stub}
146146
// @Failure 400,401,404 {object} util.ServerResponse{data=Stub}
147147
// @Security ApiKeyAuth

api/models/event.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package models
33
import (
44
"encoding/json"
55
"errors"
6+
"net/http"
7+
"time"
8+
69
"github.com/frain-dev/convoy/datastore"
710
m "github.com/frain-dev/convoy/internal/pkg/middleware"
811
"github.com/frain-dev/convoy/util"
9-
"net/http"
10-
"time"
1112
)
1213

1314
type CreateEvent struct {
@@ -26,9 +27,13 @@ func (e *CreateEvent) Validate() error {
2627
}
2728

2829
type DynamicEvent struct {
29-
Endpoint DynamicEndpoint `json:"endpoint"`
30-
Subscription DynamicSubscription `json:"subscription"`
31-
Event DynamicEventStub `json:"event"`
30+
URL string `json:"url" valid:"required~please provide a url"`
31+
Secret string `json:"secret" valid:"required~please provide a secret"`
32+
EventTypes []string `json:"event_types"`
33+
Data json.RawMessage `json:"data" valid:"required~please provide your data"`
34+
ProjectID string `json:"project_id" swaggerignore:"true"`
35+
EventType string `json:"event_type" valid:"required~please provide an event type"`
36+
IdempotencyKey string `json:"idempotency_key"`
3237
}
3338

3439
func (de *DynamicEvent) Validate() error {

api/public_integration_test.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -680,14 +680,12 @@ func (s *PublicEventIntegrationTestSuite) Test_CreateDynamicEvent() {
680680
_, _ = testdb.SeedEndpoint(s.ConvoyApp.A.DB, s.DefaultProject, endpointID, "", "", false, datastore.ActiveEndpointStatus)
681681

682682
bodyStr := `{
683-
"endpoint": {
684683
"url":"https://testing.com",
685-
"secret": "12345"
686-
},
687-
"event": {
684+
"secret": "12345",
688685
"event_type":"*",
686+
"event_types":["*"],
689687
"data": {"name":"daniel"},
690-
"custom_headers": {"x-sig":"convoy"}
688+
"idempotency_key": "idem-key-1"
691689
}
692690
}`
693691
body := serialize(bodyStr, endpointID)

docs/docs.go

+11-89
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
// Code generated by swaggo/swag at 2024-01-23 06:21:57.045906 -0800 PST m=+1.982481251. DO NOT EDIT
1+
// Package docs GENERATED BY SWAG; DO NOT EDIT
2+
// This file was generated by swaggo/swag at
3+
// 2024-01-24 14:08:39.432768 +0000 GMT m=+2.027833543
24
package docs
35

46
import "github.com/swaggo/swag"
@@ -6364,79 +6366,10 @@ const docTemplate = `{
63646366
}
63656367
}
63666368
},
6367-
"models.DynamicEndpoint": {
6368-
"type": "object",
6369-
"properties": {
6370-
"advanced_signatures": {
6371-
"type": "boolean"
6372-
},
6373-
"appID": {
6374-
"description": "Deprecated but necessary for backward compatibility",
6375-
"type": "string"
6376-
},
6377-
"authentication": {
6378-
"$ref": "#/definitions/models.EndpointAuthentication"
6379-
},
6380-
"description": {
6381-
"type": "string"
6382-
},
6383-
"http_timeout": {
6384-
"type": "string"
6385-
},
6386-
"is_disabled": {
6387-
"type": "boolean"
6388-
},
6389-
"name": {
6390-
"type": "string"
6391-
},
6392-
"owner_id": {
6393-
"type": "string"
6394-
},
6395-
"rate_limit": {
6396-
"type": "integer"
6397-
},
6398-
"rate_limit_duration": {
6399-
"type": "string"
6400-
},
6401-
"secret": {
6402-
"type": "string"
6403-
},
6404-
"slack_webhook_url": {
6405-
"type": "string"
6406-
},
6407-
"support_email": {
6408-
"type": "string"
6409-
},
6410-
"url": {
6411-
"type": "string"
6412-
}
6413-
}
6414-
},
64156369
"models.DynamicEvent": {
64166370
"type": "object",
64176371
"properties": {
6418-
"endpoint": {
6419-
"$ref": "#/definitions/models.DynamicEndpoint"
6420-
},
6421-
"event": {
6422-
"$ref": "#/definitions/models.DynamicEventStub"
6423-
},
6424-
"subscription": {
6425-
"$ref": "#/definitions/models.DynamicSubscription"
6426-
}
6427-
}
6428-
},
6429-
"models.DynamicEventStub": {
6430-
"type": "object",
6431-
"properties": {
6432-
"custom_headers": {
6433-
"type": "object",
6434-
"additionalProperties": {
6435-
"type": "string"
6436-
}
6437-
},
64386372
"data": {
6439-
"description": "Data is an arbitrary JSON value that gets sent as the body of the webhook to the endpoints",
64406373
"type": "array",
64416374
"items": {
64426375
"type": "integer"
@@ -6445,31 +6378,20 @@ const docTemplate = `{
64456378
"event_type": {
64466379
"type": "string"
64476380
},
6381+
"event_types": {
6382+
"type": "array",
6383+
"items": {
6384+
"type": "string"
6385+
}
6386+
},
64486387
"idempotency_key": {
64496388
"type": "string"
64506389
},
6451-
"project_id": {
6390+
"secret": {
64526391
"type": "string"
6453-
}
6454-
}
6455-
},
6456-
"models.DynamicSubscription": {
6457-
"type": "object",
6458-
"properties": {
6459-
"alert_config": {
6460-
"$ref": "#/definitions/models.AlertConfiguration"
64616392
},
6462-
"filter_config": {
6463-
"$ref": "#/definitions/models.FilterConfiguration"
6464-
},
6465-
"name": {
6393+
"url": {
64666394
"type": "string"
6467-
},
6468-
"rate_limit_config": {
6469-
"$ref": "#/definitions/models.RateLimitConfiguration"
6470-
},
6471-
"retry_config": {
6472-
"$ref": "#/definitions/models.RetryConfiguration"
64736395
}
64746396
}
64756397
},

docs/swagger.json

+8-88
Original file line numberDiff line numberDiff line change
@@ -6361,79 +6361,10 @@
63616361
}
63626362
}
63636363
},
6364-
"models.DynamicEndpoint": {
6365-
"type": "object",
6366-
"properties": {
6367-
"advanced_signatures": {
6368-
"type": "boolean"
6369-
},
6370-
"appID": {
6371-
"description": "Deprecated but necessary for backward compatibility",
6372-
"type": "string"
6373-
},
6374-
"authentication": {
6375-
"$ref": "#/definitions/models.EndpointAuthentication"
6376-
},
6377-
"description": {
6378-
"type": "string"
6379-
},
6380-
"http_timeout": {
6381-
"type": "string"
6382-
},
6383-
"is_disabled": {
6384-
"type": "boolean"
6385-
},
6386-
"name": {
6387-
"type": "string"
6388-
},
6389-
"owner_id": {
6390-
"type": "string"
6391-
},
6392-
"rate_limit": {
6393-
"type": "integer"
6394-
},
6395-
"rate_limit_duration": {
6396-
"type": "string"
6397-
},
6398-
"secret": {
6399-
"type": "string"
6400-
},
6401-
"slack_webhook_url": {
6402-
"type": "string"
6403-
},
6404-
"support_email": {
6405-
"type": "string"
6406-
},
6407-
"url": {
6408-
"type": "string"
6409-
}
6410-
}
6411-
},
64126364
"models.DynamicEvent": {
64136365
"type": "object",
64146366
"properties": {
6415-
"endpoint": {
6416-
"$ref": "#/definitions/models.DynamicEndpoint"
6417-
},
6418-
"event": {
6419-
"$ref": "#/definitions/models.DynamicEventStub"
6420-
},
6421-
"subscription": {
6422-
"$ref": "#/definitions/models.DynamicSubscription"
6423-
}
6424-
}
6425-
},
6426-
"models.DynamicEventStub": {
6427-
"type": "object",
6428-
"properties": {
6429-
"custom_headers": {
6430-
"type": "object",
6431-
"additionalProperties": {
6432-
"type": "string"
6433-
}
6434-
},
64356367
"data": {
6436-
"description": "Data is an arbitrary JSON value that gets sent as the body of the webhook to the endpoints",
64376368
"type": "array",
64386369
"items": {
64396370
"type": "integer"
@@ -6442,31 +6373,20 @@
64426373
"event_type": {
64436374
"type": "string"
64446375
},
6376+
"event_types": {
6377+
"type": "array",
6378+
"items": {
6379+
"type": "string"
6380+
}
6381+
},
64456382
"idempotency_key": {
64466383
"type": "string"
64476384
},
6448-
"project_id": {
6385+
"secret": {
64496386
"type": "string"
6450-
}
6451-
}
6452-
},
6453-
"models.DynamicSubscription": {
6454-
"type": "object",
6455-
"properties": {
6456-
"alert_config": {
6457-
"$ref": "#/definitions/models.AlertConfiguration"
64586387
},
6459-
"filter_config": {
6460-
"$ref": "#/definitions/models.FilterConfiguration"
6461-
},
6462-
"name": {
6388+
"url": {
64636389
"type": "string"
6464-
},
6465-
"rate_limit_config": {
6466-
"$ref": "#/definitions/models.RateLimitConfiguration"
6467-
},
6468-
"retry_config": {
6469-
"$ref": "#/definitions/models.RetryConfiguration"
64706390
}
64716391
}
64726392
},

0 commit comments

Comments
 (0)