mirror of
https://github.com/SamyRai/turash.git
synced 2025-12-26 23:01:33 +00:00
119 lines
3.5 KiB
Go
119 lines
3.5 KiB
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"bugulma/backend/internal/service"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type AdminHandler struct {
|
|
adminService *service.AdminService
|
|
analyticsSvc *service.AnalyticsService
|
|
}
|
|
|
|
func NewAdminHandler(adminService *service.AdminService, analyticsSvc *service.AnalyticsService) *AdminHandler {
|
|
return &AdminHandler{
|
|
adminService: adminService,
|
|
analyticsSvc: analyticsSvc,
|
|
}
|
|
}
|
|
|
|
// GetDashboardStats returns dashboard statistics (admin only)
|
|
// @Summary Get dashboard statistics
|
|
// @Tags admin
|
|
// @Produce json
|
|
// @Success 200 {object} service.DashboardStats
|
|
// @Router /api/v1/admin/dashboard/stats [get]
|
|
func (h *AdminHandler) GetDashboardStats(c *gin.Context) {
|
|
stats, err := h.adminService.GetDashboardStats(c.Request.Context())
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, stats)
|
|
}
|
|
|
|
// GetOrganizationStats returns organization analytics (admin only)
|
|
// @Summary Get organization statistics
|
|
// @Tags admin
|
|
// @Produce json
|
|
// @Success 200 {object} service.OrganizationStats
|
|
// @Router /api/v1/admin/analytics/organizations [get]
|
|
func (h *AdminHandler) GetOrganizationStats(c *gin.Context) {
|
|
stats, err := h.adminService.GetOrganizationStats(c.Request.Context(), nil)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, stats)
|
|
}
|
|
|
|
// GetUserActivityStats returns user activity analytics (admin only)
|
|
// @Summary Get user activity statistics
|
|
// @Tags admin
|
|
// @Produce json
|
|
// @Success 200 {object} service.UserActivityStats
|
|
// @Router /api/v1/admin/analytics/users [get]
|
|
func (h *AdminHandler) GetUserActivityStats(c *gin.Context) {
|
|
stats, err := h.adminService.GetUserActivityStats(c.Request.Context(), nil)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, stats)
|
|
}
|
|
|
|
// GetMatchingStats returns matching analytics (admin only)
|
|
// @Summary Get matching statistics
|
|
// @Tags admin
|
|
// @Produce json
|
|
// @Success 200 {object} service.MatchingStats
|
|
// @Router /api/v1/admin/analytics/matching [get]
|
|
func (h *AdminHandler) GetMatchingStats(c *gin.Context) {
|
|
stats, err := h.adminService.GetMatchingStats(c.Request.Context(), nil)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, stats)
|
|
}
|
|
|
|
// GetSystemHealth returns system health metrics (admin only)
|
|
// @Summary Get system health
|
|
// @Tags admin
|
|
// @Produce json
|
|
// @Success 200 {object} service.SystemHealth
|
|
// @Router /api/v1/admin/system/health [get]
|
|
func (h *AdminHandler) GetSystemHealth(c *gin.Context) {
|
|
health, err := h.adminService.GetSystemHealth(c.Request.Context())
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, health)
|
|
}
|
|
|
|
// GetRecentActivity returns recent activity logs (admin only)
|
|
// @Summary Get recent activity
|
|
// @Tags admin
|
|
// @Produce json
|
|
// @Success 200 {array} object
|
|
// @Router /api/v1/admin/dashboard/activity [get]
|
|
func (h *AdminHandler) GetRecentActivity(c *gin.Context) {
|
|
// Use analytics service to get recent dashboard statistics which include recent activity
|
|
if h.analyticsSvc == nil {
|
|
c.JSON(http.StatusOK, []interface{}{})
|
|
return
|
|
}
|
|
|
|
stats, err := h.analyticsSvc.GetDashboardStatistics(c.Request.Context())
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, stats.RecentActivity)
|
|
}
|