88 "github.com/MonkyMars/PWS/lib"
99 "github.com/MonkyMars/PWS/services"
1010 "github.com/MonkyMars/PWS/types"
11- "github.com/MonkyMars/PWS/workers"
1211 "github.com/gofiber/fiber/v3"
1312)
1413
1716 requestCount int64
1817)
1918
20- func GetSystemHealth (c fiber.Ctx ) error {
19+ type AppRoutes struct {}
20+
21+ func NewAppRoutes () * AppRoutes {
22+ return & AppRoutes {}
23+ }
24+
25+ func (ar * AppRoutes ) GetSystemHealth (c fiber.Ctx ) error {
2126 // Memory stats
2227 var memStats runtime.MemStats
2328 runtime .ReadMemStats (& memStats )
@@ -39,10 +44,7 @@ func GetSystemHealth(c fiber.Ctx) error {
3944 Status : status ,
4045 Message : message ,
4146 ApplicationUptime : lib .GetUptimeString (appStartTime ),
42- Services : map [string ]string {
43- "database" : dbStatus ,
44- "api" : "ok" ,
45- },
47+ DatabaseStatus : dbStatus ,
4648 Metrics : types.HealthMetrics {
4749 MemoryUsageMB : float64 (memStats .Alloc ) / 1024 / 1024 ,
4850 GoRoutines : runtime .NumGoroutine (),
@@ -51,34 +53,10 @@ func GetSystemHealth(c fiber.Ctx) error {
5153 })
5254}
5355
54- // GetAuditHealth returns the health status of the audit logging system
55- func GetAuditHealth (c fiber.Ctx ) error {
56- healthStatus := workers .HealthStatus ()
57-
58- status := "ok"
59- message := "Audit system operational"
60-
61- if ! healthStatus ["is_healthy" ].(bool ) {
62- status = "degraded"
63- message = "Audit system experiencing issues"
64- }
65-
66- if ! healthStatus ["worker_running" ].(bool ) {
67- status = "error"
68- message = "Audit worker not running"
69- }
70-
71- return response .Success (c , map [string ]any {
72- "status" : status ,
73- "message" : message ,
74- "details" : healthStatus ,
75- })
76- }
77-
7856// TODO: Add authentication middleware to protect this endpoint in production
7957// Thus making sure only authorized admins can access it
8058// Currently it's only available in development mode because of this issue
81- func GetDatabaseHealth (c fiber.Ctx ) error {
59+ func ( ar * AppRoutes ) GetDatabaseHealth (c fiber.Ctx ) error {
8260 now := time .Now ()
8361 if err := services .Ping (); err != nil {
8462 return response .ServiceUnavailable (c , "Database connection error: " + err .Error ())
@@ -91,6 +69,11 @@ func GetDatabaseHealth(c fiber.Ctx) error {
9169 })
9270}
9371
94- func NotFoundHandler (c fiber.Ctx ) error {
95- return response .NotFound (c , "The requested resource was not found." )
72+ func (ar * AppRoutes ) GetLogs (c fiber.Ctx ) error {
73+ auditService := services .NewAuditService ()
74+ logs , err := auditService .GetLogs ()
75+ if err != nil {
76+ return response .InternalServerError (c , "Failed to retrieve audit logs" )
77+ }
78+ return response .Success (c , logs )
9679}
0 commit comments