Files
spellbook/internal/application/application.go
T
abelith e4737ca179 feat
- main
chore
- minor changes
2026-08-04 01:16:32 +05:00

70 lines
1.5 KiB
Go

package application
import (
"context"
"github.com/abelith/spellbook/internal/models"
)
type SpellCaster interface {
Cast(ctx context.Context, cast models.SpellCast) (models.CastResult, error)
}
type SpellCommand interface {
Add(ctx context.Context, spell models.Spell) error
Delete(ctx context.Context, spellName string) error
}
type SpellQuery interface {
Get(ctx context.Context, spellName string) (models.Spell, error)
GetMany(ctx context.Context, query models.SearchQuery) ([]models.Spell, error)
}
type Application struct {
caster SpellCaster
spellCmd SpellCommand
spellQuery SpellQuery
}
func NewApplication(caster SpellCaster, cmd SpellCommand, query SpellQuery) *Application {
return &Application{
caster: caster,
spellCmd: cmd,
spellQuery: query,
}
}
func (a *Application) AddSpell(
ctx context.Context,
spell models.Spell,
) error {
return a.spellCmd.Add(ctx, spell)
}
func (a *Application) GetSpell(
ctx context.Context,
spellName string,
) (models.Spell, error) {
return a.spellQuery.Get(ctx, spellName)
}
func (a *Application) GetSpells(
ctx context.Context,
query models.SearchQuery,
) ([]models.Spell, error) {
return a.spellQuery.GetMany(ctx, query)
}
func (a *Application) DeleteSpell(
ctx context.Context,
spellName string,
) error {
return a.spellCmd.Delete(ctx, spellName)
}
func (a *Application) CastSpell(
ctx context.Context,
spellCast models.SpellCast,
) (models.CastResult, error) {
return a.caster.Cast(ctx, spellCast)
}