@@ -18,12 +18,17 @@ class SearchObjectsAPI(APIView):
1818 -------------------
1919
2020 Endpoint for use of query string based search.
21+ Four parameters are defined by this API:
22+ 1. contents: Search in the contents of the BCO
23+ 2. prefix: BCO Prefix to search
24+ 3. owner_user: Search by BCO owner
25+ 4. object_id: BCO object_id to search for
26+
27+ Shell
28+ ```shell
29+ curl -X GET "http://localhost:8000/api/objects/?contents=review&prefix=BCO&owner_user=bco_api_user&object_id=DRAFT" -H "accept: application/json"
30+ ```
2131 """
22-
23- #TODO: multiple values in the URL will only return the last one.
24-
25- authentication_classes = [CustomJSONWebTokenAuthentication ]
26- permission_classes = [AllowAny ,]
2732
2833 auth = openapi .Parameter ('test' , openapi .IN_QUERY , description = "test manual param" , type = openapi .TYPE_BOOLEAN )
2934
@@ -39,12 +44,12 @@ class SearchObjectsAPI(APIView):
3944 description = "BCO Prefix to search" ,
4045 type = openapi .TYPE_STRING
4146 ),
42- openapi .Parameter ('owner ' ,
47+ openapi .Parameter ('owner_user ' ,
4348 openapi .IN_QUERY ,
4449 description = "Search by BCO owner" ,
4550 type = openapi .TYPE_STRING
4651 ),
47- openapi .Parameter ('bco_id ' ,
52+ openapi .Parameter ('object_id ' ,
4853 openapi .IN_QUERY ,
4954 description = "BCO object_id to search for" ,
5055 type = openapi .TYPE_STRING
@@ -69,12 +74,15 @@ def get(self, request) -> Response:
6974 "state" ,
7075 ]
7176
72- search = self .request .GET
73- print (request .user .username )
77+ search = dict (self .request .GET )
7478 result = controled_list (request .user )
7579 for query , value in search .items ():
76- filter = f'{ query } __icontains'
77- result = search_db (filter , value , result )
80+ for item in value :
81+ if query == 'owner_user' :
82+ filter = f'{ query } '
83+ else :
84+ filter = f'{ query } __icontains'
85+ result = search_db (filter , item , result )
7886 search_result = chain (result .values (* return_values ))
7987 return Response (status = status .HTTP_200_OK , data = {search_result })
8088
0 commit comments