add statistics storage
This commit is contained in:
@@ -1,13 +1,27 @@
|
||||
package service
|
||||
|
||||
import "beadstest/internal/storage"
|
||||
import (
|
||||
"beadstest/internal/models"
|
||||
"beadstest/internal/storage"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type StatisticsService struct {
|
||||
storage *storage.StatisticsStorage
|
||||
storage *storage.Storage[models.Statistics]
|
||||
}
|
||||
|
||||
func NewStatisticsService(storage *storage.StatisticsStorage) *StatisticsService {
|
||||
func NewStatisticsService(storage *storage.Storage[models.Statistics]) (*StatisticsService, error) {
|
||||
if err := storage.Init(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &StatisticsService{
|
||||
storage: storage,
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *StatisticsService) GetStatistics() (models.Statistics, error) {
|
||||
if s.storage.Data == nil {
|
||||
return models.Statistics{}, errors.New("statistics data not initialized")
|
||||
}
|
||||
return *s.storage.Data, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user