Skip to content

Commit

Permalink
Adding search and build to /api/v1/build/<build-id>/package/ route (#193
Browse files Browse the repository at this point in the history
)

* Adding search and build to /api/v1/build/<build-id>/package/ route

Closes #190

* Black formatting
  • Loading branch information
costrouc authored Oct 19, 2021
1 parent bb6247d commit 0f25a65
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
10 changes: 8 additions & 2 deletions conda-store-server/conda_store_server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,18 @@ def get_build(db, build_id: int):
return db.query(orm.Build).filter(orm.Build.id == build_id).first()


def get_build_packages(db, build_id: int):
def get_build_packages(db, build_id: int, search: str = None, build: str = None):
filters = [(orm.build_conda_package.c.build_id == build_id)]
if search:
filters.append(orm.CondaPackage.name.contains(search, autoescape=True))
if build:
filters.append(orm.CondaPackage.build.contains(build, autoescape=True))

return (
db.query(orm.CondaPackage)
.join(orm.build_conda_package)
.join(orm.CondaChannel)
.filter(orm.build_conda_package.c.build_id == build_id)
.filter(*filters)
)


Expand Down
6 changes: 5 additions & 1 deletion conda-store-server/conda_store_server/server/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,11 @@ def api_get_build_packages(build_id):
require=True,
)

orm_packages = api.get_build_packages(conda_store.db, build.id)
search = request.args.get("search")
build_str = request.args.get("build")
orm_packages = api.get_build_packages(
conda_store.db, build.id, search=search, build=build_str
)
return paginated_api_response(
orm_packages,
schema.CondaPackage,
Expand Down
7 changes: 6 additions & 1 deletion docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,12 @@ release and make it available on [PyPi](https://pypi.org/),

- `GET /api/v1/build/<build_id>/logs/` :: get build logs

- `GET /api/v1/build/<build_id>/packages/?page=<int>&size=<int>&sort_by=<str>&order=<str>` :: list packages within build
- `GET /api/v1/build/<build_id>/packages/?search=<str>&build=<str>&page=<int>&size=<int>&sort_by=<str>&order=<str>` :: list packages within build
- allowed `sort_by` values : `channel` to sort by channel name, `name` to sort by package name
- `build` string to search within `build` for example strings include
`py27_0` etc which can be useful for filtering specific versions of
packages.
- `search` will search within the package names for a match

### Conda Channels

Expand All @@ -162,6 +166,7 @@ release and make it available on [PyPi](https://pypi.org/),
- `build` string to search within `build` for example strings include
`py27_0` etc which can be useful for filtering specific versions of
packages.
- `search` will search within the package names for a match

### REST API query format

Expand Down

0 comments on commit 0f25a65

Please sign in to comment.