84 lines
2.6 KiB
Python
84 lines
2.6 KiB
Python
from fastapi import APIRouter, HTTPException
|
|
|
|
from app.problems.grade_1.compose_and_decompose_numbers import (
|
|
compose_and_decompose_numbers,
|
|
)
|
|
from app.problems.grade_1.join_pictures_with_quantity import (
|
|
join_pictures_with_quantity,
|
|
)
|
|
from app.problems.grade_1.where_are_more_items import where_are_more_items
|
|
from app.schemas.grade_1.compose_and_decompose_numbers import (
|
|
ComposeAndDecomposeNumbersProblem,
|
|
ComposeAndDecomposeNumbersRequest,
|
|
)
|
|
from app.schemas.grade_1.join_pictures_with_quantity import (
|
|
JoinPicturesWithQuantityProblem,
|
|
JoinPicturesWithQuantityRequest,
|
|
)
|
|
from app.schemas.grade_1.where_are_more_items import (
|
|
WhereAreMoreItemsProblem,
|
|
WhereAreMoreItemsRequest,
|
|
)
|
|
|
|
router = APIRouter(prefix="/grade_1", tags=["Grade 1"])
|
|
|
|
|
|
@router.post(
|
|
"/compose_and_decompose_numbers",
|
|
response_model=ComposeAndDecomposeNumbersProblem,
|
|
)
|
|
def create_compose_and_decompose_numbers_problem(
|
|
request: ComposeAndDecomposeNumbersRequest,
|
|
) -> dict:
|
|
try:
|
|
return compose_and_decompose_numbers(
|
|
picture=request.picture.model_dump(),
|
|
whole=request.whole,
|
|
randomize_rows=request.randomize_rows,
|
|
seed=request.seed,
|
|
)
|
|
except ValueError as exc:
|
|
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
|
|
|
|
|
@router.post(
|
|
"/join_pictures_with_quantity",
|
|
response_model=JoinPicturesWithQuantityProblem,
|
|
)
|
|
def create_join_pictures_with_quantity_problem(
|
|
request: JoinPicturesWithQuantityRequest,
|
|
) -> dict:
|
|
try:
|
|
return join_pictures_with_quantity(
|
|
available_pictures=[
|
|
picture.model_dump() for picture in request.available_pictures
|
|
],
|
|
container_count_per_side=request.container_count_per_side,
|
|
min_quantity=request.min_quantity,
|
|
max_quantity=request.max_quantity,
|
|
seed=request.seed,
|
|
)
|
|
except ValueError as exc:
|
|
raise HTTPException(status_code=400, detail=str(exc)) from exc
|
|
|
|
|
|
@router.post(
|
|
"/where_are_more_items",
|
|
response_model=WhereAreMoreItemsProblem,
|
|
)
|
|
def create_where_are_more_items_problem(
|
|
request: WhereAreMoreItemsRequest,
|
|
) -> dict:
|
|
try:
|
|
return where_are_more_items(
|
|
available_pictures=[
|
|
picture.model_dump() for picture in request.available_pictures
|
|
],
|
|
comparison_count=request.comparison_count,
|
|
min_quantity=request.min_quantity,
|
|
max_quantity=request.max_quantity,
|
|
seed=request.seed,
|
|
)
|
|
except ValueError as exc:
|
|
raise HTTPException(status_code=400, detail=str(exc)) from exc
|