From b8811a4072dbb65510a83c3de28a8e4743bdd0f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Eduardo=20Jer=C3=A9z=20Gir=C3=B3n?= Date: Sun, 1 Sep 2024 23:53:39 -0600 Subject: [PATCH] Change webhook_executions table name --- .../migrations/20240818185840_add_webhooks_tables.sql | 6 +++--- internal/service/webhooks/paginate_webhook_executions.go | 6 +++--- internal/service/webhooks/paginate_webhook_executions.sql | 4 ++-- internal/service/webhooks/run_webhook.sql | 4 ++-- internal/service/webhooks/send_webhook_request.go | 4 ++-- internal/view/web/dashboard/webhooks/webhook_executions.go | 4 ++-- 6 files changed, 14 insertions(+), 14 deletions(-) diff --git a/internal/database/migrations/20240818185840_add_webhooks_tables.sql b/internal/database/migrations/20240818185840_add_webhooks_tables.sql index f9ffc96..e750ebc 100644 --- a/internal/database/migrations/20240818185840_add_webhooks_tables.sql +++ b/internal/database/migrations/20240818185840_add_webhooks_tables.sql @@ -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 diff --git a/internal/service/webhooks/paginate_webhook_executions.go b/internal/service/webhooks/paginate_webhook_executions.go index 1a72594..2d67a43 100644 --- a/internal/service/webhooks/paginate_webhook_executions.go +++ b/internal/service/webhooks/paginate_webhook_executions.go @@ -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 } diff --git a/internal/service/webhooks/paginate_webhook_executions.sql b/internal/service/webhooks/paginate_webhook_executions.sql index fd7b2f4..5b5143b 100644 --- a/internal/service/webhooks/paginate_webhook_executions.sql +++ b/internal/service/webhooks/paginate_webhook_executions.sql @@ -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'); \ No newline at end of file diff --git a/internal/service/webhooks/run_webhook.sql b/internal/service/webhooks/run_webhook.sql index 147fcf8..5adab88 100644 --- a/internal/service/webhooks/run_webhook.sql +++ b/internal/service/webhooks/run_webhook.sql @@ -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 ) diff --git a/internal/service/webhooks/send_webhook_request.go b/internal/service/webhooks/send_webhook_request.go index 155a114..f6e68f7 100644 --- a/internal/service/webhooks/send_webhook_request.go +++ b/internal/service/webhooks/send_webhook_request.go @@ -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, diff --git a/internal/view/web/dashboard/webhooks/webhook_executions.go b/internal/view/web/dashboard/webhooks/webhook_executions.go index 53c292f..12a0798 100644 --- a/internal/view/web/dashboard/webhooks/webhook_executions.go +++ b/internal/view/web/dashboard/webhooks/webhook_executions.go @@ -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{