Add Homepage watchlist summary endpoint
This commit is contained in:
@@ -1780,6 +1780,23 @@ class WatchlistStore:
|
||||
},
|
||||
}
|
||||
|
||||
def homepage_summary(self):
|
||||
with self.lock, self._connect() as conn:
|
||||
rows = conn.execute(
|
||||
"SELECT category, COUNT(*) AS count FROM watchlist GROUP BY category"
|
||||
).fetchall()
|
||||
counts = {key: 0 for key in WATCHLIST_CATEGORY_CHOICES}
|
||||
for row in rows:
|
||||
counts[normalize_watchlist_category(row["category"])] = int(row["count"] or 0)
|
||||
total = sum(counts.values())
|
||||
return {
|
||||
"watchlist": counts["watching"],
|
||||
"planned": counts["planned"],
|
||||
"finished": counts["finished"],
|
||||
"dropped": counts["dropped"],
|
||||
"total": total,
|
||||
}
|
||||
|
||||
def get(self, show_id):
|
||||
with self.lock, self._connect() as conn:
|
||||
row = conn.execute("SELECT * FROM watchlist WHERE show_id = ?", (str(show_id).strip(),)).fetchone()
|
||||
@@ -2407,6 +2424,11 @@ def get_watchlist(page=1, per_page=30, category=None):
|
||||
return WATCHLIST.list(page=page, per_page=per_page, category=category)
|
||||
|
||||
|
||||
def get_watchlist_homepage_summary():
|
||||
ensure_runtime()
|
||||
return WATCHLIST.homepage_summary()
|
||||
|
||||
|
||||
def update_watchlist_status(show_id, _mode=None):
|
||||
ensure_runtime()
|
||||
item = WATCHLIST.queue_refresh(show_id, source="manual")
|
||||
@@ -2857,6 +2879,7 @@ Handler = build_handler_class(
|
||||
ensure_runtime=ensure_runtime,
|
||||
episode_list=episode_list,
|
||||
get_config_snapshot=get_config_snapshot,
|
||||
get_watchlist_homepage_summary=get_watchlist_homepage_summary,
|
||||
get_watchlist=get_watchlist,
|
||||
get_watchlist_refresh_status=get_watchlist_refresh_status,
|
||||
http_error=HttpError,
|
||||
|
||||
Reference in New Issue
Block a user