add statistics storage

This commit is contained in:
Robin Olsen
2026-01-31 21:07:09 +01:00
parent a3a1d71325
commit 4225d202bb
10 changed files with 154 additions and 24 deletions

View File

@@ -3,13 +3,16 @@ package main
import (
"beadstest/cmd/web/routes"
"beadstest/cmd/web/server"
"beadstest/internal/models"
"beadstest/internal/service"
"beadstest/internal/storage"
"context"
"embed"
"fmt"
"os"
"time"
"github.com/google/uuid"
"github.com/steveyegge/beads"
)
@@ -27,15 +30,19 @@ func main() {
handleError(err, "Error initializing Beads service")
defer beadSvc.Close()
statStore := storage.NewStatisticsStorage("./stats.json")
statSvc := service.NewStatisticsService(statStore)
statStore := storage.NewJsonStorage("./.pm/stats.json", &models.Statistics{
ID: uuid.New(),
StartTime: time.Now(),
})
_ = statSvc // To avoid unused variable error; remove if statSvc is used
statSvc, err := service.NewStatisticsService(statStore)
handleError(err, "Error initializing Statistics service")
server := server.NewServer(server.Server{
Port: 8080,
Assets: assets,
Service: beadSvc,
Port: 8080,
Assets: assets,
Service: beadSvc,
StatisticsService: statSvc,
Routes: []server.Route{
{Pattern: "/", Component: routes.Index()},
},

View File

@@ -1,6 +1,7 @@
package server
import (
"beadstest/internal/service"
"embed"
"fmt"
"net/http"
@@ -10,10 +11,11 @@ import (
)
type Server struct {
Port int
Assets embed.FS
Routes []Route
Service beads.Storage
Port int
Assets embed.FS
Routes []Route
Service beads.Storage
StatisticsService *service.StatisticsService
}
// NewServer creates and configures a new HTTP server instance.