setup parser
This commit is contained in:
@ -11,6 +11,7 @@ import (
|
||||
|
||||
"git.loyso.art/frx/kurious/internal/common/errors"
|
||||
"git.loyso.art/frx/kurious/pkg/slices"
|
||||
"git.loyso.art/frx/kurious/pkg/xdefault"
|
||||
|
||||
"github.com/go-resty/resty/v2"
|
||||
"golang.org/x/net/html"
|
||||
@ -76,6 +77,7 @@ type ListEducationProductsParams struct {
|
||||
LearningType string
|
||||
CoursesThematics string
|
||||
|
||||
SortBy string
|
||||
Limit int
|
||||
Offset int
|
||||
}
|
||||
@ -116,6 +118,8 @@ func (c *client) ListEducationalProducts(
|
||||
const defaultLimit = 1
|
||||
const defaultSortProp = "advertising.position"
|
||||
const defaultSortDirection = "asc"
|
||||
// TODO: find out should it be settable
|
||||
const productName = "learning-courses"
|
||||
if err = c.checkClientInited(); err != nil {
|
||||
return result, err
|
||||
}
|
||||
@ -123,33 +127,28 @@ func (c *client) ListEducationalProducts(
|
||||
if !c.validLearningTypes.hasValue(params.LearningType) {
|
||||
return result, errors.NewValidationError("learning_type", "bad value")
|
||||
}
|
||||
if !c.validCourseThematics.hasValue(params.CoursesThematics) {
|
||||
if params.CoursesThematics != "" && !c.validCourseThematics.hasValue(params.CoursesThematics) {
|
||||
return result, errors.NewValidationError("courses_thematics", "bad value")
|
||||
}
|
||||
|
||||
reqParams := ListEducationProductsRequest{
|
||||
LearningType: []string{
|
||||
params.LearningType,
|
||||
},
|
||||
CoursesThematics: []string{
|
||||
params.CoursesThematics,
|
||||
},
|
||||
LearningType: valueAsArray(params.LearningType),
|
||||
CoursesThematics: valueAsArray(params.CoursesThematics),
|
||||
ProductName: productName,
|
||||
Fields: defaultProductFields,
|
||||
SortProperty: defaultSortProp, // mayber sort by price?
|
||||
SortDirection: defaultSortDirection,
|
||||
NotSubIsWebinar: strconv.FormatBool(true),
|
||||
NotB2B: strconv.FormatBool(true),
|
||||
IsMix: false, // not sure why, but for better parsing
|
||||
MixRepeated: true, // looks like this option should force to exclude duplicates
|
||||
AdvertisingOnly: false, // If true, it will show only paid items.
|
||||
Location: "", // TODO: get and fill location?
|
||||
Fingerprint: "", // not sure it should be set.
|
||||
OfferTypes: []string{}, // for more precise filter but not needed.
|
||||
|
||||
Fields: defaultProductFields,
|
||||
SortProperty: defaultSortProp, // mayber sort by price?
|
||||
SortDirection: defaultSortDirection,
|
||||
NotSubIsWebinar: strconv.FormatBool(true),
|
||||
NotB2B: strconv.FormatBool(true),
|
||||
IsMix: true, // not sure why, but for better parsing
|
||||
MixRepeated: true, // looks like this option should force to exclude duplicates
|
||||
AdvertisingOnly: false, // If true, it will show only paid items.
|
||||
Location: "", // TODO: get and fill location?
|
||||
Fingerprint: "", // not sure it should be set.
|
||||
ProductName: "", // looks like it does not affects anything
|
||||
OfferTypes: nil, // for more precise filter but not needed.
|
||||
|
||||
Limit: defaultLimit,
|
||||
Offset: 0,
|
||||
Limit: xdefault.WithFallback(params.Limit, defaultLimit),
|
||||
Offset: params.Offset,
|
||||
}
|
||||
|
||||
req := c.http.R().
|
||||
@ -353,17 +352,6 @@ func (qs querySet) exactSubset(values ...string) ([]string, error) {
|
||||
|
||||
}
|
||||
|
||||
// func (qs querySet) subset(values ...string) []string {
|
||||
// out := make([]string, 0, len(values))
|
||||
// for _, value := range values {
|
||||
// if qs.hasValue(value) {
|
||||
// out = append(out, value)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return out
|
||||
// }
|
||||
|
||||
func newQuerySet(values ...string) querySet {
|
||||
qs := querySet{
|
||||
values: make([]string, len(values)),
|
||||
@ -377,3 +365,11 @@ func newQuerySet(values ...string) querySet {
|
||||
|
||||
return qs
|
||||
}
|
||||
|
||||
func valueAsArray(value string) []string {
|
||||
if value == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
return []string{value}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user