refine architecture
change module name to repo
This commit is contained in:
73
internal/models/beads.go
Normal file
73
internal/models/beads.go
Normal file
@@ -0,0 +1,73 @@
|
||||
package models
|
||||
|
||||
import "github.com/steveyegge/beads"
|
||||
|
||||
type (
|
||||
Issue = beads.Issue
|
||||
Status = beads.Status
|
||||
IssueType = beads.IssueType
|
||||
Dependency = beads.Dependency
|
||||
DependencyType = beads.DependencyType
|
||||
Label = beads.Label
|
||||
Comment = beads.Comment
|
||||
Event = beads.Event
|
||||
EventType = beads.EventType
|
||||
BlockedIssue = beads.BlockedIssue
|
||||
TreeNode = beads.TreeNode
|
||||
IssueFilter = beads.IssueFilter
|
||||
WorkFilter = beads.WorkFilter
|
||||
StaleFilter = beads.StaleFilter
|
||||
DependencyCounts = beads.DependencyCounts
|
||||
IssueWithCounts = beads.IssueWithCounts
|
||||
SortPolicy = beads.SortPolicy
|
||||
EpicStatus = beads.EpicStatus
|
||||
)
|
||||
|
||||
// Status constants
|
||||
const (
|
||||
StatusOpen = beads.StatusOpen
|
||||
StatusInProgress = beads.StatusInProgress
|
||||
StatusBlocked = beads.StatusBlocked
|
||||
StatusDeferred = beads.StatusDeferred
|
||||
StatusClosed = beads.StatusClosed
|
||||
)
|
||||
|
||||
// IssueType constants
|
||||
const (
|
||||
TypeBug = beads.TypeBug
|
||||
TypeFeature = beads.TypeFeature
|
||||
TypeTask = beads.TypeTask
|
||||
TypeEpic = beads.TypeEpic
|
||||
TypeChore = beads.TypeChore
|
||||
)
|
||||
|
||||
// DependencyType constants
|
||||
const (
|
||||
DepBlocks = beads.DepBlocks
|
||||
DepRelated = beads.DepRelated
|
||||
DepParentChild = beads.DepParentChild
|
||||
DepDiscoveredFrom = beads.DepDiscoveredFrom
|
||||
DepConditionalBlocks = beads.DepConditionalBlocks // B runs only if A fails (bd-kzda)
|
||||
)
|
||||
|
||||
// SortPolicy constants
|
||||
const (
|
||||
SortPolicyHybrid = beads.SortPolicyHybrid
|
||||
SortPolicyPriority = beads.SortPolicyPriority
|
||||
SortPolicyOldest = beads.SortPolicyOldest
|
||||
)
|
||||
|
||||
// EventType constants
|
||||
const (
|
||||
EventCreated = beads.EventCreated
|
||||
EventUpdated = beads.EventUpdated
|
||||
EventStatusChanged = beads.EventStatusChanged
|
||||
EventCommented = beads.EventCommented
|
||||
EventClosed = beads.EventClosed
|
||||
EventReopened = beads.EventReopened
|
||||
EventDependencyAdded = beads.EventDependencyAdded
|
||||
EventDependencyRemoved = beads.EventDependencyRemoved
|
||||
EventLabelAdded = beads.EventLabelAdded
|
||||
EventLabelRemoved = beads.EventLabelRemoved
|
||||
EventCompacted = beads.EventCompacted
|
||||
)
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
)
|
||||
|
||||
type Storage[T any] struct {
|
||||
path string
|
||||
mu sync.RWMutex
|
||||
path string
|
||||
Data *T
|
||||
}
|
||||
|
||||
@@ -51,4 +51,4 @@ func (s *Storage[T]) Init() error {
|
||||
return s.Save()
|
||||
}
|
||||
return s.Load()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user