refine architecture
change module name to repo
This commit is contained in:
@@ -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{})
|
||||
}
|
||||
|
||||
63
internal/service/service.go
Normal file
63
internal/service/service.go
Normal 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()
|
||||
}
|
||||
}
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user