Migrate HickLab3D dashboard and add production auto deployment
Deploy HickLab3D Dashboard / Deploy to production (push) Failing after 19s
Deploy HickLab3D Dashboard / Deploy to production (push) Failing after 19s
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Services\DryerClient;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
use Throwable;
|
||||
|
||||
class DryerController extends Controller
|
||||
{
|
||||
public function index(): View
|
||||
{
|
||||
return view('dryer');
|
||||
}
|
||||
|
||||
public function status(DryerClient $dryer): JsonResponse
|
||||
{
|
||||
try {
|
||||
return response()->json(['status' => $dryer->status(), 'history' => $dryer->history()]);
|
||||
} catch (Throwable $exception) {
|
||||
report($exception);
|
||||
|
||||
return response()->json(['message' => 'Dryer is unavailable.'], 503);
|
||||
}
|
||||
}
|
||||
|
||||
public function control(Request $request, DryerClient $dryer): JsonResponse
|
||||
{
|
||||
abort_unless($request->user()->role === 'admin', 403);
|
||||
$data = $request->validate([
|
||||
'dryerOn' => ['required', 'boolean'],
|
||||
'profile' => ['required_if:dryerOn,1', 'nullable', 'string', 'in:PLA,PETG,ABS,Nylon,Custom'],
|
||||
'targetTemperature' => ['required_if:dryerOn,1', 'nullable', 'integer', 'between:45,70'],
|
||||
'dryingTime' => ['required_if:dryerOn,1', 'nullable', 'integer', 'between:5,2880'],
|
||||
]);
|
||||
try {
|
||||
$result = $data['dryerOn']
|
||||
? $dryer->start($data['profile'], $data['targetTemperature'], $data['dryingTime'])
|
||||
: $dryer->stop();
|
||||
|
||||
return response()->json($result);
|
||||
} catch (Throwable $exception) {
|
||||
report($exception);
|
||||
|
||||
return response()->json(['message' => 'Dryer is unavailable.'], 503);
|
||||
}
|
||||
}
|
||||
|
||||
public function acknowledge(Request $request, DryerClient $dryer): JsonResponse
|
||||
{
|
||||
abort_unless($request->user()->role === 'admin', 403);
|
||||
try {
|
||||
return response()->json($dryer->acknowledge());
|
||||
} catch (Throwable $exception) {
|
||||
report($exception);
|
||||
|
||||
return response()->json(['message' => 'Dryer fault could not be acknowledged.'], 503);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user