-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathautocomplete.go
38 lines (34 loc) · 1.08 KB
/
autocomplete.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package handler
import (
"github.com/USACE/instrumentation-api/api/internal/db"
"github.com/USACE/instrumentation-api/api/internal/dto"
"github.com/USACE/instrumentation-api/api/internal/httperr"
"net/http"
"github.com/labstack/echo/v4"
)
// ListEmailAutocomplete godoc
//
// @Summary lists results of email autocomplete
// @Tags autocomplete
// @Produce json
// @Param q query string true "search query string"
// @Success 200 {array} db.EmailAutocompleteListRow
// @Failure 400 {object} echo.HTTPError
// @Failure 404 {object} echo.HTTPError
// @Failure 500 {object} echo.HTTPError
// @Router /email_autocomplete [get]
func (h *ApiHandler) ListEmailAutocomplete(c echo.Context) error {
searchText := c.QueryParam("q")
if searchText == "" {
return c.JSON(http.StatusOK, make([]dto.EmailAutocompleteResult, 0))
}
var limit int32 = 5
rr, err := h.DBService.EmailAutocompleteList(c.Request().Context(), db.EmailAutocompleteListParams{
SearchKeyword: &searchText,
ResultLimit: limit,
})
if err != nil {
return httperr.InternalServerError(err)
}
return c.JSON(http.StatusOK, rr)
}