add class progress and fix endpoints

This commit is contained in:
root
2026-03-12 17:27:49 -04:00
parent 0f39dbee62
commit 33be0c9a0d
40 changed files with 2086 additions and 438 deletions
@@ -0,0 +1,21 @@
<?php
namespace App\Http\Resources\ClassProgress;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class ClassProgressAttachmentResource extends JsonResource
{
public function toArray(Request $request): array
{
$id = $this['id'] ?? $this->id ?? null;
return [
'id' => $id ? (int) $id : null,
'name' => $this['name'] ?? $this->original_name ?? null,
'file_path' => $this['file_path'] ?? $this->file_path ?? null,
'download_url' => $id ? url("/api/v1/class-progress/attachments/{$id}") : null,
];
}
}
@@ -0,0 +1,48 @@
<?php
namespace App\Http\Resources\ClassProgress;
use App\Http\Resources\Admin\Progress\ProgressGroupResource;
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Http\Resources\Json\ResourceCollection;
class ClassProgressGroupCollection extends ResourceCollection
{
public function toArray($request): array
{
return $this->collection->toArray();
}
public static function fromPaginator(LengthAwarePaginator $paginator): array
{
$groups = [];
foreach ($paginator->items() as $report) {
$key = $report->week_start?->format('Y-m-d') ?? '';
if ($key === '') {
continue;
}
if (!isset($groups[$key])) {
$groups[$key] = [
'week_start' => $key,
'week_end' => $report->week_end?->format('Y-m-d'),
'class_section_id' => $report->class_section_id,
'class_section_name' => $report->classSection?->class_section_name ?? '',
'reports' => [],
];
}
$groups[$key]['reports'][$report->subject] = (new ClassProgressReportResource($report))->toArray(request());
}
return [
'items' => ProgressGroupResource::collection(collect(array_values($groups))),
'pagination' => [
'current_page' => $paginator->currentPage(),
'per_page' => $paginator->perPage(),
'total' => $paginator->total(),
'last_page' => $paginator->lastPage(),
],
];
}
}
@@ -0,0 +1,35 @@
<?php
namespace App\Http\Resources\ClassProgress;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class ClassProgressReportResource extends JsonResource
{
public function toArray(Request $request): array
{
$attachments = $this->attachments ?? $this['attachments'] ?? [];
return [
'id' => $this->id,
'teacher_id' => $this->teacher_id,
'class_section_id' => $this->class_section_id,
'class_section_name' => $this->classSection?->class_section_name,
'week_start' => $this->week_start?->format('Y-m-d'),
'week_end' => $this->week_end?->format('Y-m-d'),
'subject' => $this->subject,
'unit_title' => $this->unit_title,
'covered' => $this->covered,
'homework' => $this->homework,
'status' => $this->status,
'status_label' => $this->status_label ?? (config('progress.status_options')[$this->status] ?? null),
'support_needed' => $this->support_needed,
'flags' => $this->flags_json,
'attachment_path' => $this->attachment_path,
'attachments' => ClassProgressAttachmentResource::collection(collect($attachments)),
'created_at' => $this->created_at?->toIso8601String(),
'updated_at' => $this->updated_at?->toIso8601String(),
];
}
}
@@ -0,0 +1,20 @@
<?php
namespace App\Http\Resources\ClassProgress;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class ClassProgressShowResource extends JsonResource
{
public function toArray(Request $request): array
{
$weekly = $this['weekly_reports'] ?? [];
return [
'report' => new ClassProgressReportResource($this['report']),
'weekly_reports' => ClassProgressReportResource::collection(collect($weekly)),
'status_options' => $this['status_options'] ?? [],
];
}
}