From a9c51dba338731f437979b8a2a040e2acb0513f3 Mon Sep 17 00:00:00 2001 From: Arsen Musayelyan Date: Sat, 10 Dec 2022 12:07:19 -0800 Subject: [PATCH] Add search endpoint --- search.go | 23 +++++++++++++++++++++++ types/site.go | 12 ++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 search.go diff --git a/search.go b/search.go new file mode 100644 index 0000000..df88ddc --- /dev/null +++ b/search.go @@ -0,0 +1,23 @@ +package lemmy + +import ( + "context" + "net/http" + + "go.arsenm.dev/go-lemmy/types" +) + +func (c *Client) Search(ctx context.Context, d types.Search) (*types.SearchResponse, error) { + ar := &types.SearchResponse{} + res, err := c.getReq(ctx, http.MethodGet, "/search", d, &ar) + if err != nil { + return nil, err + } + + err = resError(res, ar.LemmyResponse) + if err != nil { + return nil, err + } + + return ar, nil +} diff --git a/types/site.go b/types/site.go index 9e56c21..f3d921a 100644 --- a/types/site.go +++ b/types/site.go @@ -1,5 +1,17 @@ package types +type Search struct { + CommunityID Optional[int] `json:"community_id" url:"community_id"` + CommunityName Optional[string] `json:"community_name" url:"community_name"` + CreatorID Optional[int] `json:"creator_id" url:"creator_id"` + Limit Optional[int] `json:"limit" url:"limit"` + ListingType Optional[ListingType] `json:"listing_type" url:"listing_type"` + Page Optional[int] `json:"page" url:"page"` + Query string `json:"q" url:"q"` + Sort Optional[SortType] `json:"sort" url:"sort"` + Type Optional[SearchType] `json:"type_" url:"type_"` +} + type SearchResponse struct { Type string `json:"type,omitempty" url:"type,omitempty"` Comments []CommentView `json:"comments,omitempty" url:"comments,omitempty"`