Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| ShortcutCategoryPositionController | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
30 | |
0.00% |
0 / 1 |
| update | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
30 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Controllers\v1; |
| 4 | |
| 5 | use App\Http\Controllers\Controller; |
| 6 | use App\Http\Models\ShortcutCategoryPosition; |
| 7 | use App\Http\Models\ShortcutSubCategoryLv1Position; |
| 8 | use App\Http\Models\ShortcutSubCategoryLv2Position; |
| 9 | use App\Http\Services\ShortcutCategoryPositionService; |
| 10 | use App\Http\Services\ShortcutCategoryPositionServiceLv1; |
| 11 | use App\Http\Services\ShortcutCategoryPositionServiceLv2; |
| 12 | use Illuminate\Http\JsonResponse; |
| 13 | use Illuminate\Http\Request; |
| 14 | use Illuminate\Support\Facades\Cache; |
| 15 | |
| 16 | class ShortcutCategoryPositionController extends Controller |
| 17 | { |
| 18 | public function update(Request $request): JsonResponse |
| 19 | { |
| 20 | $data = $request->validate([ |
| 21 | 'positions' => 'required|array', |
| 22 | 'positions.*' => 'required|string', |
| 23 | 'type' => 'string|nullable', |
| 24 | ]); |
| 25 | |
| 26 | $userId = $request->user()->getKey(); |
| 27 | $searchArray = ['user_id' => $userId]; |
| 28 | |
| 29 | if ($request['type'] && $request['type'] == 'categorylv1') { |
| 30 | unset($data['type']); |
| 31 | ShortcutSubCategoryLv1Position::where($searchArray)->update($data); |
| 32 | $obj = new ShortcutCategoryPositionServiceLv1(); |
| 33 | $obj->updateCategorySequence($data['positions']); |
| 34 | } elseif ($request['type'] && $request['type'] == 'categorylv2') { |
| 35 | unset($data['type']); |
| 36 | |
| 37 | ShortcutSubCategoryLv2Position::where($searchArray)->update($data); |
| 38 | $obj = new ShortcutCategoryPositionServiceLv2(); |
| 39 | $obj->updateCategorySequence($data['positions']); |
| 40 | } else { |
| 41 | ShortcutCategoryPosition::where($searchArray)->update($data); |
| 42 | $obj = new ShortcutCategoryPositionService(); |
| 43 | $obj->updateCategorySequence($data['positions']); |
| 44 | } |
| 45 | |
| 46 | return response()->json(true); |
| 47 | } |
| 48 | } |