diff --git a/internal/application/application.go b/internal/application/application.go new file mode 100644 index 0000000..3276ea7 --- /dev/null +++ b/internal/application/application.go @@ -0,0 +1,61 @@ +package application + +import ( + "context" + "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 (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) +} diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go new file mode 100644 index 0000000..1ec4eb5 --- /dev/null +++ b/internal/handlers/handlers.go @@ -0,0 +1,14 @@ +package handlers + +import ( + "context" + "spellbook/internal/models" +) + +type Application interface { + AddSpell(ctx context.Context, spell models.Spell) error + GetSpell(ctx context.Context, spellName string) (models.Spell, error) + GetSpells(ctx context.Context, query models.SearchQuery) ([]models.Spell, error) + DeleteSpell(ctx context.Context, spellName string) error + CastSpell(ctx context.Context, spellCast models.SpellCast) (models.CastResult, error) +} diff --git a/internal/models/models.go b/internal/models/models.go new file mode 100644 index 0000000..6eafe88 --- /dev/null +++ b/internal/models/models.go @@ -0,0 +1,31 @@ +package models + +import ( + "io" + "time" +) + +type Spell struct { + Name string + Spell string + Tags []string +} + +type SpellCast struct { + Spell Spell + Args map[string]string + Stdout io.Writer + Stderr io.Writer +} + +type CastResult struct { + ExitCode int + Duration time.Duration + Meta map[string]any +} + +type SearchQuery struct { + Cursor int + Limit int + Tags []string +}