Skip to content

Commit 9a27fcb

Browse files
committed
comma separated filter in categories endpoint
1 parent 911b95f commit 9a27fcb

File tree

2 files changed

+66
-15
lines changed

2 files changed

+66
-15
lines changed

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,61 @@ Returns a JSON object with the following schema:
5454
]
5555
```
5656

57+
### `GET /categories`
58+
59+
This endpoint can return a full list of categories names or a categories with all the associated technologies
60+
61+
#### Parameters
62+
63+
The following parameters can be used to filter the data:
64+
65+
- `category` (`required`): A comma-separated string representing the category name(s).
66+
- `onlyname` (optional): A string 'true' or 'false'.
67+
68+
#### Response
69+
70+
```bash
71+
curl --request GET \
72+
--url 'https://dev-gw-2vzgiib6.uk.gateway.dev/v1/categories?category=Domain%20parking%2CCI'
73+
```
74+
75+
```json
76+
[
77+
{
78+
"technologies": [
79+
"Arsys Domain Parking"
80+
],
81+
"origins": 11,
82+
"category": "Domain parking"
83+
},
84+
{
85+
"technologies": [
86+
"Jenkins",
87+
"TeamCity"
88+
],
89+
"origins": 20,
90+
"category": "CI"
91+
}
92+
]
93+
```
94+
95+
```bash
96+
curl --request GET \
97+
--url 'https://dev-gw-2vzgiib6.uk.gateway.dev/v1/categories?onlyname=true'
98+
```
99+
100+
```json
101+
[
102+
"Blogs",
103+
"LMS",
104+
"CI",
105+
"Cross border ecommerce",
106+
"Cart abandonment",
107+
"Domain parking",
108+
...
109+
]
110+
111+
```
57112

58113
### `GET /technologies`
59114

functions/categories/libs/queries.py

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,24 @@ def list_data(params):
1111

1212
query = ref
1313

14-
if 'technology' in params:
15-
params_array = convert_to_array(params['technology'])
16-
query = query.where('technology', 'in', params_array)
17-
18-
if 'category' in params:
19-
params_array = convert_to_array(params['category'])
20-
query = query.where('category', 'in', params_array)
21-
22-
documents = query.stream()
23-
2414
data = []
2515

2616
if 'onlyname' in params:
17+
documents = query.stream()
2718

2819
for doc in documents:
29-
item = doc.to_dict()
30-
if 'category' in item:
31-
data.append(item['category'])
20+
item = doc.to_dict()
21+
if 'category' in item:
22+
data.append(item['category'])
3223

3324
else:
3425

35-
for doc in documents:
36-
data.append(doc.to_dict())
26+
if 'category' in params:
27+
category_array = convert_to_array(params['category'])
28+
29+
for category in category_array:
30+
results = DB.collection(u'categories').where("category", "==", category).stream()
31+
for doc in results:
32+
data.append(doc.to_dict())
3733

3834
return Result(result=data)

0 commit comments

Comments
 (0)