Skip to content

Commit

Permalink
refactor: change of response codes for creating and deleting tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
n-kakuko committed Oct 11, 2024
1 parent a70c054 commit 6465b2a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
8 changes: 4 additions & 4 deletions backend/oas/user/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ paths:
nShots: 1000
note: Bell State Sampling Example
responses:
'200':
'201':
description: Task submitted
content:
application/json:
Expand Down Expand Up @@ -237,7 +237,7 @@ paths:
schema:
type: string
responses:
'200':
'204':
description: Quantum task deleted
content:
application/json:
Expand Down Expand Up @@ -447,7 +447,7 @@ paths:
- -2.e-8
note: Bell State Estimation Example
responses:
'200':
'201':
description: Task submitted
content:
application/json:
Expand Down Expand Up @@ -561,7 +561,7 @@ paths:
schema:
type: string
responses:
'200':
'204':
description: Quantum task deleted
content:
application/json:
Expand Down
8 changes: 4 additions & 4 deletions backend/oas/user/paths/tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ tasks.sampling:
}

responses:
"200":
"201":
description: "Task submitted"
content:
application/json:
Expand Down Expand Up @@ -159,7 +159,7 @@ tasks.sampling.taskId:
description: "Task identifier"
schema: {type: string}
responses:
"200":
"204":
description: "Quantum task deleted"
content:
application/json:
Expand Down Expand Up @@ -373,7 +373,7 @@ tasks.estimation:
}

responses:
"200":
"201":
description: "Task submitted"
content:
application/json:
Expand Down Expand Up @@ -487,7 +487,7 @@ tasks.estimation.taskId:
description: "Task identifier"
schema: {type: string}
responses:
"200":
"204":
description: "Quantum task deleted"
content:
application/json:
Expand Down
17 changes: 11 additions & 6 deletions backend/oqtopus_cloud/user/routers/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from fastapi import (
APIRouter,
Depends,
status,
)
from fastapi import Request as Event
from pydantic import ValidationError
Expand Down Expand Up @@ -315,6 +316,7 @@ def get_resources(

@router.post(
"/tasks/sampling",
status_code=status.HTTP_201_CREATED,
response_model=SubmitTaskResponse,
responses={400: {"model": Detail}, 500: {"model": Detail}},
)
Expand Down Expand Up @@ -460,15 +462,16 @@ def get_sampling_task(

@router.delete(
"/tasks/sampling/{taskId}",
response_model=SuccessResponse,
status_code=status.HTTP_204_NO_CONTENT,
response_model=None,
responses={400: {"model": Detail}, 404: {"model": Detail}, 500: {"model": Detail}},
)
@tracer.capture_method
def delete_sampling_task(
event: Event,
taskId: str,
db: Session = Depends(get_db),
) -> SuccessResponse | ErrorResponse:
) -> None | ErrorResponse:
try:
TaskId(root=uuid.UUID(taskId))
except ValidationError:
Expand All @@ -494,7 +497,7 @@ def delete_sampling_task(

db.delete(task)
db.commit()
return SuccessResponse(message="task deleted")
return
except Exception as e:
logger.info(f"error: {str(e)}")
return InternalServerErrorResponse(detail=str(e))
Expand Down Expand Up @@ -611,6 +614,7 @@ def get_estimation_tasks(

@router.post(
"/tasks/estimation",
status_code=status.HTTP_201_CREATED,
response_model=SubmitTaskResponse,
responses={400: {"model": Detail}, 500: {"model": Detail}},
)
Expand Down Expand Up @@ -784,15 +788,16 @@ def get_estimation_task(

@router.delete(
"/tasks/estimation/{taskId}",
response_model=SuccessResponse,
status_code=status.HTTP_204_NO_CONTENT,
response_model=None,
responses={400: {"model": Detail}, 404: {"model": Detail}, 500: {"model": Detail}},
)
@tracer.capture_method
def delete_estimation_task(
event: Event,
taskId: str,
db: Session = Depends(get_db),
) -> SuccessResponse | ErrorResponse:
) -> None | ErrorResponse:
try:
TaskId(root=uuid.UUID(taskId))
except ValidationError:
Expand All @@ -818,7 +823,7 @@ def delete_estimation_task(

db.delete(task)
db.commit()
return SuccessResponse(message="task deleted")
return
except Exception as e:
logger.info(f"error: {str(e)}")
return InternalServerErrorResponse(detail=str(e))
Expand Down
4 changes: 2 additions & 2 deletions backend/tests/oqtopus_cloud/user/routers/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
# }


# def test_post_task_200(
# def test_post_task_201(
# test_db,
# ):
# """_summary_
Expand Down Expand Up @@ -123,4 +123,4 @@
# note=None,
# )
# response = client.post("/tasks", content=body.model_dump_json())
# assert response.status_code == 200
# assert response.status_code == 201
8 changes: 4 additions & 4 deletions docs/oas/user/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ paths:
nShots: 1000
note: Bell State Sampling Example
responses:
'200':
'201':
description: Task submitted
content:
application/json:
Expand Down Expand Up @@ -237,7 +237,7 @@ paths:
schema:
type: string
responses:
'200':
'204':
description: Quantum task deleted
content:
application/json:
Expand Down Expand Up @@ -447,7 +447,7 @@ paths:
- -2.e-8
note: Bell State Estimation Example
responses:
'200':
'201':
description: Task submitted
content:
application/json:
Expand Down Expand Up @@ -561,7 +561,7 @@ paths:
schema:
type: string
responses:
'200':
'204':
description: Quantum task deleted
content:
application/json:
Expand Down

0 comments on commit 6465b2a

Please sign in to comment.