diff --git a/migas/server/schema.py b/migas/server/schema.py index ca57836..6ce2d4d 100644 --- a/migas/server/schema.py +++ b/migas/server/schema.py @@ -22,6 +22,8 @@ from .models import get_project_tables from .types import ( AuthenticationResult, + BreadcrumbResult, + CheckProjectResult, Context, ContextInput, DateTime, @@ -42,16 +44,16 @@ async def get_projects(self) -> list[str]: return projs @strawberry.field - async def check_project(self, project: str, project_version: str | None = None) -> JSON: - '''Check project for latest version, developer notes, etc.''' + async def check_project(self, project: str, project_version: str) -> CheckProjectResult: + '''Check version of project for latest version, developer notes, etc.''' fetched = await fetch_project_info(project) - return { - 'bad_versions': fetched['bad_versions'], - 'cached': fetched['cached'], - 'latest_version': fetched['version'], - 'message': '', # TODO: Allow message for bad_versions - 'success': fetched['success'], - } + is_flagged = project_version in fetched['bad_versions'] + return CheckProjectResult( + success=fetched['success'], + flagged=is_flagged, + latest=fetched['version'], + # TODO: Parse/relay message + ) @strawberry.field async def get_usage( @@ -125,9 +127,9 @@ async def add_breadcrumb( language_version: str, ctx: ContextInput, proc: ProcessInput, - ) -> bool: + ) -> BreadcrumbResult: if not '/' in project: - return False + return BreadcrumbResult(success=False) context = Context( user_id=ctx.user_id, @@ -155,14 +157,14 @@ async def add_breadcrumb( bg_tasks = info.context['background_tasks'] bg_tasks.add_task(ingest_project, project) - return True + return BreadcrumbResult(success=True) @strawberry.field async def add_project(self, p: ProjectInput, info: Info) -> JSON: # validate project if not p.project or '/' not in p.project: - raise Exception("Invalid project specified.") + return {'success': False} # convert to Project and set defaults project = Project( diff --git a/migas/server/types.py b/migas/server/types.py index 35ec054..39fb96e 100644 --- a/migas/server/types.py +++ b/migas/server/types.py @@ -176,6 +176,20 @@ class AuthenticationResult: message: str +@strawberry.type +class BreadcrumbResult: + success: bool + message: str = '' + + +@strawberry.type +class CheckProjectResult: + success: bool + latest: str + flagged: bool + message: str = '' + + async def serialize(data: dict) -> dict: """Serialize data into database-friendly types""" for k, v in data.items():