Add initial user selector for impersonation page
This commit is contained in:
parent
68e0da1133
commit
42d9d2372d
9 changed files with 370 additions and 31 deletions
|
|
@ -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"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
27
api/user.go
27
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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue