refactor: route calc through service layer
This commit is contained in:
@@ -2,7 +2,7 @@ from api.core.Gzip import register_gzip_request
|
||||
from fastapi import APIRouter, Body
|
||||
from api.core.Response import response
|
||||
from api.dp import AltersDep
|
||||
from core.basic.character import createCharacter
|
||||
from services.calc_service import calculate
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -11,5 +11,4 @@ register_gzip_request(router)
|
||||
|
||||
@router.post('/calc')
|
||||
async def calc(state: AltersDep, config=Body(None)):
|
||||
character = createCharacter(state.alter, state.equVersion)
|
||||
return response(data=character.calc(config))
|
||||
return response(data=calculate(state, config))
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
"""Application services for backend API orchestration."""
|
||||
@@ -0,0 +1,10 @@
|
||||
from typing import Any
|
||||
|
||||
from api.core.Auth import AlterState
|
||||
from core.basic.character import createCharacter
|
||||
|
||||
|
||||
def calculate(state: AlterState, config: dict[str, Any] | None) -> dict[str, Any]:
|
||||
safe_config = config or {}
|
||||
character = createCharacter(state.alter, state.equVersion)
|
||||
return character.calc(safe_config)
|
||||
@@ -0,0 +1,11 @@
|
||||
from api.core.Auth import AlterState
|
||||
from services.calc_service import calculate
|
||||
|
||||
|
||||
def test_calculate_returns_character_calc_result(minimal_calc_config):
|
||||
state = AlterState('GF.swordman_male.weapon_master', 'token', {}, '0', 0)
|
||||
|
||||
result = calculate(state, minimal_calc_config)
|
||||
|
||||
assert isinstance(result, dict)
|
||||
assert set(['uuid', 'skills', 'info', 'suits', 'buffer']).issubset(result)
|
||||
Reference in New Issue
Block a user