From 9450af6c8e6caabbd1ed11f298f5e3aaeb8803a1 Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Fri, 22 May 2026 00:12:07 +0300 Subject: [PATCH] Deploy: 2026-05-22 00:12:07 --- backend/app/Controllers/GroupController.php | 43 ++++++++++ backend/public/index.html | 93 ++++++++++++++++++++- backend/public/index.php | 1 + 3 files changed, 136 insertions(+), 1 deletion(-) 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