Skip to content

Commit

Permalink
add support for query options
Browse files Browse the repository at this point in the history
  • Loading branch information
Vishwas Shashidhar committed Dec 8, 2021
1 parent a368ed1 commit fc9d0af
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 10 deletions.
40 changes: 33 additions & 7 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,28 @@ func (b *bullhornClient) QueryEntity(name string, query string, options QueryOpt
if err != nil {
return nil, nil, err
}
params := make(map[string]string)
params["fields"] = strings.Join(options.Fields[:], ",")

body := Query{Where: query}
count := 10
if options.Count != 0 {
count = options.Count
}
start := 0
if options.Start != 0 {
start = options.Start
}
body := Query{
Where: query,
Options: Options{
Fields: strings.Join(options.Fields[:], ","),
Count: count,
Start: start,
},
}
if options.OrderBy != "" {
body.Options.OrderBy = options.OrderBy
}
requestUrl := fmt.Sprintf("%s/query/%s", b.ApiUrl, name)
rr, cr, err := b.B.Call(requestUrl, "post", b.getHeaders(), params, body)
rr, cr, err := b.B.Call(requestUrl, "post", b.getHeaders(), nil, body)
if err != nil {
var bhErr Error
err := json.Unmarshal(rr.Body(), &bhErr)
Expand Down Expand Up @@ -293,10 +309,20 @@ func (b *bullhornClient) SearchEntity(name string, query string, options QueryOp
if options.Count != 0 {
count = options.Count
}
start := 0
if options.Start != 0 {
start = options.Start
}
body := Search{
Query: query,
Fields: strings.Join(options.Fields[:], ","),
Count: count,
Query: query,
Options: Options{
Fields: strings.Join(options.Fields[:], ","),
Count: count,
Start: start,
},
}
if options.OrderBy != "" {
body.Options.OrderBy = options.OrderBy
}
requestUrl := fmt.Sprintf("%s/search/%s", b.ApiUrl, name)
rr, cr, err := b.B.Call(requestUrl, "post", b.getHeaders(), nil, body)
Expand Down
13 changes: 10 additions & 3 deletions entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,21 @@ type Error struct {
Message string `json:"errorMessage"`
}

type Options struct {
Fields string `json:"fields"`
Start int `json:"start"`
Count int `json:"count"`
OrderBy string `json:"orderBy"`
}

type Query struct {
Where string `json:"where"`
Options
}

type Search struct {
Query string `json:"query"`
Fields string `json:"fields"`
Count int `json:"count"`
Query string `json:"query"`
Options
}

type Ping struct {
Expand Down

0 comments on commit fc9d0af

Please sign in to comment.