Cetaklabel/Http/Controllers/Api/SubSubJobController.php

90 lines
2.8 KiB
PHP
Raw Normal View History

2023-05-15 10:03:46 +00:00
<?php
2023-05-20 14:09:49 +00:00
namespace Modules\Cetaklabel\Http\Controllers\Api;
2023-05-15 10:03:46 +00:00
use App\Http\Controllers\ApiController;
use Exception;
2023-05-20 14:09:49 +00:00
use Modules\Cetaklabel\Entities\SubSubJob;
use Modules\Cetaklabel\Http\Requests\SubSubJob\StoreSubSubJobRequest;
use Modules\Cetaklabel\Http\Requests\SubSubJob\UpdateSubSubJobRequest;
2023-05-15 10:03:46 +00:00
use Symfony\Component\HttpFoundation\JsonResponse;
class SubSubJobController extends ApiController
{
2023-05-15 14:14:52 +00:00
public function index()
: JsonResponse
2023-05-15 10:03:46 +00:00
{
$sub_sub_jobs = SubSubJob::all();
return $this->sendResponse($sub_sub_jobs, 'Sub Sub Jobs retrieved successfully.');
}
2023-05-15 14:14:52 +00:00
public function show($sub_sub_job)
: JsonResponse
2023-05-15 10:03:46 +00:00
{
$sub_sub_job = SubSubJob::find($sub_sub_job);
if (is_null($sub_sub_job)) {
return $this->sendError('Sub Sub Job not found.');
}
return $this->sendResponse($sub_sub_job, 'Sub Sub Job retrieved successfully.');
}
2023-05-15 14:14:52 +00:00
public function store(StoreSubSubJobRequest $request)
: JsonResponse
2023-05-15 10:03:46 +00:00
{
// Validate the request...
$validated = $request->validated();
// Store the SubSubJob...
if ($validated) {
try {
$data = SubSubJob::create($validated);
return $this->sendResponse($data, 'Sub Sub Job created successfully.');
} catch (Exception $e) {
return $this->sendError($e->getMessage(), $e->getCode());
}
}
return $this->sendError('Sub Sub Job created failed.', 400);
}
2023-05-15 14:14:52 +00:00
public function update(UpdateSubSubJobRequest $request, SubSubJob $sub_sub_job)
: JsonResponse
2023-05-15 10:03:46 +00:00
{
// Validate the request...
$validated = $request->validated();
// Store the SubSubJob...
if ($validated) {
try {
$data = $sub_sub_job->update($validated);
return $this->sendResponse($data, 'Sub Sub Job updated successfully.');
} catch (Exception $e) {
return $this->sendError($e->getMessage(), $e->getCode());
}
}
return $this->sendError('Sub Sub Job created failed.', 400);
}
2023-05-15 14:14:52 +00:00
public function destroy($id)
: JsonResponse
2023-05-15 10:03:46 +00:00
{
$sub_sub_job = SubSubJob::find($id);
if (is_null($sub_sub_job)) {
return $this->sendError('Sub Sub Job not found.');
}
try {
$sub_sub_job->delete();
return $this->sendResponse($sub_sub_job, 'Sub Sub Job deleted successfully.');
} catch (Exception $e) {
return $this->sendError($e->getMessage(), $e->getCode());
}
}
}