MCPcopy Create free account
hub / github.com/cppla/ServerStatus / find_collection_item

Function find_collection_item

server/manage_api.py:249–262  ·  view source on GitHub ↗
(config, key, item_id)

Source from the content-addressed store, hash-verified

247
248
249def find_collection_item(config, key, item_id):
250 items = config.get(key, [])
251 if item_id.isdigit():
252 index = int(item_id)
253 if 0 <= index < len(items):
254 return index, items[index]
255 return -1, None
256 id_field = COLLECTIONS[key]["id_field"]
257 matches = [(index, item) for index, item in enumerate(items) if str(item.get(id_field, "")) == item_id]
258 if len(matches) > 1:
259 raise ApiError(409, f"{key} has duplicate {id_field}; use numeric index instead", {"id": item_id})
260 if matches:
261 return matches[0]
262 return -1, None
263
264
265def collection_routes():

Callers 1

routeMethod · 0.85

Calls 1

ApiErrorClass · 0.85

Tested by

no test coverage detected