mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-04-24 15:27:17 +00:00
return description from the search
This commit is contained in:
parent
d19deb57e7
commit
117e69c906
@ -34,7 +34,7 @@
|
||||
success: function (resp) {
|
||||
const $options = resp.map(function (pkg) {
|
||||
const $option = document.createElement("option");
|
||||
$option.value = pkg;
|
||||
$option.value = `${pkg.package} (${pkg.description})`;
|
||||
return $option;
|
||||
});
|
||||
$knownPackages.empty().append($options);
|
||||
|
@ -20,7 +20,7 @@
|
||||
import aur # type: ignore
|
||||
|
||||
from aiohttp.web import Response, json_response
|
||||
from typing import Iterator
|
||||
from typing import Callable, Iterator
|
||||
|
||||
from ahriman.web.views.base import BaseView
|
||||
|
||||
@ -36,7 +36,7 @@ class SearchView(BaseView):
|
||||
|
||||
search string (non empty) must be supplied as `for` parameter
|
||||
|
||||
:return: 200 with found package bases sorted by name
|
||||
:return: 200 with found package bases and descriptions sorted by base
|
||||
"""
|
||||
search: Iterator[str] = filter(lambda s: len(s) > 3, self.request.query.getall("for", default=[]))
|
||||
search_string = " ".join(search)
|
||||
@ -45,4 +45,11 @@ class SearchView(BaseView):
|
||||
return json_response(text="Search string must not be empty", status=400)
|
||||
packages = aur.search(search_string)
|
||||
|
||||
return json_response(sorted(package.package_base for package in packages))
|
||||
comparator: Callable[[aur.Package], str] = lambda item: str(item.package_base)
|
||||
response = [
|
||||
{
|
||||
"package": package.package_base,
|
||||
"description": package.description,
|
||||
} for package in sorted(packages, key=comparator)
|
||||
]
|
||||
return json_response(response)
|
||||
|
@ -12,7 +12,8 @@ async def test_get(client: TestClient, aur_package_ahriman: aur.Package, mocker:
|
||||
response = await client.get("/service-api/v1/search", params={"for": "ahriman"})
|
||||
|
||||
assert response.ok
|
||||
assert await response.json() == ["ahriman"]
|
||||
assert await response.json() == [{"package": aur_package_ahriman.package_base,
|
||||
"description": aur_package_ahriman.description}]
|
||||
|
||||
|
||||
async def test_get_exception(client: TestClient, mocker: MockerFixture) -> None:
|
||||
|
Loading…
Reference in New Issue
Block a user