DTO for search results
This commit is contained in:
@@ -17,6 +17,7 @@ final readonly class SearchResult implements JsonSerializable
|
|||||||
public array $notConserved,
|
public array $notConserved,
|
||||||
public array $findings,
|
public array $findings,
|
||||||
public array $underwater,
|
public array $underwater,
|
||||||
|
public int $count,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function jsonSerialize(): array
|
public function jsonSerialize(): array
|
||||||
@@ -26,6 +27,7 @@ final readonly class SearchResult implements JsonSerializable
|
|||||||
"notConserved" => $this->notConserved,
|
"notConserved" => $this->notConserved,
|
||||||
"findings" => $this->findings,
|
"findings" => $this->findings,
|
||||||
"underwater" => $this->underwater,
|
"underwater" => $this->underwater,
|
||||||
|
"count" => $this->count,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -29,7 +29,7 @@ final class SearchService
|
|||||||
$filters = $this->normalizeFilters($rawFilters);
|
$filters = $this->normalizeFilters($rawFilters);
|
||||||
|
|
||||||
// No results should be returned if no filter is valid
|
// No results should be returned if no filter is valid
|
||||||
if (empty($filters)) return new SearchResult([], [], [], []);
|
if (empty($filters)) return new SearchResult([], [], [], [], 0);
|
||||||
|
|
||||||
$sites = [];
|
$sites = [];
|
||||||
if (!(count($filters) === 1 && isset($filters['category']))) {
|
if (!(count($filters) === 1 && isset($filters['category']))) {
|
||||||
@@ -49,6 +49,7 @@ final class SearchService
|
|||||||
notConserved: [],
|
notConserved: [],
|
||||||
findings: $findings,
|
findings: $findings,
|
||||||
underwater: [],
|
underwater: [],
|
||||||
|
count: count($sites) + count($findings)
|
||||||
);
|
);
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
|||||||
Reference in New Issue
Block a user