MCPcopy Create free account
hub / github.com/GoMudEngine/GoMud / apiAdminGetStorage

Method apiAdminGetStorage

modules/storage/admin.go:22–55  ·  view source on GitHub ↗

apiAdminGetStorage handles GET /admin/api/v1/storage?user_id= Returns the list of stored items for the given user.

(r *http.Request)

Source from the content-addressed store, hash-verified

20// apiAdminGetStorage handles GET /admin/api/v1/storage?user_id=<id>
21// Returns the list of stored items for the given user.
22func (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.

Callers

nothing calls this directly

Calls 4

storageForUserMethod · 0.95
GetMethod · 0.45
NameMethod · 0.45
ShorthandIdMethod · 0.45

Tested by

no test coverage detected