apiAdminGetStorage handles GET /admin/api/v1/storage?user_id= Returns the list of stored items for the given user.
(r *http.Request)
| 20 | // apiAdminGetStorage handles GET /admin/api/v1/storage?user_id=<id> |
| 21 | // Returns the list of stored items for the given user. |
| 22 | func (m *StorageModule) apiAdminGetStorage(r *http.Request) (int, bool, any) { |
| 23 | type result struct { |
| 24 | UserId int `json:"user_id"` |
| 25 | Username string `json:"username"` |
| 26 | Items []adminStorageItem `json:"items"` |
| 27 | } |
| 28 | |
| 29 | userIdStr := r.URL.Query().Get("user_id") |
| 30 | if userIdStr == "" { |
| 31 | return http.StatusBadRequest, false, map[string]string{"error": "user_id query param is required"} |
| 32 | } |
| 33 | userId, err := strconv.Atoi(userIdStr) |
| 34 | if err != nil || userId <= 0 { |
| 35 | return http.StatusBadRequest, false, map[string]string{"error": "invalid user_id"} |
| 36 | } |
| 37 | |
| 38 | username, storageItems := m.storageForUser(userId) |
| 39 | |
| 40 | entries := make([]adminStorageItem, 0, len(storageItems)) |
| 41 | for i, itm := range storageItems { |
| 42 | entries = append(entries, adminStorageItem{ |
| 43 | Index: i + 1, |
| 44 | ItemId: itm.ItemId, |
| 45 | Name: itm.Name(), |
| 46 | ShortId: itm.ShorthandId(), |
| 47 | }) |
| 48 | } |
| 49 | |
| 50 | return http.StatusOK, true, result{ |
| 51 | UserId: userId, |
| 52 | Username: username, |
| 53 | Items: entries, |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | // apiAdminDeleteStorageItem handles DELETE /admin/api/v1/storage?user_id=<id>&short_id=<sid> |
| 58 | // Removes the item with the matching short_id from the user's storage. |
nothing calls this directly
no test coverage detected