2017-06-23 23:00:42 +02:00
|
|
|
from rest_framework.response import Response
|
2018-06-10 10:55:16 +02:00
|
|
|
from rest_framework.views import APIView
|
|
|
|
|
|
2017-06-23 23:00:42 +02:00
|
|
|
from funkwhale_api.common.permissions import ConditionalAuthentication
|
|
|
|
|
|
|
|
|
|
from .client import client
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class APISearch(APIView):
|
|
|
|
|
permission_classes = [ConditionalAuthentication]
|
|
|
|
|
|
|
|
|
|
def get(self, request, *args, **kwargs):
|
2018-06-09 15:36:16 +02:00
|
|
|
results = client.search(request.GET["query"])
|
|
|
|
|
return Response([client.to_funkwhale(result) for result in results])
|
2017-06-23 23:00:42 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class APISearchs(APIView):
|
|
|
|
|
permission_classes = [ConditionalAuthentication]
|
|
|
|
|
|
|
|
|
|
def post(self, request, *args, **kwargs):
|
|
|
|
|
results = client.search_multiple(request.data)
|
2018-06-09 15:36:16 +02:00
|
|
|
return Response(
|
|
|
|
|
{
|
|
|
|
|
key: [client.to_funkwhale(result) for result in group]
|
|
|
|
|
for key, group in results.items()
|
|
|
|
|
}
|
|
|
|
|
)
|