Fix missing subscriber count in individual list GET API.

This commit is contained in:
Kailash Nadh 2022-11-27 23:07:40 +05:30
parent 8e3e1b9af8
commit 448f0e3428

View file

@ -74,20 +74,29 @@ func (c *Core) GetList(id int, uuid string) (models.List, error) {
uu = uuid
}
var out []models.List
var res []models.List
queryStr, stmt := makeSearchQuery("", "", "", c.q.QueryLists)
if err := c.db.Select(&out, stmt, id, uu, queryStr, 0, 1); err != nil {
if err := c.db.Select(&res, stmt, id, uu, queryStr, 0, 1); err != nil {
c.log.Printf("error fetching lists: %v", err)
return models.List{}, echo.NewHTTPError(http.StatusInternalServerError,
c.i18n.Ts("globals.messages.errorFetching", "name", "{globals.terms.lists}", "error", pqErrMsg(err)))
}
if len(out) == 0 {
if len(res) == 0 {
return models.List{}, echo.NewHTTPError(http.StatusBadRequest,
c.i18n.Ts("globals.messages.notFound", "name", "{globals.terms.list}"))
}
return out[0], nil
out := res[0]
if out.Tags == nil {
out.Tags = []string{}
}
// Total counts.
for _, c := range out.SubscriberCounts {
out.SubscriberCount += c
}
return out, nil
}
// GetListsByOptin returns lists by optin type.