Skip to content

Commit

Permalink
Merge branch 'arteevraina-get-all-packages-api'
Browse files Browse the repository at this point in the history
  • Loading branch information
henilp105 committed Feb 11, 2023
2 parents b7a197e + 76285d6 commit cd8c0a5
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions flask/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,28 @@ def delete_package_version(namespace_name, package_name, version):
return jsonify({"status": "error", "message": "Package version not found"}), 404


@app.route("/packages/list", methods=["GET"])
def get_packages():
page = int(request.args.get("page", 0))

packages = db.packages.find().limit(10).skip(page * 10)
response_packages = []
for package in packages:
# Get the namespace id of the package.
namespace_id = package["namespace"]

# Get the namespace document from namespace id.
namespace = db.namespaces.find_one({"_id": namespace_id})

response_packages.append({
"package_name": package["name"],
"namespace_name": namespace["namespace"],
"description": package["description"],
})

return jsonify({"packages": response_packages})


def sort_versions(versions):
"""
Sorts the list of version in the reverse order. Such that the latest version comes at
Expand Down

0 comments on commit cd8c0a5

Please sign in to comment.