36 lines
801 B
Go
36 lines
801 B
Go
|
|
package handler
|
||
|
|
|
||
|
|
import (
|
||
|
|
"net/http"
|
||
|
|
"strconv"
|
||
|
|
|
||
|
|
"github.com/gin-gonic/gin"
|
||
|
|
|
||
|
|
"dating-app/internal/monitoring"
|
||
|
|
"dating-app/internal/utils"
|
||
|
|
)
|
||
|
|
|
||
|
|
type MonitoringHandler struct {
|
||
|
|
store *monitoring.Store
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewMonitoringHandler(store *monitoring.Store) *MonitoringHandler {
|
||
|
|
return &MonitoringHandler{store: store}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Summary GET /admin/monitoring/summary
|
||
|
|
func (h *MonitoringHandler) Summary(c *gin.Context) {
|
||
|
|
utils.Success(c, http.StatusOK, "", h.store.Summary())
|
||
|
|
}
|
||
|
|
|
||
|
|
// RecentRequests GET /admin/monitoring/requests?limit=100
|
||
|
|
func (h *MonitoringHandler) RecentRequests(c *gin.Context) {
|
||
|
|
limit := 100
|
||
|
|
if raw := c.Query("limit"); raw != "" {
|
||
|
|
if n, err := strconv.Atoi(raw); err == nil && n > 0 && n <= 1000 {
|
||
|
|
limit = n
|
||
|
|
}
|
||
|
|
}
|
||
|
|
utils.Success(c, http.StatusOK, "", h.store.Recent(limit))
|
||
|
|
}
|