Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 6 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| SearchDataController | |
0.00% |
0 / 6 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| index | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Controllers\v2; |
| 4 | |
| 5 | use App\Http\Controllers\Controller; |
| 6 | use App\Http\Requests\v2\SearchData\SearchDataRequest; |
| 7 | use App\Http\Services\SearchDataService; |
| 8 | use Illuminate\Http\JsonResponse; |
| 9 | use Symfony\Component\HttpFoundation\Response; |
| 10 | |
| 11 | /** |
| 12 | * Search Data Controller |
| 13 | * |
| 14 | * Provides search functionality across user shortcuts (FlyCuts) and |
| 15 | * admin-created templates (FlyPlates). Searches match against title, |
| 16 | * text content, shortcut name, and first line fields. |
| 17 | */ |
| 18 | class SearchDataController extends Controller |
| 19 | { |
| 20 | public function __construct( |
| 21 | private SearchDataService $searchDataService |
| 22 | ) {} |
| 23 | |
| 24 | /** |
| 25 | * Search shortcuts and templates by query string. |
| 26 | * |
| 27 | * Returns matching shortcuts (scoped to the authenticated user) and |
| 28 | * templates (global admin content), grouped by type. |
| 29 | * |
| 30 | * @param SearchDataRequest $request Validated request containing the search query |
| 31 | * |
| 32 | * @response 200 { |
| 33 | * "data": [ |
| 34 | * { |
| 35 | * "type": "Shortcuts", |
| 36 | * "items": [ |
| 37 | * { |
| 38 | * "_id": "507f1f77bcf86cd799439011", |
| 39 | * "title": "My Shortcut", |
| 40 | * "shortcut": "/myshortcut", |
| 41 | * "first_line": "Hello, this is...", |
| 42 | * "text": "Hello, this is my shortcut content", |
| 43 | * "html": "<p>Hello, this is my shortcut content</p>", |
| 44 | * "version": 1, |
| 45 | * "category_id": "507f1f77bcf86cd799439012", |
| 46 | * "category_name": "My Category", |
| 47 | * "type": "user", |
| 48 | * "user_id": "507f1f77bcf86cd799439013", |
| 49 | * "uploads": [], |
| 50 | * "media_sizes": null, |
| 51 | * "template_id": null, |
| 52 | * "template_version": null, |
| 53 | * "template_category_id": null, |
| 54 | * "user_defined": true, |
| 55 | * "sub_categories_lv1_id": null, |
| 56 | * "sub_categories_lv2_id": null, |
| 57 | * "rollback_counts": 0, |
| 58 | * "version_counts": 1, |
| 59 | * "charactors_count": 34, |
| 60 | * "words_count": 6, |
| 61 | * "html_count": 46, |
| 62 | * "shareable": false, |
| 63 | * "reference_shares_shortcut_id": null, |
| 64 | * "flycutUsage_count": 5, |
| 65 | * "flycutUsage_time_saved": 2.5, |
| 66 | * "flycutUsage_cost_saved": 1.25, |
| 67 | * "number_of_times_used": 5, |
| 68 | * "time_saved": 2.5, |
| 69 | * "created_at": "2024-01-15T10:30:00.000000Z", |
| 70 | * "updated_at": "2024-01-15T10:30:00.000000Z" |
| 71 | * } |
| 72 | * ] |
| 73 | * }, |
| 74 | * { |
| 75 | * "type": "FlyPlates", |
| 76 | * "items": [ |
| 77 | * { |
| 78 | * "_id": "507f1f77bcf86cd799439021", |
| 79 | * "title": "Welcome Template", |
| 80 | * "shortcut": "/welcome", |
| 81 | * "first_line": "Welcome to our...", |
| 82 | * "text": "Welcome to our platform", |
| 83 | * "html": "<p>Welcome to our platform</p>", |
| 84 | * "version": 1, |
| 85 | * "category_id": "507f1f77bcf86cd799439022", |
| 86 | * "category_name": "Business Templates", |
| 87 | * "uploads": [], |
| 88 | * "type": "template", |
| 89 | * "subcategory_lv1_id": null, |
| 90 | * "subcategory_lv2_id": null, |
| 91 | * "premium": false, |
| 92 | * "unique_slug": "welcome-template", |
| 93 | * "action": "add", |
| 94 | * "created_at": "2024-01-10T08:00:00.000000Z", |
| 95 | * "updated_at": "2024-01-10T08:00:00.000000Z" |
| 96 | * } |
| 97 | * ] |
| 98 | * } |
| 99 | * ], |
| 100 | * "message": "Succeed" |
| 101 | * } |
| 102 | * @response 422 { |
| 103 | * "data": [], |
| 104 | * "message": "The query field is required." |
| 105 | * } |
| 106 | */ |
| 107 | public function index(SearchDataRequest $request): JsonResponse |
| 108 | { |
| 109 | $results = $this->searchDataService->search($request->validated('query')); |
| 110 | |
| 111 | return response()->json([ |
| 112 | 'data' => $results, |
| 113 | 'message' => 'Succeed', |
| 114 | ], Response::HTTP_OK); |
| 115 | } |
| 116 | } |