services

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package services provides reusable business logic interfaces for markata-go.

Overview

This package defines service interfaces that abstract the lifecycle.Manager and provide clean APIs for TUI, CLI, and future web interfaces. All services are designed to be stateless and thread-safe.

Service Architecture

┌─────────────────────────────────────────────────────────────────┐
│                    pkg/services/ (Business Logic)                │
│  ┌─────────────┐ ┌─────────────┐ ┌─────────────┐               │
│  │ PostService │ │ FeedService │ │BuildService │               │
│  └──────┬──────┘ └──────┬──────┘ └──────┬──────┘               │
│         │               │               │                       │
│         └───────────────┴───────────────┘                       │
│                         │                                        │
│              ┌──────────┴──────────┐                            │
│              │  lifecycle.Manager   │                           │
│              └─────────────────────┘                            │
└─────────────────────────────────────────────────────────────────┘

Usage

Create an App instance to access all services:

app, err := services.NewApp(manager)
if err != nil {
    return err
}

posts, err := app.Posts.List(ctx, services.ListOptions{
    Published: boolPtr(true),
    SortBy:    "date",
    Limit:     10,
})

Package services provides business logic interfaces that can be reused across TUI, CLI, and future web interfaces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	Posts PostService
	Feeds FeedService
	Tags  TagService
	Build BuildService

	// Manager is the underlying lifecycle manager (for advanced access)
	Manager *lifecycle.Manager
}

App bundles all services together for easy dependency injection.

func NewApp

func NewApp(manager *lifecycle.Manager) *App

NewApp creates a new App with all services initialized.

type BuildEvent

type BuildEvent struct {
	// Type is the event type
	Type BuildEventType

	// Stage is the current build stage
	Stage string

	// Message is the event message
	Message string

	// Progress is the progress percentage (0-100)
	Progress int

	// Error is the error if Type is BuildEventError
	Error error
}

BuildEvent represents a build progress event.

type BuildEventType

type BuildEventType string

BuildEventType identifies the type of build event.

const (
	BuildEventStart    BuildEventType = "start"
	BuildEventStage    BuildEventType = "stage"
	BuildEventProgress BuildEventType = "progress"
	BuildEventComplete BuildEventType = "complete"
	BuildEventError    BuildEventType = "error"
)

type BuildOptions

type BuildOptions struct {
	// Watch enables watch mode for continuous rebuilding
	Watch bool

	// Serve enables the development server
	Serve bool

	// Port is the server port (default: 8080)
	Port int

	// Clean removes output directory before building
	Clean bool

	// Concurrency sets parallel processing level
	Concurrency int
}

BuildOptions configures build operations.

type BuildResult

type BuildResult struct {
	// Success indicates if the build completed successfully
	Success bool

	// Duration is the build time
	Duration time.Duration

	// PostsProcessed is the number of posts processed
	PostsProcessed int

	// FilesWritten is the number of files written
	FilesWritten int

	// Errors contains any errors that occurred
	Errors []error

	// Warnings contains non-critical warnings
	Warnings []string
}

BuildResult contains the result of a build operation.

type BuildService

type BuildService interface {
	// Build runs the build process.
	Build(ctx context.Context, opts BuildOptions) (*BuildResult, error)

	// LoadOnly runs only the load stage (for TUI browsing without full build).
	LoadOnly(ctx context.Context) error

	// LoadForTUI runs through Collect stage for TUI browsing.
	// This includes Transform (for stats, titles) and Collect (for feeds).
	LoadForTUI(ctx context.Context) error

	// Subscribe returns a channel for build progress events.
	Subscribe() <-chan BuildEvent
}

BuildService provides build orchestration.

type DateRange

type DateRange struct {
	Start *time.Time
	End   *time.Time
}

DateRange defines a date range filter.

type FeedService

type FeedService interface {
	// List returns all configured feeds.
	List(ctx context.Context) ([]*lifecycle.Feed, error)

	// Get returns a single feed by name.
	Get(ctx context.Context, name string) (*lifecycle.Feed, error)

	// GetPosts returns posts belonging to a feed.
	GetPosts(ctx context.Context, feedName string, opts ListOptions) ([]*models.Post, error)
}

FeedService provides business logic for feed operations.

type ListOptions

type ListOptions struct {
	// Filter is a filter expression (same syntax as lifecycle.Manager.Filter)
	Filter string

	// Tags filters posts by tags (AND logic - post must have all tags)
	Tags []string

	// DateRange filters posts by date range
	DateRange *DateRange

	// Published filters by published status (nil = all)
	Published *bool

	// Draft filters by draft status (nil = all)
	Draft *bool

	// SortBy is the field to sort by (e.g., "date", "title")
	SortBy string

	// SortOrder is the sort direction (default: desc for date, asc for title)
	SortOrder SortOrder

	// Offset is the number of items to skip (for pagination)
	Offset int

	// Limit is the maximum number of items to return (0 = no limit)
	Limit int
}

ListOptions configures list operations.

type PostService

type PostService interface {
	// List returns posts matching the given options.
	List(ctx context.Context, opts ListOptions) ([]*models.Post, error)

	// Get returns a single post by path.
	Get(ctx context.Context, path string) (*models.Post, error)

	// Search returns posts matching a text query.
	Search(ctx context.Context, query string, opts SearchOptions) ([]*models.Post, error)

	// Count returns the total number of posts matching options.
	Count(ctx context.Context, opts ListOptions) (int, error)
}

PostService provides business logic for post operations.

type SearchOptions

type SearchOptions struct {
	// Fields to search in (default: title, description, content)
	Fields []string

	// CaseSensitive enables case-sensitive search
	CaseSensitive bool

	// Fuzzy enables fuzzy matching
	Fuzzy bool

	// Limit is the maximum number of results (0 = no limit)
	Limit int
}

SearchOptions configures search operations.

type SortOrder

type SortOrder string

SortOrder defines the sort direction.

const (
	SortAsc  SortOrder = "asc"
	SortDesc SortOrder = "desc"
)

type TagInfo

type TagInfo struct {
	// Name is the tag name
	Name string

	// Count is the number of posts with this tag
	Count int

	// Slug is the URL-safe version of the tag
	Slug string
}

TagInfo represents a tag with metadata.

type TagService

type TagService interface {
	// List returns all tags with their post counts.
	List(ctx context.Context) ([]TagInfo, error)

	// GetPosts returns posts with a specific tag.
	GetPosts(ctx context.Context, tag string, opts ListOptions) ([]*models.Post, error)
}

TagService provides business logic for tag operations.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL