able to get product
This commit is contained in:
@ -6,8 +6,8 @@ import (
|
||||
"log/slog"
|
||||
"strconv"
|
||||
|
||||
"git.loyso.art/frx/kurious/internal/domain"
|
||||
"git.loyso.art/frx/kurious/internal/infrastructure/interfaceadapters/courses/sravni"
|
||||
"git.loyso.art/frx/kurious/internal/common/client/sravni"
|
||||
"git.loyso.art/frx/kurious/internal/common/errors"
|
||||
|
||||
"github.com/teris-io/cli"
|
||||
)
|
||||
@ -25,12 +25,14 @@ func setupAPICommand(ctx context.Context) cli.Command {
|
||||
WithChar('t').
|
||||
WithType(cli.TypeString)
|
||||
|
||||
apiEducationListProducts := cli.NewCommand("list_products", "List products by some filters").
|
||||
WithOption(learningTypeOpt).
|
||||
WithOption(courseThematic).
|
||||
WithOption(limitOption).
|
||||
WithOption(offsetOption).
|
||||
WithAction(newListProductAction(ctx))
|
||||
apiEducationListProducts := buildCLICommand(func() cli.Command {
|
||||
return cli.NewCommand("list_products", "List products by some filters").
|
||||
WithOption(learningTypeOpt).
|
||||
WithOption(courseThematic).
|
||||
WithOption(limitOption).
|
||||
WithOption(offsetOption).
|
||||
WithAction(newListProductAction(ctx))
|
||||
})
|
||||
|
||||
apiEducation := cli.NewCommand("education", "Education related category").
|
||||
WithCommand(apiEducationListProducts)
|
||||
@ -64,36 +66,6 @@ func asCLIAction(a action) cli.Action {
|
||||
}
|
||||
}
|
||||
|
||||
type baseAction struct {
|
||||
ctx context.Context
|
||||
client sravni.Client
|
||||
log *slog.Logger
|
||||
}
|
||||
|
||||
func (ba *baseAction) parse(_ []string, options map[string]string) (err error) {
|
||||
ba.log = makeLogger(options).With(slog.String("component", "action"))
|
||||
ba.client, err = makeSravniClient(ba.ctx, ba.log, options)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (ba *baseAction) handle() error {
|
||||
return domain.ErrNotImplemented
|
||||
}
|
||||
|
||||
func (ba baseAction) context() context.Context {
|
||||
return ba.ctx
|
||||
}
|
||||
|
||||
func newBaseAction(ctx context.Context) *baseAction {
|
||||
return &baseAction{
|
||||
ctx: ctx,
|
||||
}
|
||||
}
|
||||
|
||||
type listProductsActionParams struct {
|
||||
learningType string
|
||||
courseThematic string
|
||||
@ -104,6 +76,7 @@ type listProductsActionParams struct {
|
||||
type listProductsAction struct {
|
||||
*baseAction
|
||||
|
||||
client sravni.Client
|
||||
params listProductsActionParams
|
||||
}
|
||||
|
||||
@ -125,11 +98,11 @@ func (a *listProductsAction) parse(args []string, options map[string]string) err
|
||||
|
||||
a.params.learningType, ok = options[learningTypeOptName]
|
||||
if !ok {
|
||||
return domain.SimpleError("learning_type is empty")
|
||||
return errors.SimpleError("learning_type is empty")
|
||||
}
|
||||
a.params.courseThematic, ok = options[courseThematicOptName]
|
||||
if !ok {
|
||||
return domain.SimpleError("course_thematic is empty")
|
||||
return errors.SimpleError("course_thematic is empty")
|
||||
}
|
||||
|
||||
if value, ok := options[limitOption.Key()]; ok {
|
||||
@ -139,6 +112,13 @@ func (a *listProductsAction) parse(args []string, options map[string]string) err
|
||||
a.params.offset, _ = strconv.Atoi(value)
|
||||
}
|
||||
|
||||
client, err := makeSravniClient(a.ctx, a.log, options)
|
||||
if err != nil {
|
||||
return fmt.Errorf("making sravni client: %w", err)
|
||||
}
|
||||
|
||||
a.client = client
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user