update controllers logic
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user