1.3: GET /admin/users/stats — Felhasználói statisztikák endpoint #307

Closed
opened 2026-06-29 03:36:25 +02:00 by kincses · 3 comments
Owner

Mérföldkő: Admin User & Person Management
Cél: Dashboard statisztikák a felhasználókról: total_users, active_users, deleted_users, banned_users, new_users_today/week/month, users_by_role, users_by_plan, users_by_language, users_with_person, users_without_person, registration_trend (napi bontás), active_organizations_count, total_memberships.

🔗 Függőségek (Dependencies)

  • Bemenet (Mikre támaszkodik): User, OrganizationMember modellek; require_admin függőség
  • Kimenet (Mik támaszkodnak rá): Frontend dashboard (5.1), user lista oldal statisztikai kártyái (3.1)

📝 Elemzés

Új GET /admin/users/stats endpoint. SQL aggregációk: COUNT, GROUP BY role/plan/language. Registration trend: DATE(created_at) GROUP BY. JOIN marketplace.organization_members a memberships számhoz.

**Mérföldkő:** Admin User & Person Management **Cél:** Dashboard statisztikák a felhasználókról: total_users, active_users, deleted_users, banned_users, new_users_today/week/month, users_by_role, users_by_plan, users_by_language, users_with_person, users_without_person, registration_trend (napi bontás), active_organizations_count, total_memberships. ### 🔗 Függőségek (Dependencies) - **Bemenet (Mikre támaszkodik):** User, OrganizationMember modellek; require_admin függőség - **Kimenet (Mik támaszkodnak rá):** Frontend dashboard (5.1), user lista oldal statisztikai kártyái (3.1) ### 📝 Elemzés Új GET /admin/users/stats endpoint. SQL aggregációk: COUNT, GROUP BY role/plan/language. Registration trend: DATE(created_at) GROUP BY. JOIN marketplace.organization_members a memberships számhoz.
kincses added this to the Epic 10 (Admin UI) Jegyek Létrehozása milestone 2026-06-29 03:36:25 +02:00
kincses added the Status: To DoScope: BackendType: Feature labels 2026-06-29 03:36:25 +02:00
kincses added Status: In Progress and removed Status: To Do labels 2026-06-29 04:07:52 +02:00
kincses started working 2026-06-29 04:07:52 +02:00
Author
Owner

▶️ Munka megkezdve: 2026-06-29 04:07:51

▶️ **Munka megkezdve:** 2026-06-29 04:07:51
kincses added Status: Done and removed Status: In Progress labels 2026-06-29 04:13:01 +02:00
kincses worked for 5 minutes 2026-06-29 04:13:01 +02:00
Author
Owner

Munka befejezve: 2026-06-29 04:13:01

Technikai Összefoglaló:
GET /admin/users/stats endpoint implemented: RegistrationTrendItem + UserStatsResponse Pydantic models, 8 async SQL queries (total/active/deleted/banned users, new users today/week/month, role/plan/language distribution, Person relationship, 30-day registration trend, org stats). HTTP 200 verified with 34 users, 25 active orgs.

⏱️ Az idő rögzítve.

✅ **Munka befejezve:** 2026-06-29 04:13:01 **Technikai Összefoglaló:** GET /admin/users/stats endpoint implemented: RegistrationTrendItem + UserStatsResponse Pydantic models, 8 async SQL queries (total/active/deleted/banned users, new users today/week/month, role/plan/language distribution, Person relationship, 30-day registration trend, org stats). HTTP 200 verified with 34 users, 25 active orgs. ⏱️ *Az idő rögzítve.*
Author
Owner

Gitea #307: GET /admin/users/stats — Completed

Implementáció

A backend/app/api/v1/endpoints/admin_users.py fájlban implementáltam a GET /admin/users/stats végpontot a plans/logic_spec_admin_user_person_management.md specifikáció alapján.

Hozzáadott komponensek:

  1. RegistrationTrendItem Pydantic modell — napi regisztrációs trend elem (date + count)
  2. UserStatsResponse Pydantic modell — 15 mezős válaszstruktúra
  3. get_user_stats async végpont — 8 SQL lekérdezés egy tranzakcióban:
    • Alap statisztikák (total/active/deleted/banned users)
    • Új felhasználók (today/week/month)
    • Megoszlás (role, subscription_plan, preferred_language szerint)
    • Person kapcsolat megléte/hiánya
    • 30 napos regisztrációs trend (date_trunc-el)
    • Szervezeti statisztikák (aktív org-k, tagságok)

Teszt eredmények:

  • HTTP 200 — Minden adat helyesen visszaadva
  • Sync Engine: 1279/1279 OK
  • Gitea #307: Lezárva

API válasz minta:

{
  "total_users": 34, "active_users": 16, "deleted_users": 1, "banned_users": 17,
  "new_users_today": 0, "new_users_this_week": 0, "new_users_this_month": 28,
  "users_by_role": {"user": 30, "admin": 2, "superadmin": 2},
  "users_by_plan": {"pro": 1, "premium": 3, "enterprise": 2, "free": 28},
  "users_by_language": {"hu": 31, "en": 3},
  "users_with_person": 34, "users_without_person": 0,
  "registration_trend": [...],
  "active_organizations_count": 25, "total_memberships": 23
}
## ✅ Gitea #307: GET /admin/users/stats — Completed ### Implementáció A [`backend/app/api/v1/endpoints/admin_users.py`](backend/app/api/v1/endpoints/admin_users.py:106) fájlban implementáltam a `GET /admin/users/stats` végpontot a [`plans/logic_spec_admin_user_person_management.md`](plans/logic_spec_admin_user_person_management.md:224) specifikáció alapján. ### Hozzáadott komponensek: 1. **`RegistrationTrendItem`** Pydantic modell — napi regisztrációs trend elem (date + count) 2. **`UserStatsResponse`** Pydantic modell — 15 mezős válaszstruktúra 3. **`get_user_stats`** async végpont — 8 SQL lekérdezés egy tranzakcióban: - Alap statisztikák (total/active/deleted/banned users) - Új felhasználók (today/week/month) - Megoszlás (role, subscription_plan, preferred_language szerint) - Person kapcsolat megléte/hiánya - 30 napos regisztrációs trend (`date_trunc`-el) - Szervezeti statisztikák (aktív org-k, tagságok) ### Teszt eredmények: - **HTTP 200** ✅ — Minden adat helyesen visszaadva - **Sync Engine:** ✅ 1279/1279 OK - **Gitea #307:** ✅ Lezárva ### API válasz minta: ```json { "total_users": 34, "active_users": 16, "deleted_users": 1, "banned_users": 17, "new_users_today": 0, "new_users_this_week": 0, "new_users_this_month": 28, "users_by_role": {"user": 30, "admin": 2, "superadmin": 2}, "users_by_plan": {"pro": 1, "premium": 3, "enterprise": 2, "free": 28}, "users_by_language": {"hu": 31, "en": 3}, "users_with_person": 34, "users_without_person": 0, "registration_trend": [...], "active_organizations_count": 25, "total_memberships": 23 } ```
Sign in to join this conversation.