Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion hub-server/internal/app/wiring.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/agenthub/hub-server/internal/service/message"
"github.com/agenthub/hub-server/internal/service/messagereaction"
"github.com/agenthub/hub-server/internal/service/oidc"
"github.com/agenthub/hub-server/internal/service/publicstats"
"github.com/agenthub/hub-server/internal/service/session"
"github.com/agenthub/hub-server/internal/service/workspace"
)
Expand Down Expand Up @@ -244,7 +245,7 @@ func (a *App) initHandlers(_ context.Context) error {
a.AttachmentHandler = handler.NewAttachmentHandler(a.AttachmentService)
a.NotificationHandler = handler.NewNotificationHandler(a.NotificationService)
a.HealthHandler = handler.NewHealthHandler(a.DB, a.CacheClient, &a.Config.DB, a.startTime, a.Version)
pubStatsSvc := service.NewPublicStatsService(a.DB)
pubStatsSvc := publicstats.NewPublicStatsService(a.DB)
a.PublicHandler = handler.NewPublicHandler(pubStatsSvc, a.startTime)

return nil
Expand Down
6 changes: 3 additions & 3 deletions hub-server/internal/handler/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/gin-gonic/gin"

"github.com/agenthub/hub-server/internal/service"
"github.com/agenthub/hub-server/internal/service/publicstats"
)

// PublicStats is the response body for GET /api/public/stats.
Expand All @@ -20,13 +20,13 @@ type PublicStats struct {

// PublicHandler serves unauthenticated public endpoints for the website.
type PublicHandler struct {
statsSvc *service.PublicStatsService
statsSvc *publicstats.PublicStatsService
startTime time.Time
}

// NewPublicHandler creates a PublicHandler.
// startTime should be the moment App.Run was called.
func NewPublicHandler(statsSvc *service.PublicStatsService, startTime time.Time) *PublicHandler {
func NewPublicHandler(statsSvc *publicstats.PublicStatsService, startTime time.Time) *PublicHandler {
return &PublicHandler{statsSvc: statsSvc, startTime: startTime}
}

Expand Down
4 changes: 2 additions & 2 deletions hub-server/internal/handler/public_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

"github.com/agenthub/hub-server/internal/handler"
"github.com/agenthub/hub-server/internal/model"
"github.com/agenthub/hub-server/internal/service"
"github.com/agenthub/hub-server/internal/service/publicstats"
)

func TestPublicStatsBucketsCountsAndUptime(t *testing.T) {
Expand All @@ -43,7 +43,7 @@ func TestPublicStatsBucketsCountsAndUptime(t *testing.T) {
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Request = httptest.NewRequest(http.MethodGet, "/api/public/stats", nil)
statsSvc := service.NewPublicStatsService(db)
statsSvc := publicstats.NewPublicStatsService(db)
h := handler.NewPublicHandler(statsSvc, time.Now().Add(-25*time.Hour-13*time.Minute))

h.Stats(c)
Expand Down
9 changes: 9 additions & 0 deletions hub-server/internal/service/publicstats/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Package publicstats holds the public-facing statistics service for Hub.
//
// PublicStatsService serves aggregate counts (users, agents, online agents,
// messages) to the public stats endpoint. It neither uses nor is used by any
// sibling of the flat service package, so it is the first low-coupling domain
// grouped into a subpackage.
//
// See #1761.
package publicstats
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package service
package publicstats

import (
"gorm.io/gorm"
Expand Down
3 changes: 2 additions & 1 deletion hub-server/tests/integration/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"github.com/agenthub/hub-server/internal/service/message"
"github.com/agenthub/hub-server/internal/service/messagereaction"
"github.com/agenthub/hub-server/internal/service/oidc"
"github.com/agenthub/hub-server/internal/service/publicstats"
"github.com/agenthub/hub-server/internal/service/session"
"github.com/agenthub/hub-server/internal/testkit"
"github.com/agenthub/hub-server/internal/ws"
Expand Down Expand Up @@ -144,7 +145,7 @@ func TestMain(m *testing.M) {
notificationService := service.NewNotificationService(db, mgr)
notificationHandler := handler.NewNotificationHandler(notificationService)
healthHandler := handler.NewHealthHandler(db, cacheClient, &cfg.DB, time.Now(), "test")
publicHandler := handler.NewPublicHandler(service.NewPublicStatsService(db), time.Now())
publicHandler := handler.NewPublicHandler(publicstats.NewPublicStatsService(db), time.Now())

// Phase 1-7 handlers
// config.yaml ships production-empty TokenDance ID values (client_id "",
Expand Down
Loading