Skip to content

Commit

Permalink
Add '.query{}' params to search results API.
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Nov 30, 2023
1 parent f42e2bc commit b4eb5ad
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions cmd/dictpress/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,24 @@ import (

// results represents a set of results.
type results struct {
FromLang string `json:"-"`
ToLang string `json:"-"`
Entries []data.Entry `json:"entries"`
Entries []data.Entry `json:"entries"`

Query struct {
Query string `json:"query"`
FromLang string `json:"from_lang"`
ToLang string `json:"to_lang"`
Types []string `json:"types"`
Tags []string `json:"tags"`
} `json:"query"`

// Pagination fields.
paginator.Set
}

// glossary represents a set of glossary words.
type glossary struct {
FromLang string `json:"-"`
ToLang string `json:"-"`
FromLang string `json:"from_lang"`
ToLang string `json:"to_lang"`
Words []data.GlossaryWord `json:"entries"`

// Pagination fields.
Expand Down Expand Up @@ -164,6 +170,19 @@ func doSearch(c echo.Context, isAuthed bool) (data.Query, *results, error) {

pg.SetTotal(total)

out.Query.FromLang = fromLang
out.Query.ToLang = toLang
out.Query.Types = qp["type"]
out.Query.Tags = qp["tag"]
out.Query.Query = q

if out.Query.Types == nil {
out.Query.Types = []string{}
}
if out.Query.Tags == nil {
out.Query.Tags = []string{}
}

out.Entries = res
out.Page = pg.Page
out.PerPage = pg.PerPage
Expand Down

0 comments on commit b4eb5ad

Please sign in to comment.