Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
gammamatrix committed Apr 30, 2024
1 parent b338db3 commit 095d929
Show file tree
Hide file tree
Showing 56 changed files with 2,749 additions and 875 deletions.
130 changes: 67 additions & 63 deletions src/Http/Controllers/BoardController.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

declare(strict_types=1);
/**
* Playground
*/

declare(strict_types=1);
namespace Playground\Matrix\Resource\Http\Controllers;

use Illuminate\Http\JsonResponse;
Expand All @@ -12,18 +12,8 @@
use Illuminate\Support\Carbon;
use Illuminate\View\View;
use Playground\Matrix\Models\Board;
use Playground\Matrix\Resource\Http\Requests\Board\CreateRequest;
use Playground\Matrix\Resource\Http\Requests\Board\DestroyRequest;
use Playground\Matrix\Resource\Http\Requests\Board\EditRequest;
use Playground\Matrix\Resource\Http\Requests\Board\IndexRequest;
use Playground\Matrix\Resource\Http\Requests\Board\LockRequest;
use Playground\Matrix\Resource\Http\Requests\Board\RestoreRequest;
use Playground\Matrix\Resource\Http\Requests\Board\ShowRequest;
use Playground\Matrix\Resource\Http\Requests\Board\StoreRequest;
use Playground\Matrix\Resource\Http\Requests\Board\UnlockRequest;
use Playground\Matrix\Resource\Http\Requests\Board\UpdateRequest;
use Playground\Matrix\Resource\Http\Resources\Board as BoardResource;
use Playground\Matrix\Resource\Http\Resources\BoardCollection;
use Playground\Matrix\Resource\Http\Requests;
use Playground\Matrix\Resource\Http\Resources;

/**
* \Playground\Matrix\Resource\Http\Controllers\BoardController
Expand Down Expand Up @@ -55,8 +45,9 @@ class BoardController extends Controller
* @route GET /resource/matrix/boards/create playground.matrix.resource.boards.create
*/
public function create(
CreateRequest $request
Requests\Board\CreateRequest $request
): JsonResponse|View {

$validated = $request->validated();

$user = $request->user();
Expand Down Expand Up @@ -95,10 +86,7 @@ public function create(
session()->flashInput($flash);
}

return view(
'playground-matrix-resource::board/form',
$data
);
return view(sprintf('%1$s/form', $this->packageInfo['view']), $data);
}

/**
Expand All @@ -108,8 +96,9 @@ public function create(
*/
public function edit(
Board $board,
EditRequest $request
Requests\Board\EditRequest $request
): JsonResponse|View {

$validated = $request->validated();

$user = $request->user();
Expand Down Expand Up @@ -144,10 +133,7 @@ public function edit(

session()->flashInput($flash);

return view(
'playground-matrix-resource::board/form',
$data
);
return view(sprintf('%1$s/form', $this->packageInfo['view']), $data);
}

/**
Expand All @@ -157,8 +143,9 @@ public function edit(
*/
public function destroy(
Board $board,
DestroyRequest $request
Requests\Board\DestroyRequest $request
): Response|RedirectResponse {

$validated = $request->validated();

if (empty($validated['force'])) {
Expand All @@ -177,7 +164,7 @@ public function destroy(
return redirect($returnUrl);
}

return redirect(route('playground.matrix.resource.boards'));
return redirect(route($this->packageInfo['model_route']));
}

/**
Expand All @@ -187,13 +174,14 @@ public function destroy(
*/
public function lock(
Board $board,
LockRequest $request
): JsonResponse|RedirectResponse|BoardResource {
Requests\Board\LockRequest $request
): JsonResponse|RedirectResponse|Resources\Board {

$validated = $request->validated();

$user = $request->user();

$board->setAttribute('locked', true);
$board->locked = true;

$board->save();

Expand All @@ -205,7 +193,7 @@ public function lock(
];

if ($request->expectsJson()) {
return (new BoardResource($board))->response($request);
return (new Resources\Board($board))->response($request);
}

$returnUrl = $validated['_return_url'] ?? '';
Expand All @@ -214,7 +202,10 @@ public function lock(
return redirect($returnUrl);
}

return redirect(route('playground.matrix.resource.boards.show', ['board' => $board->id]));
return redirect(route(sprintf(
'%1$s.show',
$this->packageInfo['model_route']
), ['board' => $board->id]));
}

/**
Expand All @@ -223,8 +214,9 @@ public function lock(
* @route GET /resource/matrix playground.matrix.resource.boards
*/
public function index(
IndexRequest $request
): JsonResponse|View|BoardCollection {
Requests\Board\IndexRequest $request
): JsonResponse|View|Resources\BoardCollection {

$user = $request->user();

$validated = $request->validated();
Expand All @@ -234,6 +226,7 @@ public function index(
$query->sort($validated['sort'] ?? null);

if (! empty($validated['filter']) && is_array($validated['filter'])) {

$query->filterTrash($validated['filter']['trash'] ?? null);

$query->filterIds(
Expand All @@ -258,12 +251,12 @@ public function index(
}

$perPage = ! empty($validated['perPage']) && is_int($validated['perPage']) ? $validated['perPage'] : null;
$paginator = $query->paginate( $perPage);
$paginator = $query->paginate($perPage);

$paginator->appends($validated);

if ($request->expectsJson()) {
return (new BoardCollection($paginator))->response($request);
return (new Resources\BoardCollection($paginator))->response($request);
}

$meta = [
Expand All @@ -284,10 +277,7 @@ public function index(
'meta' => $meta,
];

return view(
'playground-matrix-resource::board/index',
$data
);
return view(sprintf('%1$s/index', $this->packageInfo['view']), $data);
}

/**
Expand All @@ -297,16 +287,17 @@ public function index(
*/
public function restore(
Board $board,
RestoreRequest $request
): JsonResponse|RedirectResponse|BoardResource {
Requests\Board\RestoreRequest $request
): JsonResponse|RedirectResponse|Resources\Board {

$validated = $request->validated();

$user = $request->user();

$board->restore();

if ($request->expectsJson()) {
return (new BoardResource($board))->response($request);
return (new Resources\Board($board))->response($request);
}

$returnUrl = $validated['_return_url'] ?? '';
Expand All @@ -315,7 +306,10 @@ public function restore(
return redirect($returnUrl);
}

return redirect(route('playground.matrix.resource.boards.show', ['board' => $board->id]));
return redirect(route(sprintf(
'%1$s.show',
$this->packageInfo['model_route']
), ['board' => $board->id]));
}

/**
Expand All @@ -325,8 +319,9 @@ public function restore(
*/
public function show(
Board $board,
ShowRequest $request
): JsonResponse|View|BoardResource {
Requests\Board\ShowRequest $request
): JsonResponse|View|Resources\Board {

$validated = $request->validated();

$user = $request->user();
Expand All @@ -340,7 +335,7 @@ public function show(
];

if ($request->expectsJson()) {
return (new BoardResource($board))->response($request);
return (new Resources\Board($board))->response($request);
}

$meta['input'] = $request->input();
Expand All @@ -351,10 +346,7 @@ public function show(
'meta' => $meta,
];

return view(
'playground-matrix-resource::board/detail',
$data
);
return view(sprintf('%1$s/detail', $this->packageInfo['view']), $data);
}

/**
Expand All @@ -363,8 +355,9 @@ public function show(
* @route POST /resource/matrix playground.matrix.resource.boards.post
*/
public function store(
StoreRequest $request
): Response|JsonResponse|RedirectResponse|BoardResource {
Requests\Board\StoreRequest $request
): Response|JsonResponse|RedirectResponse|Resources\Board {

$validated = $request->validated();

$user = $request->user();
Expand All @@ -374,7 +367,7 @@ public function store(
$board->save();

if ($request->expectsJson()) {
return (new BoardResource($board))->response($request);
return (new Resources\Board($board))->response($request);
}

$returnUrl = $validated['_return_url'] ?? '';
Expand All @@ -383,7 +376,10 @@ public function store(
return redirect($returnUrl);
}

return redirect(route('playground.matrix.resource.boards.show', ['board' => $board->id]));
return redirect(route(sprintf(
'%1$s.show',
$this->packageInfo['model_route']
), ['board' => $board->id]));
}

/**
Expand All @@ -393,18 +389,19 @@ public function store(
*/
public function unlock(
Board $board,
UnlockRequest $request
): JsonResponse|RedirectResponse|BoardResource {
Requests\Board\UnlockRequest $request
): JsonResponse|RedirectResponse|Resources\Board {

$validated = $request->validated();

$user = $request->user();

$board->setAttribute('locked', false);
$board->locked = false;

$board->save();

if ($request->expectsJson()) {
return (new BoardResource($board))->response($request);
return (new Resources\Board($board))->response($request);
}

$returnUrl = $validated['_return_url'] ?? '';
Expand All @@ -413,7 +410,10 @@ public function unlock(
return redirect($returnUrl);
}

return redirect(route('playground.matrix.resource.boards.show', ['board' => $board->id]));
return redirect(route(sprintf(
'%1$s.show',
$this->packageInfo['model_route']
), ['board' => $board->id]));
}

/**
Expand All @@ -423,16 +423,17 @@ public function unlock(
*/
public function update(
Board $board,
UpdateRequest $request
): JsonResponse|RedirectResponse|BoardResource {
Requests\Board\UpdateRequest $request
): JsonResponse|RedirectResponse|Resources\Board {

$validated = $request->validated();

$user = $request->user();

$board->update($validated);

if ($request->expectsJson()) {
return (new BoardResource($board))->response($request);
return (new Resources\Board($board))->response($request);
}

$returnUrl = $validated['_return_url'] ?? '';
Expand All @@ -441,6 +442,9 @@ public function update(
return redirect($returnUrl);
}

return redirect(route('playground.matrix.resource.boards.show', ['board' => $board->id]));
return redirect(route(sprintf(
'%1$s.show',
$this->packageInfo['model_route']
), ['board' => $board->id]));
}
}
Loading

0 comments on commit 095d929

Please sign in to comment.