add test batches
This commit is contained in:
@@ -9,7 +9,6 @@ use App\Http\Requests\Staff\StaffUpdateRequest;
|
||||
use App\Http\Resources\Staff\StaffCollection;
|
||||
use App\Http\Resources\Staff\StaffResource;
|
||||
use App\Models\Staff;
|
||||
use App\Models\User;
|
||||
use App\Services\Staff\StaffCommandService;
|
||||
use App\Services\Staff\StaffQueryService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@@ -48,12 +47,12 @@ class StaffController extends BaseApiController
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
$staff = $this->queryService->find($id);
|
||||
if (! $staff) {
|
||||
if (!$staff) {
|
||||
return $this->error('Staff member not found.', Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
$this->authorize('view', $staff);
|
||||
$staff->school_id = User::getSchoolIdByUserId((int) ($staff->user_id ?? 0));
|
||||
$staff->school_id = \App\Models\User::getSchoolIdByUserId((int) ($staff->user_id ?? 0));
|
||||
|
||||
return $this->success([
|
||||
'staff' => new StaffResource($staff),
|
||||
@@ -67,8 +66,7 @@ class StaffController extends BaseApiController
|
||||
try {
|
||||
$staff = $this->commandService->create($request->validated());
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Staff create failed: '.$e->getMessage());
|
||||
|
||||
Log::error('Staff create failed: ' . $e->getMessage());
|
||||
return $this->error($e->getMessage(), Response::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
@@ -80,7 +78,7 @@ class StaffController extends BaseApiController
|
||||
public function update(StaffUpdateRequest $request, int $id): JsonResponse
|
||||
{
|
||||
$staff = $this->queryService->find($id);
|
||||
if (! $staff) {
|
||||
if (!$staff) {
|
||||
return $this->error('Staff member not found.', Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
@@ -89,8 +87,7 @@ class StaffController extends BaseApiController
|
||||
try {
|
||||
$updated = $this->commandService->update($staff, $request->validated());
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Staff update failed: '.$e->getMessage());
|
||||
|
||||
Log::error('Staff update failed: ' . $e->getMessage());
|
||||
return $this->error('Unable to update staff.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
@@ -102,7 +99,7 @@ class StaffController extends BaseApiController
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
$staff = $this->queryService->find($id);
|
||||
if (! $staff) {
|
||||
if (!$staff) {
|
||||
return $this->error('Staff member not found.', Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
@@ -111,12 +108,11 @@ class StaffController extends BaseApiController
|
||||
try {
|
||||
$deleted = $this->commandService->delete($staff);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('Staff delete failed: '.$e->getMessage());
|
||||
|
||||
Log::error('Staff delete failed: ' . $e->getMessage());
|
||||
return $this->error('Unable to delete staff.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
if (! $deleted) {
|
||||
if (!$deleted) {
|
||||
return $this->error('Unable to delete staff.', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
|
||||
@@ -124,12 +124,12 @@ class TeacherController extends BaseApiController
|
||||
|
||||
private function teacherPayload(?array $teacher, int $userId): ?array
|
||||
{
|
||||
if (! $teacher) {
|
||||
if (!$teacher) {
|
||||
$model = User::query()->find($userId);
|
||||
$teacher = $model?->toArray();
|
||||
}
|
||||
|
||||
if (! $teacher) {
|
||||
if (!$teacher) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -142,6 +142,9 @@ class TeacherController extends BaseApiController
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|JsonResponse
|
||||
*/
|
||||
private function authenticatedUserIdOrUnauthorized(): int|JsonResponse
|
||||
{
|
||||
$userId = (int) (auth()->id() ?? 0);
|
||||
|
||||
Reference in New Issue
Block a user