lots of changes and reducing dependency imports
This commit is contained in:
@@ -10,12 +10,13 @@ import (
|
||||
"github.com/LazyBachelor/LazyPM/internal/models"
|
||||
"github.com/LazyBachelor/LazyPM/internal/storage"
|
||||
"github.com/charmbracelet/huh"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/steveyegge/beads"
|
||||
)
|
||||
|
||||
func NewServices(ctx context.Context, config Config) (*App, func(), error) {
|
||||
type App = models.App
|
||||
type Config = models.Config
|
||||
|
||||
func NewApp(ctx context.Context, config Config) (*App, func(), error) {
|
||||
var cleanupFuncs []func()
|
||||
|
||||
if !config.AutoInit {
|
||||
@@ -31,14 +32,14 @@ func NewServices(ctx context.Context, config Config) (*App, func(), error) {
|
||||
}
|
||||
cleanupFuncs = append(cleanupFuncs, func() { store.Close() })
|
||||
|
||||
beadsSvc, err := NewBeadsService(ctx, store, config.IssuePrefix)
|
||||
beadsSvc, err := storage.NewBeadsIssueStorage(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(),
|
||||
ID: 0,
|
||||
StartTime: time.Now(),
|
||||
})
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/internal/models"
|
||||
|
||||
"github.com/steveyegge/beads"
|
||||
)
|
||||
|
||||
type BeadsService struct {
|
||||
beads.Storage
|
||||
}
|
||||
|
||||
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 {
|
||||
return nil, fmt.Errorf("failed to set issue_prefix: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return &BeadsService{
|
||||
Storage: storage,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *BeadsService) AllIssues(ctx context.Context) ([]models.Issue, error) {
|
||||
issuesPtr, err := s.Storage.SearchIssues(ctx, "", models.IssueFilter{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(issuesPtr) == 0 {
|
||||
return []models.Issue{}, nil
|
||||
}
|
||||
|
||||
issues := models.IssuesPtrToIssues(issuesPtr)
|
||||
|
||||
return issues, nil
|
||||
}
|
||||
|
||||
func (s *BeadsService) DeleteIssues() error {
|
||||
|
||||
var deleteIssues = "DELETE FROM issues;"
|
||||
|
||||
if _, err := s.UnderlyingDB().Exec(deleteIssues); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package service
|
||||
|
||||
type Config struct {
|
||||
AutoInit bool
|
||||
RootCmd string
|
||||
WebAddress string
|
||||
BeadsDBPath string
|
||||
IssuePrefix string
|
||||
StatisticsStoragePath string
|
||||
}
|
||||
|
||||
var BaseConfig = Config{
|
||||
AutoInit: false,
|
||||
RootCmd: "pm",
|
||||
IssuePrefix: "pm",
|
||||
WebAddress: ":8080",
|
||||
BeadsDBPath: "./.pm/db.db",
|
||||
StatisticsStoragePath: "./.pm/stats.json",
|
||||
}
|
||||
|
||||
func (c Config) WithAutoInit(autoInit bool) Config {
|
||||
c.AutoInit = autoInit
|
||||
return c
|
||||
}
|
||||
|
||||
func (c Config) WithRootCmd(rootCmd string) Config {
|
||||
c.RootCmd = rootCmd
|
||||
return c
|
||||
}
|
||||
|
||||
func (c Config) WithWebAddress(webAddress string) Config {
|
||||
c.WebAddress = webAddress
|
||||
return c
|
||||
}
|
||||
|
||||
func (c Config) WithBeadsDBPath(beadsDBPath string) Config {
|
||||
c.BeadsDBPath = beadsDBPath
|
||||
return c
|
||||
}
|
||||
|
||||
func (c Config) WithIssuePrefix(issuePrefix string) Config {
|
||||
c.IssuePrefix = issuePrefix
|
||||
return c
|
||||
}
|
||||
|
||||
func (c Config) WithStatisticsStoragePath(path string) Config {
|
||||
c.StatisticsStoragePath = path
|
||||
return c
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log/slog"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/internal/models"
|
||||
"github.com/steveyegge/beads"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
Config Config
|
||||
Issues IssueService
|
||||
Stats StatsService
|
||||
|
||||
Logger *slog.Logger
|
||||
|
||||
CurrentFeedback *ValidationFeedback
|
||||
}
|
||||
|
||||
type IssueService interface {
|
||||
beads.Storage
|
||||
AllIssues(ctx context.Context) ([]models.Issue, error)
|
||||
DeleteIssues() error
|
||||
}
|
||||
|
||||
type StatsService interface {
|
||||
Load(ctx context.Context) error
|
||||
Save(ctx context.Context) error
|
||||
GetStatistics() (models.Statistics, error)
|
||||
}
|
||||
|
||||
type ValidationFeedback struct {
|
||||
Success bool
|
||||
Message string
|
||||
}
|
||||
Reference in New Issue
Block a user