diff --git a/backend/app/Controllers/GroupController.php b/backend/app/Controllers/GroupController.php index 7f567e6..37bd615 100644 --- a/backend/app/Controllers/GroupController.php +++ b/backend/app/Controllers/GroupController.php @@ -70,4 +70,47 @@ class GroupController extends BaseController $response->json(['status' => 'success', 'message' => 'Contact added to group']); } + + /** + * Attach multiple contacts to a group in bulk + */ + public function bulkAddContacts(Request $request, Response $response) + { + $errors = $this->validate($request, [ + 'group_id' => 'required', + 'contact_ids' => 'required' + ]); + if (!empty($errors)) { + $response->status(400)->json(['status' => 'error', 'errors' => $errors]); + return; + } + + $body = $request->getBody(); + $groupId = (int)$body['group_id']; + $contactIds = $body['contact_ids']; + + if (!is_array($contactIds)) { + $response->status(400)->json(['status' => 'error', 'message' => 'contact_ids must be an array']); + return; + } + + $groupModel = new ContactGroup(); + + $pdo = \App\Core\Database::getConnection(); + try { + $pdo->beginTransaction(); + foreach ($contactIds as $contactId) { + $groupModel->attachContact($groupId, (int)$contactId); + } + $pdo->commit(); + } catch (\Exception $e) { + if ($pdo->inTransaction()) { + $pdo->rollBack(); + } + $response->status(500)->json(['status' => 'error', 'message' => 'Bulk insert failed: ' . $e->getMessage()]); + return; + } + + $response->json(['status' => 'success', 'message' => 'Contacts added to group in bulk']); + } } diff --git a/backend/public/index.html b/backend/public/index.html index ab8198a..e26e56f 100644 --- a/backend/public/index.html +++ b/backend/public/index.html @@ -713,7 +713,7 @@ - + +
+ + Selected: contact(s) + +
+ + or + + +
+
+
+ @@ -859,6 +880,9 @@
+ + Name Phone Email