-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemp.txt
More file actions
33 lines (24 loc) · 1.03 KB
/
temp.txt
File metadata and controls
33 lines (24 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
@app.route('/packages', methods=['POST'])
def packages_list():
# Parse request body
package_queries = request.json
for query in package_queries:
if 'Name' not in query:
return jsonify({'error': "There is missing field(s) in the PackageQuery/AuthenticationToken\
\ or it is formed improperly, or the AuthenticationToken is invalid."}), 400
# Check for pagination offset
offset = request.args.get('offset', 0)
print("offset ", offset)
# Mock database query
results = []
for package in PACKAGES:
for query in package_queries:
print(query)
if query == '*' or query == package['Name']:
results.append(package)
# Apply pagination
paginated_results = results[int(offset):int(offset)+10] # limit to 10 results per page
# Generate response
response = jsonify(paginated_results)
response.headers.add('offset', str(int(offset)+10)) # set next page offset in response header
return response, 200