Admin: Social-Media-Tab mit Manager-Übersicht, Plattform-Auswertung und Post-Nachweis, SW by-v370
This commit is contained in:
parent
e2bb1a4b2d
commit
4f58a784c7
3 changed files with 182 additions and 1 deletions
|
|
@ -728,6 +728,65 @@ async def wiki_fetch_photos(limit: int = 50, user=Depends(require_mod)):
|
|||
# ------------------------------------------------------------------
|
||||
# DELETE /api/admin/wiki/zuchter/{id} — Züchter-Eintrag löschen (Admin/Mod)
|
||||
# ------------------------------------------------------------------
|
||||
@router.get("/social")
|
||||
async def admin_social_stats(user=Depends(require_mod)):
|
||||
"""Social-Media-Übersicht für Admins — alle Manager, alle Plattformen."""
|
||||
with db() as conn:
|
||||
# Pro Manager: Name + Counts
|
||||
managers = conn.execute("""
|
||||
SELECT u.id, u.name,
|
||||
COUNT(sc.id) AS total,
|
||||
COUNT(CASE WHEN sc.status='published' THEN 1 END) AS published,
|
||||
COUNT(CASE WHEN sc.status='idea' THEN 1 END) AS ideas,
|
||||
COUNT(CASE WHEN sc.status='scheduled' THEN 1 END) AS scheduled,
|
||||
COUNT(CASE WHEN sc.post_url IS NOT NULL
|
||||
AND sc.post_url != ''
|
||||
AND sc.status='published' THEN 1 END) AS with_link
|
||||
FROM users u
|
||||
JOIN social_content sc ON sc.created_by = u.id
|
||||
GROUP BY u.id
|
||||
ORDER BY published DESC
|
||||
""").fetchall()
|
||||
|
||||
# Veröffentlichte Posts nach Plattform
|
||||
by_platform = conn.execute("""
|
||||
SELECT platform, COUNT(*) AS n
|
||||
FROM social_content
|
||||
WHERE status='published'
|
||||
GROUP BY platform
|
||||
ORDER BY n DESC
|
||||
""").fetchall()
|
||||
|
||||
# Veröffentlichte Posts nach Monat (letzte 6 Monate)
|
||||
by_month = conn.execute("""
|
||||
SELECT strftime('%Y-%m', published_at) AS monat, COUNT(*) AS n
|
||||
FROM social_content
|
||||
WHERE status='published' AND published_at IS NOT NULL
|
||||
GROUP BY monat
|
||||
ORDER BY monat DESC
|
||||
LIMIT 6
|
||||
""").fetchall()
|
||||
|
||||
# Letzte veröffentlichte Posts mit Link (für Abrechnung/Nachweis)
|
||||
recent_published = conn.execute("""
|
||||
SELECT sc.id, sc.topic, sc.platform, sc.category,
|
||||
sc.published_at, sc.post_url, sc.ai_score,
|
||||
u.name AS manager
|
||||
FROM social_content sc
|
||||
LEFT JOIN users u ON u.id = sc.created_by
|
||||
WHERE sc.status = 'published'
|
||||
ORDER BY sc.published_at DESC
|
||||
LIMIT 50
|
||||
""").fetchall()
|
||||
|
||||
return {
|
||||
"managers": [dict(r) for r in managers],
|
||||
"by_platform": [dict(r) for r in by_platform],
|
||||
"by_month": [dict(r) for r in by_month],
|
||||
"recent_published": [dict(r) for r in recent_published],
|
||||
}
|
||||
|
||||
|
||||
@router.delete("/wiki/zuchter/{zuchter_id}", status_code=204)
|
||||
async def admin_delete_zuchter(zuchter_id: int, user=Depends(require_mod)):
|
||||
with db() as conn:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue