From b94da621d7ea760483f5a13a16ab9acce89e800a Mon Sep 17 00:00:00 2001 From: Kailash Nadh Date: Thu, 5 May 2022 18:05:13 +0530 Subject: [PATCH] Fix broken public link redirect. --- cmd/public.go | 4 ++-- internal/core/campaigns.go | 12 +++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/cmd/public.go b/cmd/public.go index b219f7d3..6b3c8ad5 100644 --- a/cmd/public.go +++ b/cmd/public.go @@ -353,8 +353,8 @@ func handleLinkRedirect(c echo.Context) error { subUUID = "" } - var url string - if err := app.core.RegisterCampaignLinkClick(linkUUID, campUUID, subUUID); err != nil { + url, err := app.core.RegisterCampaignLinkClick(linkUUID, campUUID, subUUID) + if err != nil { e := err.(*echo.HTTPError) return c.Render(e.Code, tplMessage, makeMsgTpl(app.i18n.T("public.errorTitle"), "", e.Error())) } diff --git a/internal/core/campaigns.go b/internal/core/campaigns.go index 6d8e68cf..de744af7 100644 --- a/internal/core/campaigns.go +++ b/internal/core/campaigns.go @@ -329,14 +329,16 @@ func (c *Core) RegisterCampaignView(campUUID, subUUID string) error { } // RegisterCampaignLinkClick registers a subscriber's link click on a campaign. -func (c *Core) RegisterCampaignLinkClick(linkUUID, campUUID, subUUID string) error { - if _, err := c.q.RegisterLinkClick.Exec(linkUUID, campUUID, subUUID); err != nil { +func (c *Core) RegisterCampaignLinkClick(linkUUID, campUUID, subUUID string) (string, error) { + var url string + if err := c.q.RegisterLinkClick.Get(&url, linkUUID, campUUID, subUUID); err != nil { if pqErr, ok := err.(*pq.Error); ok && pqErr.Column == "link_id" { - return echo.NewHTTPError(http.StatusBadRequest, c.i18n.Ts("public.invalidLink")) + return "", echo.NewHTTPError(http.StatusBadRequest, c.i18n.Ts("public.invalidLink")) } c.log.Printf("error registering link click: %s", err) - return echo.NewHTTPError(http.StatusInternalServerError, c.i18n.Ts("public.errorProcessingRequest")) + return "", echo.NewHTTPError(http.StatusInternalServerError, c.i18n.Ts("public.errorProcessingRequest")) } - return nil + + return url, nil }