Skip to content

Commit

Permalink
Change webhook_executions table name
Browse files Browse the repository at this point in the history
eduardolat committed Sep 2, 2024
1 parent f172f4b commit b8811a4
Showing 6 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ BEFORE UPDATE ON webhooks FOR EACH ROW EXECUTE FUNCTION change_updated_at();
CREATE INDEX IF NOT EXISTS
idx_webhooks_target_ids ON webhooks USING GIN (target_ids);

CREATE TABLE IF NOT EXISTS webhook_results (
CREATE TABLE IF NOT EXISTS webhook_executions (
id UUID NOT NULL DEFAULT uuid_generate_v4() PRIMARY KEY,
webhook_id UUID NOT NULL REFERENCES webhooks(id) ON DELETE CASCADE,

@@ -45,11 +45,11 @@ CREATE TABLE IF NOT EXISTS webhook_results (
);

CREATE INDEX IF NOT EXISTS
idx_webhook_results_webhook_id ON webhook_results(webhook_id);
idx_webhook_executions_webhook_id ON webhook_executions(webhook_id);
-- +goose StatementEnd

-- +goose Down
-- +goose StatementBegin
DROP TABLE IF EXISTS webhook_results;
DROP TABLE IF EXISTS webhook_executions;
DROP TABLE IF EXISTS webhooks;
-- +goose StatementEnd
6 changes: 3 additions & 3 deletions internal/service/webhooks/paginate_webhook_executions.go
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ type PaginateWebhookExecutionsParams struct {

func (s *Service) PaginateWebhookExecutions(
ctx context.Context, params PaginateWebhookExecutionsParams,
) (paginateutil.PaginateResponse, []dbgen.WebhookResult, error) {
) (paginateutil.PaginateResponse, []dbgen.WebhookExecution, error) {
page := max(params.Page, 1)
limit := min(max(params.Limit, 1), 100)

@@ -34,7 +34,7 @@ func (s *Service) PaginateWebhookExecutions(
offset := paginateutil.CreateOffsetFromParams(paginateParams)
paginateResponse := paginateutil.CreatePaginateResponse(paginateParams, int(count))

webhookResults, err := s.dbgen.WebhooksServicePaginateWebhookExecutions(
webhookExecutions, err := s.dbgen.WebhooksServicePaginateWebhookExecutions(
ctx, dbgen.WebhooksServicePaginateWebhookExecutionsParams{
WebhookID: params.WebhookID,
Limit: int32(params.Limit),
@@ -45,5 +45,5 @@ func (s *Service) PaginateWebhookExecutions(
return paginateutil.PaginateResponse{}, nil, err
}

return paginateResponse, webhookResults, nil
return paginateResponse, webhookExecutions, nil
}
4 changes: 2 additions & 2 deletions internal/service/webhooks/paginate_webhook_executions.sql
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
-- name: WebhooksServicePaginateWebhookExecutionsCount :one
SELECT COUNT(*) FROM webhook_results
SELECT COUNT(*) FROM webhook_executions
WHERE webhook_id = @webhook_id;

-- name: WebhooksServicePaginateWebhookExecutions :many
SELECT * FROM webhook_results
SELECT * FROM webhook_executions
WHERE webhook_id = @webhook_id
ORDER BY created_at DESC
LIMIT sqlc.arg('limit') OFFSET sqlc.arg('offset');
4 changes: 2 additions & 2 deletions internal/service/webhooks/run_webhook.sql
Original file line number Diff line number Diff line change
@@ -4,8 +4,8 @@ WHERE is_active = true
AND event_type = @event_type
AND @target_id::UUID = ANY(target_ids);

-- name: WebhooksServiceCreateWebhookResult :one
INSERT INTO webhook_results (
-- name: WebhooksServiceCreateWebhookExecution :one
INSERT INTO webhook_executions (
webhook_id, req_method, req_headers, req_body,
res_status, res_headers, res_body, res_duration
)
4 changes: 2 additions & 2 deletions internal/service/webhooks/send_webhook_request.go
Original file line number Diff line number Diff line change
@@ -64,8 +64,8 @@ func (s *Service) SendWebhookRequest(
return fmt.Errorf("error reading response body: %w", err)
}

_, err = s.dbgen.WebhooksServiceCreateWebhookResult(
ctx, dbgen.WebhooksServiceCreateWebhookResultParams{
_, err = s.dbgen.WebhooksServiceCreateWebhookExecution(
ctx, dbgen.WebhooksServiceCreateWebhookExecutionParams{
WebhookID: webhook.ID,
ReqMethod: sql.NullString{String: req.Method, Valid: true},
ReqHeaders: webhook.Headers,
4 changes: 2 additions & 2 deletions internal/view/web/dashboard/webhooks/webhook_executions.go
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ func (h *handlers) paginateWebhookExecutionsHandler(c echo.Context) error {
func webhookExecutionsList(
webhookID uuid.UUID,
pagination paginateutil.PaginateResponse,
execs []dbgen.WebhookResult,
execs []dbgen.WebhookExecution,
) gomponents.Node {
if len(execs) == 0 {
return html.Tr(
@@ -111,7 +111,7 @@ func webhookExecutionsList(
}

func webhookExecutionDetailsButton(
exec dbgen.WebhookResult,
exec dbgen.WebhookExecution,
duration time.Duration,
) gomponents.Node {
mo := component.Modal(component.ModalParams{

0 comments on commit b8811a4

Please sign in to comment.