Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General: Use query functions in rest api calls #3457

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 13 additions & 24 deletions openpype/modules/avalon_apps/rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@

from aiohttp.web_response import Response

from openpype.pipeline import AvalonMongoDB
from openpype.client import (
get_projects,
get_project,
get_assets,
get_asset_by_name,
)
from openpype_modules.webserver.base_routes import RestApiEndpoint


Expand All @@ -14,19 +19,13 @@ def __init__(self, resource):
self.resource = resource
super(_RestApiEndpoint, self).__init__()

@property
def dbcon(self):
return self.resource.dbcon


class AvalonProjectsEndpoint(_RestApiEndpoint):
async def get(self) -> Response:
output = []
for project_name in self.dbcon.database.collection_names():
project_doc = self.dbcon.database[project_name].find_one({
"type": "project"
})
output.append(project_doc)
output = [
project_doc
for project_doc in get_projects()
]
Comment on lines +25 to +28
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this isn't just output = list(get_projects())?

return Response(
status=200,
body=self.resource.encode(output),
Expand All @@ -36,9 +35,7 @@ async def get(self) -> Response:

class AvalonProjectEndpoint(_RestApiEndpoint):
async def get(self, project_name) -> Response:
project_doc = self.dbcon.database[project_name].find_one({
"type": "project"
})
project_doc = get_project(project_name)
if project_doc:
return Response(
status=200,
Expand All @@ -53,9 +50,7 @@ async def get(self, project_name) -> Response:

class AvalonAssetsEndpoint(_RestApiEndpoint):
async def get(self, project_name) -> Response:
asset_docs = list(self.dbcon.database[project_name].find({
"type": "asset"
}))
asset_docs = list(get_assets(project_name))
return Response(
status=200,
body=self.resource.encode(asset_docs),
Expand All @@ -65,10 +60,7 @@ async def get(self, project_name) -> Response:

class AvalonAssetEndpoint(_RestApiEndpoint):
async def get(self, project_name, asset_name) -> Response:
asset_doc = self.dbcon.database[project_name].find_one({
"type": "asset",
"name": asset_name
})
asset_doc = get_asset_by_name(project_name, asset_name)
if asset_doc:
return Response(
status=200,
Expand All @@ -88,9 +80,6 @@ def __init__(self, avalon_module, server_manager):
self.module = avalon_module
self.server_manager = server_manager

self.dbcon = AvalonMongoDB()
self.dbcon.install()

self.prefix = "/avalon"

self.endpoint_defs = (
Expand Down