diff options
-rw-r--r-- | api4/post.go | 12 | ||||
-rw-r--r-- | model/client4.go | 4 |
2 files changed, 6 insertions, 10 deletions
diff --git a/api4/post.go b/api4/post.go index 65a508df7..3d1077358 100644 --- a/api4/post.go +++ b/api4/post.go @@ -277,18 +277,14 @@ func searchPosts(c *Context, w http.ResponseWriter, r *http.Request) { return } - props := model.MapFromJson(r.Body) - terms := props["terms"] - - if len(terms) == 0 { + props := model.StringInterfaceFromJson(r.Body) + terms, ok := props["terms"].(string) + if !ok || len(terms) == 0 { c.SetInvalidParam("terms") return } - isOrSearch := false - if val, ok := props["is_or_search"]; ok && val != "" { - isOrSearch, _ = strconv.ParseBool(val) - } + isOrSearch, _ := props["is_or_search"].(bool) posts, err := app.SearchPostsInTeam(terms, c.Session.UserId, c.Params.TeamId, isOrSearch) if err != nil { diff --git a/model/client4.go b/model/client4.go index 8ca227589..89fed55ff 100644 --- a/model/client4.go +++ b/model/client4.go @@ -1684,8 +1684,8 @@ func (c *Client4) GetPostsBefore(channelId, postId string, page, perPage int, et // SearchPosts returns any posts with matching terms string. func (c *Client4) SearchPosts(teamId string, terms string, isOrSearch bool) (*PostList, *Response) { - requestBody := map[string]string{"terms": terms, "is_or_search": strconv.FormatBool(isOrSearch)} - if r, err := c.DoApiPost(c.GetTeamRoute(teamId)+"/posts/search", MapToJson(requestBody)); err != nil { + requestBody := map[string]interface{}{"terms": terms, "is_or_search": isOrSearch} + if r, err := c.DoApiPost(c.GetTeamRoute(teamId)+"/posts/search", StringInterfaceToJson(requestBody)); err != nil { return nil, BuildErrorResponse(r, err) } else { defer closeBody(r) |