refine architecture

change module name to repo
This commit is contained in:
Robin Olsen
2026-02-02 11:22:20 +01:00
parent 4225d202bb
commit 0dcfe3989d
32 changed files with 822 additions and 114 deletions

View File

@@ -1,17 +1,18 @@
package service
import (
"github.com/LazyBachelor/LazyPM/internal/models"
"context"
"fmt"
"github.com/steveyegge/beads"
)
type Service struct {
type BeadsService struct {
beads.Storage
}
func NewService(ctx context.Context, storage beads.Storage, prefix string) (*Service, error) {
func NewBeadsService(ctx context.Context, storage beads.Storage, prefix string) (*BeadsService, error) {
issue_prefix, err := storage.GetConfig(ctx, "issue_prefix")
if err != nil || issue_prefix == "" {
if err := storage.SetConfig(ctx, "issue_prefix", prefix); err != nil {
@@ -20,7 +21,11 @@ func NewService(ctx context.Context, storage beads.Storage, prefix string) (*Ser
fmt.Println("Initialized with prefix:", prefix)
}
return &Service{
Storage: storage,
return &BeadsService{
Storage: storage,
}, nil
}
func (s *BeadsService) AllIssues(ctx context.Context) ([]*models.Issue, error) {
return s.Storage.SearchIssues(ctx, "", models.IssueFilter{})
}

View File

@@ -0,0 +1,63 @@
package service
import (
"github.com/LazyBachelor/LazyPM/internal/models"
"github.com/LazyBachelor/LazyPM/internal/storage"
"context"
"time"
"github.com/google/uuid"
"github.com/steveyegge/beads"
)
type Config struct {
WebAddress string
BeadsDBPath string
IssuePrefix string
StatisticsStoragePath string
}
type Services struct {
Config Config
Beads *BeadsService
Statistics *StatisticsService
}
func NewServices(ctx context.Context, config Config) (*Services, func(), error) {
var cleanupFuncs []func()
store, err := beads.NewSQLiteStorage(ctx, config.BeadsDBPath)
if err != nil {
return nil, nil, err
}
cleanupFuncs = append(cleanupFuncs, func() { store.Close() })
beadsSvc, err := NewBeadsService(ctx, store, config.IssuePrefix)
if err != nil {
return nil, nil, err
}
cleanupFuncs = append(cleanupFuncs, func() { beadsSvc.Close() })
statStore := storage.NewJsonStorage(config.StatisticsStoragePath, &models.Statistics{
ID: uuid.New(),
StartTime: time.Now(),
})
statSvc, err := NewStatisticsService(statStore)
if err != nil {
return nil, nil, err
}
return &Services{
Beads: beadsSvc,
Statistics: statSvc,
Config: config,
}, func() { runCleanup(cleanupFuncs) }, nil
}
func runCleanup(funcs []func()) {
for _, fn := range funcs {
fn()
}
}

View File

@@ -1,8 +1,8 @@
package service
import (
"beadstest/internal/models"
"beadstest/internal/storage"
"github.com/LazyBachelor/LazyPM/internal/models"
"github.com/LazyBachelor/LazyPM/internal/storage"
"errors"
)