Fix incorrect 'get subscriber' calls

This commit is contained in:
Kailash Nadh 2021-02-15 18:27:14 +05:30
parent e90fb1d88d
commit 97b78aa695
2 changed files with 4 additions and 10 deletions

View File

@ -118,15 +118,14 @@ func handleViewCampaignMessage(c echo.Context) error {
} }
// Get the subscriber. // Get the subscriber.
var sub models.Subscriber sub, err := getSubscriber(0, subUUID, "", app)
if err := app.queries.GetSubscriber.Get(&sub, 0, subUUID); err != nil { if err != nil {
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
return c.Render(http.StatusNotFound, tplMessage, return c.Render(http.StatusNotFound, tplMessage,
makeMsgTpl(app.i18n.T("public.notFoundTitle"), "", makeMsgTpl(app.i18n.T("public.notFoundTitle"), "",
app.i18n.T("public.errorFetchingEmail"))) app.i18n.T("public.errorFetchingEmail")))
} }
app.log.Printf("error fetching campaign subscriber: %v", err)
return c.Render(http.StatusInternalServerError, tplMessage, return c.Render(http.StatusInternalServerError, tplMessage,
makeMsgTpl(app.i18n.T("public.errorTitle"), "", makeMsgTpl(app.i18n.T("public.errorTitle"), "",
app.i18n.Ts("public.errorFetchingCampaign"))) app.i18n.Ts("public.errorFetchingCampaign")))

View File

@ -338,7 +338,6 @@ func handleSubscriberSendOptin(c echo.Context) error {
var ( var (
app = c.Get("app").(*App) app = c.Get("app").(*App)
id, _ = strconv.Atoi(c.Param("id")) id, _ = strconv.Atoi(c.Param("id"))
out models.Subscribers
) )
if id < 1 { if id < 1 {
@ -346,19 +345,15 @@ func handleSubscriberSendOptin(c echo.Context) error {
} }
// Fetch the subscriber. // Fetch the subscriber.
err := app.queries.GetSubscriber.Select(&out, id, nil) out, err := getSubscriber(id, "", "", app)
if err != nil { if err != nil {
app.log.Printf("error fetching subscriber: %v", err) app.log.Printf("error fetching subscriber: %v", err)
return echo.NewHTTPError(http.StatusInternalServerError, return echo.NewHTTPError(http.StatusInternalServerError,
app.i18n.Ts("globals.messages.errorFetching", app.i18n.Ts("globals.messages.errorFetching",
"name", "{globals.terms.subscribers}", "error", pqErrMsg(err))) "name", "{globals.terms.subscribers}", "error", pqErrMsg(err)))
} }
if len(out) == 0 {
return echo.NewHTTPError(http.StatusBadRequest,
app.i18n.Ts("globals.messages.notFound", "name", "{globals.terms.subscriber}"))
}
if _, err := sendOptinConfirmation(out[0], nil, app); err != nil { if _, err := sendOptinConfirmation(out, nil, app); err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, return echo.NewHTTPError(http.StatusInternalServerError,
app.i18n.T("subscribers.errorSendingOptin")) app.i18n.T("subscribers.errorSendingOptin"))
} }