Some checks failed
tests / ci (pull_request) Has been cancelled
- Created sub-namespaces under Admin\Manage for Course, Academic, Announcement, Finance, and Service. - Added new FormRequest classes for handling validation in each sub-namespace. - Implemented Service classes for managing business logic related to each resource. - Updated routes to reflect the new sub-namespace structure. - Enhanced code organization and maintainability by grouping related functionalities.
55 lines
1.9 KiB
PHP
55 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin\Manage\Academic;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Admin\Manage\Academic\AssignmentRequest;
|
|
use App\Http\Requests\PaginatedRequest;
|
|
use App\Models\Assignment;
|
|
use App\Services\Admin\Manage\Academic\AssignmentService;
|
|
use App\Services\Admin\Manage\Course\CourseClassService;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Inertia\Inertia;
|
|
use Inertia\Response;
|
|
|
|
class AssignmentController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly AssignmentService $service,
|
|
private readonly CourseClassService $courseClassService,
|
|
) {}
|
|
|
|
public function index(PaginatedRequest $request): Response
|
|
{
|
|
return Inertia::render('admin/manage/assignments/index', [
|
|
'assignments' => $this->service->paginated(...$request->validatedWithDefaults()),
|
|
'courseClasses' => $this->courseClassService->getAllForSelect(),
|
|
]);
|
|
}
|
|
|
|
public function store(AssignmentRequest $request): RedirectResponse
|
|
{
|
|
$this->service->create($request->validated(), $request->file('attachment'));
|
|
|
|
Inertia::flash('toast', ['type' => 'success', 'message' => 'Tugas berhasil ditambahkan.']);
|
|
|
|
return to_route('admin.manage.assignments.index');
|
|
}
|
|
|
|
public function update(AssignmentRequest $request, Assignment $assignment): RedirectResponse
|
|
{
|
|
$this->service->update($assignment, $request->validated(), $request->file('attachment'));
|
|
|
|
Inertia::flash('toast', ['type' => 'success', 'message' => 'Tugas berhasil diperbarui.']);
|
|
|
|
return to_route('admin.manage.assignments.index');
|
|
}
|
|
|
|
public function destroy(Assignment $assignment): RedirectResponse
|
|
{
|
|
$this->service->delete($assignment);
|
|
|
|
return Inertia::flash('toast', ['type' => 'success', 'message' => 'Tugas berhasil dihapus.'])->back();
|
|
}
|
|
}
|