Skip to content
This repository was archived by the owner on May 7, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/diffcalc_API/models/UBCalculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ class editOrientationParams(BaseModel):
xyz: Optional[Tuple[float, float, float]] = None
position: Optional[Tuple[float, float, float, float, float, float]] = None
tagOrIdx: Union[int, str]


class deleteParams(BaseModel):
Comment thread
rosesyrett marked this conversation as resolved.
tagOrIdx: Union[int, str]
30 changes: 15 additions & 15 deletions src/diffcalc_API/routes/UBCalculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from diffcalc_API.models.UBCalculation import (
addOrientationParams,
addReflectionParams,
deleteParams,
editOrientationParams,
editReflectionParams,
setLatticeParams,
Expand All @@ -26,11 +27,6 @@
router = APIRouter(prefix="/ub", tags=["ub"])


@router.get("/")
async def read_main():
return {"msg": "Hello World"}


@router.put("/{name}/reflection")
async def add_reflection(
name: str,
Expand All @@ -54,7 +50,12 @@ async def add_reflection(
)

persist(hklCalc, name)
return {"message": f"added reflection for UB Calculation of crystal {name}"}
return {
"message": (
f"added reflection for UB Calculation of crystal {name}. "
f"Reflist is: {hklCalc.ubcalc.reflist.reflections}"
)
}


@router.put("/{name}/orientation")
Expand Down Expand Up @@ -111,7 +112,6 @@ async def edit_reflection(
persist: Callable[[HklCalculation, str], Path] = Depends(supplyPersist),
):
reflection = get_reflection(hklCalc, params.tagOrIdx)

hklCalc.ubcalc.edit_reflection(
params.tagOrIdx,
params.hkl if params.hkl else (reflection.h, reflection.k, reflection.l),
Expand Down Expand Up @@ -189,26 +189,26 @@ async def calculate_UB(
@router.delete("/{name}/reflection")
async def delete_reflection(
name: str,
tagOrIdx: Union[str, int] = Body(..., example="refl1"),
params: deleteParams = Body(..., example={"tagOrIdx": "refl1"}),
hklCalc: HklCalculation = Depends(unpickleHkl),
persist: Callable[[HklCalculation, str], Path] = Depends(supplyPersist),
):
_ = get_reflection(hklCalc, tagOrIdx)
hklCalc.ubcalc.del_reflection(tagOrIdx)
_ = get_reflection(hklCalc, params.tagOrIdx)
hklCalc.ubcalc.del_reflection(params.tagOrIdx)
persist(hklCalc, name)

return {"message": f"reflection with tag or index {tagOrIdx} deleted."}
return {"message": f"reflection with tag or index {params.tagOrIdx} deleted."}


@router.delete("/{name}/orientation")
async def delete_orientation(
name: str,
tagOrIdx: Union[str, int] = Body(..., example="plane"),
params: deleteParams = Body(..., example={"tagOrIdx": "plane"}),
hklCalc: HklCalculation = Depends(unpickleHkl),
persist: Callable[[HklCalculation, str], Path] = Depends(supplyPersist),
):
_ = get_orientation(hklCalc, tagOrIdx)
hklCalc.ubcalc.del_orientation(tagOrIdx)
_ = get_orientation(hklCalc, params.tagOrIdx)
hklCalc.ubcalc.del_orientation(params.tagOrIdx)
persist(hklCalc, name)

return {"message": f"reflection with tag or index {tagOrIdx} deleted."}
return {"message": f"reflection with tag or index {params.tagOrIdx} deleted."}
5 changes: 0 additions & 5 deletions tests/test_diffcalc_API.py

This file was deleted.

8 changes: 4 additions & 4 deletions tests/test_ubcalc.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def test_edit_reflection(client: TestClient):

def test_delete_reflection(client: TestClient):
dummyHkl.ubcalc.add_reflection([0, 0, 1], Position(7, 0, 10, 0, 0, 0), 12, "foo")
response = client.delete("/ub/test/reflection", json="foo")
response = client.delete("/ub/test/reflection", json={"tagOrIdx": "foo"})

assert response.status_code == 200
with pytest.raises(Exception):
Expand All @@ -87,7 +87,7 @@ def test_edit_or_delete_reflection_fails_for_non_existing_reflection(
)
deleteResponse = client.delete(
"/ub/test/reflection",
json="foo",
json={"tagOrIdx": "foo"},
)

assert editResponse.status_code == codes.get_reflection
Expand Down Expand Up @@ -134,7 +134,7 @@ def test_delete_orientation(client: TestClient):
dummyHkl.ubcalc.add_orientation([0, 0, 1], [0, 0, 1], None, "bar")
response = client.delete(
"/ub/test/orientation",
json="bar",
json={"tagOrIdx": "bar"},
)

assert response.status_code == 200
Expand All @@ -154,7 +154,7 @@ def test_edit_or_delete_orientation_fails_for_non_existing_orientation(
)
deleteResponse = client.delete(
"/ub/test/orientation",
json="bar",
json={"tagOrIdx": "bar"},
)

assert editResponse.status_code == codes.get_orientation
Expand Down