Skip to content

Commit

Permalink
Fix broken single list fetch API.
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Nov 22, 2022
1 parent e60b385 commit 8d4a575
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 8 additions & 0 deletions cmd/lists.go
Expand Up @@ -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("")
Expand Down
7 changes: 4 additions & 3 deletions internal/core/lists.go
Expand Up @@ -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.
Expand Down

0 comments on commit 8d4a575

Please sign in to comment.