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