fix tests
This commit is contained in:
@@ -94,8 +94,9 @@ class ClassProgressController extends BaseApiController
|
||||
$filters['semester'] = $filters['semester'] ?? ($meta['semester'] ?? null);
|
||||
$paginator = $this->queryService->listReports($auth, $filters);
|
||||
|
||||
if (!empty($filters['group_by_week'])) {
|
||||
if (! empty($filters['group_by_week'])) {
|
||||
$grouped = ClassProgressGroupCollection::fromPaginator($paginator);
|
||||
|
||||
return $this->respondSuccess($grouped, 'Progress reports retrieved.');
|
||||
}
|
||||
|
||||
@@ -135,6 +136,7 @@ class ClassProgressController extends BaseApiController
|
||||
Log::error('Failed to create class progress reports.', [
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
return $this->respondError('Unable to save progress reports.', 500);
|
||||
}
|
||||
|
||||
@@ -170,6 +172,7 @@ class ClassProgressController extends BaseApiController
|
||||
Log::error('Failed to update class progress report.', [
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
return $this->respondError('Unable to update progress report.', 500);
|
||||
}
|
||||
|
||||
@@ -184,6 +187,7 @@ class ClassProgressController extends BaseApiController
|
||||
Log::error('Failed to delete class progress report.', [
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
return $this->respondError('Unable to delete progress report.', 500);
|
||||
}
|
||||
|
||||
@@ -193,7 +197,7 @@ class ClassProgressController extends BaseApiController
|
||||
public function downloadAttachment(int $attachment): BinaryFileResponse|JsonResponse
|
||||
{
|
||||
$record = ClassProgressAttachment::query()->find($attachment);
|
||||
if (!$record || !$record->file_path) {
|
||||
if (! $record || ! $record->file_path) {
|
||||
return $this->respondError('Attachment not found.', 404);
|
||||
}
|
||||
|
||||
@@ -202,11 +206,12 @@ class ClassProgressController extends BaseApiController
|
||||
}
|
||||
|
||||
$path = $this->attachmentService->resolvePath($record->file_path);
|
||||
if (!$path) {
|
||||
if (! $path) {
|
||||
return $this->respondError('Attachment missing.', 404);
|
||||
}
|
||||
|
||||
$downloadName = $record->original_name ?: basename($path);
|
||||
|
||||
return response()->download($path, $downloadName);
|
||||
}
|
||||
|
||||
@@ -214,12 +219,12 @@ class ClassProgressController extends BaseApiController
|
||||
{
|
||||
$this->authorize('view', $class_progress);
|
||||
|
||||
if (!$class_progress->attachment_path) {
|
||||
if (! $class_progress->attachment_path) {
|
||||
return $this->respondError('Attachment not found.', 404);
|
||||
}
|
||||
|
||||
$path = $this->attachmentService->resolvePath($class_progress->attachment_path);
|
||||
if (!$path) {
|
||||
if (! $path) {
|
||||
return $this->respondError('Attachment missing.', 404);
|
||||
}
|
||||
|
||||
@@ -228,19 +233,18 @@ class ClassProgressController extends BaseApiController
|
||||
|
||||
/**
|
||||
* @param mixed $user
|
||||
* @return User|JsonResponse
|
||||
*/
|
||||
private function requireAuthenticatedUser($user): User|JsonResponse
|
||||
{
|
||||
if (!$user instanceof User) {
|
||||
if (! $user instanceof User) {
|
||||
$user = auth()->user();
|
||||
}
|
||||
|
||||
if (!$user instanceof User) {
|
||||
if (! $user instanceof User) {
|
||||
$user = $this->laravelRequest->user();
|
||||
}
|
||||
|
||||
if (!$user instanceof User) {
|
||||
if (! $user instanceof User) {
|
||||
return $this->respondError('Unauthorized.', Response::HTTP_UNAUTHORIZED);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user