Skip to content

Commit

Permalink
add browser search
Browse files Browse the repository at this point in the history
  • Loading branch information
its-felix committed Sep 9, 2024
1 parent 6585473 commit a1f9d43
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
13 changes: 11 additions & 2 deletions go/api/web/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import (
"github.com/explore-flights/monorepo/go/common/adapt"
"github.com/labstack/echo/v4"
"net/http"
"net/url"
"strings"
)

func NewSearchEndpoint(s3c adapt.S3Lister, bucket string) echo.HandlerFunc {
const schedulesPrefix = "processed/schedules/"

return func(c echo.Context) error {
query := strings.ToUpper(c.QueryParam("q"))
query := strings.TrimSpace(strings.ToUpper(c.QueryParam("q")))
prefix := schedulesPrefix

if len(query) >= 2 {
Expand Down Expand Up @@ -51,6 +52,14 @@ func NewSearchEndpoint(s3c adapt.S3Lister, bucket string) echo.HandlerFunc {
}
}

return c.JSON(http.StatusOK, fns)
if c.Request().Header.Get(echo.HeaderAccept) == echo.MIMEApplicationJSON {
return c.JSON(http.StatusOK, fns)
} else {
if len(fns) < 1 {
return c.NoContent(http.StatusNotFound)
}

return c.Redirect(http.StatusFound, "/flight/"+url.PathEscape(fns[0].String()))
}
}
}
9 changes: 8 additions & 1 deletion ui/src/lib/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,14 @@ export class ApiClient {
const params = new URLSearchParams();
params.set('q', query);

return transform(this.httpClient.fetch(`/api/search?${params.toString()}`));
return transform(this.httpClient.fetch(
`/api/search?${params.toString()}`,
{
headers: {
'Accept': 'application/json',
},
},
));
}

raw(url: string): Promise<ApiResponse<JsonType>> {
Expand Down

0 comments on commit a1f9d43

Please sign in to comment.