Files
spellbook/internal/application/application.go
T
abelith 478ac2fc7b chore
- application struct
2026-08-03 04:49:59 +05:00

62 lines
1.3 KiB
Go

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)
}