update controllers logic

This commit is contained in:
root
2026-04-23 00:04:35 -04:00
parent 1977a513df
commit ca4ba272fc
353 changed files with 13402 additions and 1301 deletions
@@ -2,7 +2,7 @@
namespace App\Http\Controllers\Api\Communication;
use App\Http\Controllers\Api\BaseApiController;
use App\Http\Controllers\Api\Core\BaseApiController;
use App\Services\Communication\CommunicationFamilyService;
use App\Services\Communication\CommunicationPreviewService;
use App\Services\Communication\CommunicationSendService;
@@ -123,6 +123,11 @@ class CommunicationController extends BaseApiController
], 404);
}
$senderId = $this->authenticatedUserIdOrUnauthorized();
if ($senderId instanceof JsonResponse) {
return $senderId;
}
$result = $this->sendService->send([
'student_id' => $studentId,
'family_id' => $familyId,
@@ -133,7 +138,7 @@ class CommunicationController extends BaseApiController
'cc' => $cc,
'bcc' => $bcc,
'student_name' => trim(($student['firstname'] ?? '') . ' ' . ($student['lastname'] ?? '')),
'sent_by' => (int) (auth()->id() ?? 0),
'sent_by' => $senderId,
]);
if (!$result['ok']) {
@@ -175,4 +180,17 @@ class CommunicationController extends BaseApiController
}
return 'Teacher';
}
/**
* @return int|JsonResponse
*/
private function authenticatedUserIdOrUnauthorized(): int|JsonResponse
{
$userId = (int) (auth()->id() ?? 0);
if ($userId <= 0) {
return response()->json(['ok' => false, 'message' => 'Unauthorized.'], 401);
}
return $userId;
}
}