add builders and chaining methods for various types and variables for better reusability and readability

This commit is contained in:
Robin Olsen
2026-02-19 17:26:16 +01:00
parent 2e702e799d
commit 0f41f76679
10 changed files with 179 additions and 68 deletions

64
internal/models/issue.go Normal file
View File

@@ -0,0 +1,64 @@
package models
type IssueBuilder struct {
ID string
Title string
Description string
Status Status
IssueType IssueType
Priority int
}
func NewIssueBuilder() *IssueBuilder {
return &IssueBuilder{}
}
func NewBaseIssue() *IssueBuilder {
return NewIssueBuilder().
WithID("pm-abc").
WithTitle("Basic Issue").
WithDescription("Basic Description").
WithIssueType(TypeTask).
WithStatus(StatusOpen)
}
func (b *IssueBuilder) WithID(id string) *IssueBuilder {
b.ID = id
return b
}
func (b *IssueBuilder) WithTitle(title string) *IssueBuilder {
b.Title = title
return b
}
func (b *IssueBuilder) WithDescription(description string) *IssueBuilder {
b.Description = description
return b
}
func (b *IssueBuilder) WithStatus(status Status) *IssueBuilder {
b.Status = status
return b
}
func (b *IssueBuilder) WithIssueType(issueType IssueType) *IssueBuilder {
b.IssueType = issueType
return b
}
func (b *IssueBuilder) WithPriority(priority int) *IssueBuilder {
b.Priority = priority
return b
}
func (b IssueBuilder) Build() Issue {
return Issue{
ID: b.ID,
Title: b.Title,
Description: b.Description,
Status: b.Status,
IssueType: b.IssueType,
Priority: b.Priority,
}
}

View File

@@ -41,3 +41,13 @@ func (s *BeadsService) AllIssues(ctx context.Context) ([]models.Issue, error) {
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
}

View File

@@ -0,0 +1,34 @@
package service
type Config struct {
RootCmd string
WebAddress string
BeadsDBPath string
IssuePrefix string
StatisticsStoragePath string
}
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
}