reconstruction of the project
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api\Assignment;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Assignment\StoreAssignmentRequest;
|
||||
use App\Http\Resources\Assignment\AssignmentOverviewResource;
|
||||
use App\Http\Resources\Assignment\AssignmentSectionResource;
|
||||
use App\Services\Assignment\AssignmentService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AssignmentApiController extends Controller
|
||||
{
|
||||
public function __construct(
|
||||
protected AssignmentService $assignmentService
|
||||
) {}
|
||||
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$data = $this->assignmentService->getAssignmentsOverview(
|
||||
schoolYear: $request->query('school_year'),
|
||||
semester: $request->query('semester'),
|
||||
);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Assignments retrieved successfully.',
|
||||
'data' => new AssignmentOverviewResource((object) $data),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(StoreAssignmentRequest $request): JsonResponse
|
||||
{
|
||||
$assignment = $this->assignmentService->storeAssignment(
|
||||
data: $request->validated(),
|
||||
updatedBy: $request->user()?->id
|
||||
);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Assignment saved successfully.',
|
||||
'data' => $assignment,
|
||||
], 201);
|
||||
}
|
||||
|
||||
public function classAssignmentData(): JsonResponse
|
||||
{
|
||||
$data = $this->assignmentService->getClassAssignmentData();
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Class assignment data retrieved successfully.',
|
||||
'data' => [
|
||||
'classSections' => AssignmentSectionResource::collection(collect($data['classSections'])),
|
||||
'semester' => $data['semester'],
|
||||
'school_year' => $data['school_year'],
|
||||
],
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user