Add initial user selector for impersonation page

This commit is contained in:
Eli Ribble 2026-03-20 05:20:37 +00:00
parent 68e0da1133
commit 42d9d2372d
No known key found for this signature in database
9 changed files with 370 additions and 31 deletions

View file

@ -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"`
}

View file

@ -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)

View file

@ -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
}