-
-
Notifications
You must be signed in to change notification settings - Fork 366
Expand file tree
/
Copy pathSearchController.php
More file actions
58 lines (49 loc) · 1.5 KB
/
SearchController.php
File metadata and controls
58 lines (49 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/**
* SPDX-License-Identifier: MIT
* Copyright (c) 2017-2018 Tobias Reich
* Copyright (c) 2018-2025 LycheeOrg.
*/
namespace App\Http\Controllers\Gallery;
use App\Actions\Search\AlbumSearch;
use App\Actions\Search\PhotoSearch;
use App\Enum\ColumnSortingPhotoType;
use App\Enum\OrderSortingType;
use App\Http\Requests\Search\GetSearchRequest;
use App\Http\Requests\Search\InitSearchRequest;
use App\Http\Resources\Search\InitResource;
use App\Http\Resources\Search\ResultsResource;
use App\Models\Album;
use App\Models\Configs;
use Illuminate\Routing\Controller;
/**
* Controller responsible for the config.
*/
class SearchController extends Controller
{
/**
* Return init Search.
*/
public function init(InitSearchRequest $request): InitResource
{
return new InitResource();
}
/**
* Get the search results given a query.
*/
public function search(GetSearchRequest $request, AlbumSearch $album_search, PhotoSearch $photo_search): ResultsResource
{
$terms = $request->terms();
$album = $request->album();
if (!$album instanceof Album) {
$album = null;
}
/** @disregard P1013 Undefined method withQueryString() (stupid intelephense) */
$photo_results = $photo_search
->sqlQuery($terms, $album)
->orderBy(ColumnSortingPhotoType::TAKEN_AT->value, OrderSortingType::ASC->value)
->paginate(Configs::getValueAsInt('search_pagination_limit'));
$album_results = $album_search->queryAlbums($terms, $album);
return ResultsResource::fromData($album_results, $photo_results);
}
}