diff --git a/api/query_params.go b/api/query_params.go index 2b929247..84138f45 100644 --- a/api/query_params.go +++ b/api/query_params.go @@ -2,6 +2,7 @@ package api type queryParams struct { Limit *int `schema:"limit"` + Query *string `schema:"query"` Sort *string `schema:"sort"` Type *string `schema:"type"` } diff --git a/api/routes.go b/api/routes.go index 25c9b43f..c4b944ef 100644 --- a/api/routes.go +++ b/api/routes.go @@ -30,7 +30,9 @@ func AddRoutes(r chi.Router) { r.Method("GET", "/signal", authenticatedHandlerJSON(listSignal)) r.Method("GET", "/trap-data", auth.NewEnsureAuth(apiTrapData)) r.Method("GET", "/tile/{z}/{y}/{x}", auth.NewEnsureAuth(getTile)) - r.Method("GET", "/user", authenticatedHandlerJSON(getUser)) + r.Method("GET", "/user/self", authenticatedHandlerJSON(getUser)) + r.Method("GET", "/user/suggestion", authenticatedHandlerJSON(listUserSuggestion)) + r.Method("GET", "/user", authenticatedHandlerJSON(listUser)) // Unauthenticated endpoints r.Get("/district", apiGetDistrict) diff --git a/api/user.go b/api/user.go index 0326de19..7f3cb244 100644 --- a/api/user.go +++ b/api/user.go @@ -16,3 +16,30 @@ func getUser(ctx context.Context, r *http.Request, user platform.User, query que user.NotificationCounts = *counts return &user, nil } + +type responseListUser struct { + Users []platform.User `json:"users"` +} + +func listUser(ctx context.Context, r *http.Request, user platform.User, query queryParams) (*responseListUser, *nhttp.ErrorWithStatus) { + return &responseListUser{ + Users: []platform.User{}, + }, nil +} + +type responseListUserSuggestion struct { + Users []platform.User `json:"users"` +} + +func listUserSuggestion(ctx context.Context, r *http.Request, user platform.User, query queryParams) (*responseListUser, *nhttp.ErrorWithStatus) { + if query.Query == nil { + return nil, nhttp.NewErrorStatus(http.StatusBadRequest, "you need to include a query") + } + users, err := platform.UserSuggestion(ctx, user, *query.Query) + if err != nil { + return nil, nhttp.NewError("query suggestions: %w", err) + } + return &responseListUser{ + Users: users, + }, nil +} diff --git a/html/static/js/user-selector.js b/html/static/js/user-selector.js new file mode 100644 index 00000000..63b3d8cb --- /dev/null +++ b/html/static/js/user-selector.js @@ -0,0 +1,243 @@ +class UserSelector extends HTMLElement { + constructor() { + super(); + this.attachShadow({ mode: "open" }); + this.selectedUser = null; + this.debounceTimer = null; + } + + connectedCallback() { + this.render(); + this.setupEventListeners(); + } + + render() { + this.shadowRoot.innerHTML = ` + + + +