add show course and map names
This commit is contained in:
@ -13,6 +13,7 @@ import (
|
||||
"git.loyso.art/frx/kurious/internal/common/config"
|
||||
"git.loyso.art/frx/kurious/internal/common/xcontext"
|
||||
"git.loyso.art/frx/kurious/internal/common/xlog"
|
||||
"git.loyso.art/frx/kurious/internal/kurious/adapters"
|
||||
"git.loyso.art/frx/kurious/internal/kurious/ports"
|
||||
"git.loyso.art/frx/kurious/internal/kurious/service"
|
||||
)
|
||||
@ -43,19 +44,39 @@ func app(ctx context.Context) error {
|
||||
|
||||
log := config.NewSLogger(cfg.Log)
|
||||
|
||||
app, err := service.NewApplication(ctx, service.ApplicationConfig{
|
||||
LogConfig: cfg.Log,
|
||||
YDB: cfg.YDB,
|
||||
})
|
||||
if err != nil {
|
||||
return fmt.Errorf("making new application: %w", err)
|
||||
}
|
||||
|
||||
sravniClient, err := sravni.NewClient(ctx, log, cfg.DebugHTTP)
|
||||
if err != nil {
|
||||
return fmt.Errorf("making sravni client: %w", err)
|
||||
}
|
||||
|
||||
mainPageState, err := sravniClient.GetMainPageState()
|
||||
if err != nil {
|
||||
return fmt.Errorf("getting main page state: %w", err)
|
||||
}
|
||||
|
||||
dictionaries := mainPageState.Props.InitialReduxState.Dictionaries.Data
|
||||
|
||||
dictFieldsAsMap := func(fields ...sravni.Field) map[string]string {
|
||||
out := make(map[string]string, len(fields))
|
||||
for _, field := range fields {
|
||||
out[field.Value] = field.Name
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
courseThematcisMapped := dictFieldsAsMap(dictionaries.CourseThematics.Fields...)
|
||||
learningTypeMapped := dictFieldsAsMap(dictionaries.LearningType.Fields...)
|
||||
|
||||
mapper := adapters.NewMemoryMapper(courseThematcisMapped, learningTypeMapped)
|
||||
|
||||
app, err := service.NewApplication(ctx, service.ApplicationConfig{
|
||||
LogConfig: cfg.Log,
|
||||
YDB: cfg.YDB,
|
||||
}, mapper)
|
||||
if err != nil {
|
||||
return fmt.Errorf("making new application: %w", err)
|
||||
}
|
||||
|
||||
bgProcess := ports.NewBackgroundProcess(ctx, log)
|
||||
err = bgProcess.RegisterSyncSravniHandler(ctx, app, sravniClient, cfg.SyncSravniCron)
|
||||
if err != nil {
|
||||
|
||||
@ -9,7 +9,7 @@ import (
|
||||
|
||||
"git.loyso.art/frx/kurious/internal/common/client/sravni"
|
||||
"git.loyso.art/frx/kurious/internal/common/errors"
|
||||
"git.loyso.art/frx/kurious/internal/common/xslice"
|
||||
"git.loyso.art/frx/kurious/internal/common/xslices"
|
||||
|
||||
"github.com/teris-io/cli"
|
||||
)
|
||||
@ -188,7 +188,7 @@ func (a *productsFilterCountAction) parse(args []string, options map[string]stri
|
||||
filterNotEmpty := func(value string) bool {
|
||||
return value != ""
|
||||
}
|
||||
a.params.courseThematic = xslice.Filter(
|
||||
a.params.courseThematic = xslices.Filter(
|
||||
strings.Split(options[courseThematicOptName], ","),
|
||||
filterNotEmpty,
|
||||
)
|
||||
|
||||
@ -10,9 +10,11 @@ import (
|
||||
"os/signal"
|
||||
"time"
|
||||
|
||||
"git.loyso.art/frx/kurious/internal/common/client/sravni"
|
||||
"git.loyso.art/frx/kurious/internal/common/config"
|
||||
"git.loyso.art/frx/kurious/internal/common/generator"
|
||||
"git.loyso.art/frx/kurious/internal/common/xcontext"
|
||||
"git.loyso.art/frx/kurious/internal/kurious/adapters"
|
||||
xhttp "git.loyso.art/frx/kurious/internal/kurious/ports/http"
|
||||
"git.loyso.art/frx/kurious/internal/kurious/service"
|
||||
"golang.org/x/sync/errgroup"
|
||||
@ -46,10 +48,35 @@ func app(ctx context.Context) error {
|
||||
|
||||
log := config.NewSLogger(cfg.Log)
|
||||
|
||||
sravniClient, err := sravni.NewClient(ctx, log, false)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to make new sravni client: %w", err)
|
||||
}
|
||||
|
||||
mainPageState, err := sravniClient.GetMainPageState()
|
||||
if err != nil {
|
||||
return fmt.Errorf("getting main page state: %w", err)
|
||||
}
|
||||
|
||||
dictionaries := mainPageState.Props.InitialReduxState.Dictionaries.Data
|
||||
|
||||
dictFieldsAsMap := func(fields ...sravni.Field) map[string]string {
|
||||
out := make(map[string]string, len(fields))
|
||||
for _, field := range fields {
|
||||
out[field.Value] = field.Name
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
courseThematcisMapped := dictFieldsAsMap(dictionaries.CourseThematics.Fields...)
|
||||
learningTypeMapped := dictFieldsAsMap(dictionaries.LearningType.Fields...)
|
||||
|
||||
mapper := adapters.NewMemoryMapper(courseThematcisMapped, learningTypeMapped)
|
||||
|
||||
app, err := service.NewApplication(ctx, service.ApplicationConfig{
|
||||
LogConfig: cfg.Log,
|
||||
YDB: cfg.YDB,
|
||||
})
|
||||
}, mapper)
|
||||
if err != nil {
|
||||
return fmt.Errorf("making new application: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user