From 8d4a5751d82037fe4e5340d1e931188021f90fb8 Mon Sep 17 00:00:00 2001 From: Kailash Nadh Date: Tue, 22 Nov 2022 23:11:05 +0530 Subject: [PATCH] Fix broken single list fetch API. --- cmd/lists.go | 8 ++++++++ internal/core/lists.go | 7 ++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/cmd/lists.go b/cmd/lists.go index 418b4f9..f454895 100644 --- a/cmd/lists.go +++ b/cmd/lists.go @@ -30,6 +30,14 @@ func handleGetLists(c echo.Context) error { single = true } + if single { + out, err := app.core.GetList(listID, "") + if err != nil { + return err + } + return c.JSON(http.StatusOK, okResp{out}) + } + // Minimal query simply returns the list of all lists without JOIN subscriber counts. This is fast. if !single && minimal { res, err := app.core.GetLists("") diff --git a/internal/core/lists.go b/internal/core/lists.go index 9a5f4bb..6db679e 100644 --- a/internal/core/lists.go +++ b/internal/core/lists.go @@ -82,11 +82,12 @@ func (c *Core) GetList(id int, uuid string) (models.List, error) { c.i18n.Ts("globals.messages.errorFetching", "name", "{globals.terms.lists}", "error", pqErrMsg(err))) } - if len(out) == 1 { - return out[0], nil + if len(out) == 0 { + return models.List{}, echo.NewHTTPError(http.StatusBadRequest, + c.i18n.Ts("globals.messages.notFound", "name", "{globals.terms.list}")) } - return models.List{}, nil + return out[0], nil } // GetListsByOptin returns lists by optin type.