refactored example request
This commit is contained in:
@@ -9,6 +9,7 @@ use App\Models\Project;
|
||||
use App\Models\Ticket;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
@@ -49,15 +50,21 @@ class ProjectBoardController extends Controller
|
||||
403,
|
||||
);
|
||||
|
||||
$validated = $request->validated();
|
||||
$boardColumnId = Arr::get($validated, 'board_column_id');
|
||||
$redirectRoute = Arr::get($validated, 'redirect_to') === 'backlog'
|
||||
? 'projects.backlog.index'
|
||||
: 'projects.board.index';
|
||||
|
||||
$destinationColumn = $project->boardColumns()
|
||||
->find($request->boardColumnId());
|
||||
->find($boardColumnId);
|
||||
|
||||
$originBoardColumnId = $ticket->board_column_id;
|
||||
$originLabel = $ticket->boardColumn?->name ?? 'Backlog';
|
||||
$destinationLabel = $destinationColumn?->name ?? 'Backlog';
|
||||
|
||||
if ($ticket->board_column_id === $request->boardColumnId()) {
|
||||
return to_route($request->redirectRouteName(), $project)
|
||||
if ($ticket->board_column_id === $boardColumnId) {
|
||||
return to_route($redirectRoute, $project)
|
||||
->with('status', "{$ticket->ticket_key} already belongs to {$destinationLabel}.");
|
||||
}
|
||||
|
||||
@@ -82,7 +89,7 @@ class ProjectBoardController extends Controller
|
||||
],
|
||||
);
|
||||
|
||||
return to_route($request->redirectRouteName(), $project)
|
||||
return to_route($redirectRoute, $project)
|
||||
->with('status', "{$ticket->ticket_key} moved to {$destinationLabel}.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,22 +36,4 @@ class MoveProjectTicketRequest extends FormRequest
|
||||
'redirect_to' => ['required', 'string', Rule::in(['backlog', 'board'])],
|
||||
];
|
||||
}
|
||||
|
||||
public function boardColumnId(): ?int
|
||||
{
|
||||
$boardColumnId = $this->validated('board_column_id');
|
||||
|
||||
if ($boardColumnId === null || $boardColumnId === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (int) $boardColumnId;
|
||||
}
|
||||
|
||||
public function redirectRouteName(): string
|
||||
{
|
||||
return $this->validated('redirect_to') === 'backlog'
|
||||
? 'projects.backlog.index'
|
||||
: 'projects.board.index';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user