adminUsers responds with a list of all users in a given audience
(w http.ResponseWriter, r *http.Request)
| 52 | |
| 53 | // adminUsers responds with a list of all users in a given audience |
| 54 | func (a *API) adminUsers(w http.ResponseWriter, r *http.Request) error { |
| 55 | ctx := r.Context() |
| 56 | instanceID := getInstanceID(ctx) |
| 57 | aud := a.requestAud(ctx, r) |
| 58 | |
| 59 | pageParams, err := paginate(r) |
| 60 | if err != nil { |
| 61 | return badRequestError("Bad Pagination Parameters: %v", err) |
| 62 | } |
| 63 | |
| 64 | sortParams, err := sort(r, map[string]bool{models.CreatedAt: true}, []models.SortField{models.SortField{Name: models.CreatedAt, Dir: models.Descending}}) |
| 65 | if err != nil { |
| 66 | return badRequestError("Bad Sort Parameters: %v", err) |
| 67 | } |
| 68 | |
| 69 | filter := r.URL.Query().Get("filter") |
| 70 | |
| 71 | users, err := models.FindUsersInAudience(a.db, instanceID, aud, pageParams, sortParams, filter) |
| 72 | if err != nil { |
| 73 | return internalServerError("Database error finding users").WithInternalError(err) |
| 74 | } |
| 75 | addPaginationHeaders(w, r, pageParams) |
| 76 | |
| 77 | return sendJSON(w, http.StatusOK, map[string]interface{}{ |
| 78 | "users": users, |
| 79 | "aud": aud, |
| 80 | }) |
| 81 | } |
| 82 | |
| 83 | // adminUserGet returns information about a single user |
| 84 | func (a *API) adminUserGet(w http.ResponseWriter, r *http.Request) error { |
nothing calls this directly
no test coverage detected