Skip to content

Commit

Permalink
Make inputs and sources optional
Browse files Browse the repository at this point in the history
  • Loading branch information
shirte committed Dec 21, 2024
1 parent 59057df commit 2165f91
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions nerdd_backend/routers/dynamic.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json
import logging
from typing import List, Union
from typing import List, Optional, Union

from fastapi import APIRouter, Body, Depends, HTTPException, Query, Request, UploadFile
from pydantic import create_model, model_validator
Expand Down Expand Up @@ -77,11 +77,17 @@ async def _create_job(
request: Request = None,
):
if "job_type" in params and params["job_type"] != module.name:
return HTTPException(
raise HTTPException(
status_code=400,
detail="job_type was specified, but it does not match the module name",
)

if len(inputs) == 0 and len(sources) == 0:
raise HTTPException(
status_code=400,
detail="At least one input or source must be provided",
)

result_source = await put_multiple_sources(inputs, sources, files, request)

return await create_job(
Expand All @@ -97,12 +103,16 @@ async def _create_job(
# GET /jobs
#
async def create_simple_job(
inputs: List[str] = Query(),
sources: List[str] = Query(),
inputs: Optional[List[str]] = Query(default=None),
sources: Optional[List[str]] = Query(default=None),
params: QueryModelGet = Depends(),
request: Request = None,
):
return await _create_job(inputs, sources, [], params.dict(), request)
if inputs is None:
inputs = []
if sources is None:
sources = []
return await _create_job(inputs, sources, [], params.model_dump(), request)

router.get(f"/{module.name}" "/jobs/", include_in_schema=False)(create_simple_job)
router.get(f"/{module.name}" "/jobs")(create_simple_job)
Expand Down

0 comments on commit 2165f91

Please sign in to comment.