Complete backend for SprintChat Hub migration: - Messages: send, edit, delete, list (paginated cursor), thread, search - Files: upload (multipart), download, thumbnail, info, list - Users: get, getByIds, search, status (online detection) - Reactions: add, remove, list (grouped by emoji) - Pins: pin, unpin, list (with message content) - Channel stats: member/message/pinned/unread counts 4 new DB tables: Hub_Messages, Hub_Files, Hub_Reactions, Hub_PinnedPosts 21 new endpoints added to PUBLIC_ROUTES Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
55 lines
1.5 KiB
PHP
55 lines
1.5 KiB
PHP
<?php
|
|
/**
|
|
* GET /api/hub/users/search.php
|
|
*
|
|
* Search agents by name or address.
|
|
*
|
|
* Query params:
|
|
* Query string REQUIRED search term
|
|
* Project string optional filter by project name
|
|
* Limit int optional default 25, max 100
|
|
*
|
|
* Response: { OK: true, Users: [...] }
|
|
*/
|
|
|
|
require_once __DIR__ . '/../../helpers.php';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
|
|
jsonResponse(['OK' => false, 'ERROR' => 'method_not_allowed'], 405);
|
|
}
|
|
|
|
$query = trim($_GET['Query'] ?? '');
|
|
$project = trim($_GET['Project'] ?? '');
|
|
$limit = min(max((int) ($_GET['Limit'] ?? 25), 1), 100);
|
|
|
|
if ($query === '') jsonResponse(['OK' => false, 'ERROR' => 'query_required']);
|
|
|
|
$searchTerm = '%' . $query . '%';
|
|
$sql = "SELECT * FROM Sprinter_Agents WHERE (AgentName LIKE ? OR FullAddress LIKE ? OR Role LIKE ?) AND IsActive = 1";
|
|
$params = [$searchTerm, $searchTerm, $searchTerm];
|
|
|
|
if ($project !== '') {
|
|
$sql .= " AND ProjectName = ?";
|
|
$params[] = $project;
|
|
}
|
|
|
|
$sql .= " ORDER BY AgentName ASC LIMIT ?";
|
|
$params[] = $limit;
|
|
|
|
$rows = queryTimed($sql, $params);
|
|
|
|
$users = [];
|
|
foreach ($rows as $a) {
|
|
$users[] = [
|
|
'ID' => (int) $a['ID'],
|
|
'AgentName' => $a['AgentName'],
|
|
'FullAddress' => $a['FullAddress'],
|
|
'ProjectName' => $a['ProjectName'],
|
|
'AgentType' => $a['AgentType'],
|
|
'Role' => $a['Role'],
|
|
'IsActive' => true,
|
|
'CreatedAt' => toISO8601($a['CreatedAt']),
|
|
];
|
|
}
|
|
|
|
jsonResponse(['OK' => true, 'Users' => $users]);
|