90 lines
2.8 KiB
PHP
90 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace Modules\CetakLabel\Http\Controllers\Api;
|
|
|
|
use App\Http\Controllers\ApiController;
|
|
use Exception;
|
|
use Modules\CetakLabel\Entities\SubSubJob;
|
|
use Modules\CetakLabel\Http\Requests\SubSubJob\StoreSubSubJobRequest;
|
|
use Modules\CetakLabel\Http\Requests\SubSubJob\UpdateSubSubJobRequest;
|
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
|
|
class SubSubJobController extends ApiController
|
|
{
|
|
public function index()
|
|
: JsonResponse
|
|
{
|
|
$sub_sub_jobs = SubSubJob::all();
|
|
|
|
return $this->sendResponse($sub_sub_jobs, 'Sub Sub Jobs retrieved successfully.');
|
|
}
|
|
|
|
public function show($sub_sub_job)
|
|
: JsonResponse
|
|
{
|
|
$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.');
|
|
}
|
|
|
|
public function store(StoreSubSubJobRequest $request)
|
|
: JsonResponse
|
|
{
|
|
// 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);
|
|
}
|
|
|
|
public function update(UpdateSubSubJobRequest $request, SubSubJob $sub_sub_job)
|
|
: JsonResponse
|
|
{
|
|
// 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);
|
|
}
|
|
|
|
public function destroy($id)
|
|
: JsonResponse
|
|
{
|
|
$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());
|
|
}
|
|
}
|
|
}
|