-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Goal
Implement/fix the API to reorder FormKit schema node children with optimistic concurrency, following TDD and addressing issues found in PR #21.
Requirements
Feature (from PR 21)
- POST endpoint
reorder_node_childrenacceptingparent_id,children(list of child UUIDs in desired order), and optionallatest_changefor conflict detection. - Optimistic locking: If client sends
latest_changeand it does not match server, return 409 Conflict ("change conflict"). - Validation: Only reorder when the set of
childrenexactly matches existingNodeChildrenfor that parent (same count and IDs). - Response: Return new order and updated
latest_changeso client can update cache. NodeChildrenManager.latest_change()returns current maxtrack_changefor theNodeChildrentable.
TDD (tests first)
- Keep/extend
tests/test_nodechildren.pyas the spec. - Add tests before implementation changes:
- 409 when
latest_changeis stale (no reorder). - 400/409 when children don't match (count or IDs); expect clear error, not 500.
- 200 success with updated
latest_changeand correct order persisted. - 401/403 for unauthenticated/unauthorized if endpoint is protected (then add
auth=formkit_authand permission check).
- 409 when
Implementation fixes
- Handle
reorder_childrenreturn value: on(None, "Children do not match")return 400 (or 409) with message, not 200. - Fix docstring typo: "NodeChildern" → "NodeChildren".
- Rename
chnge→current_change(or similar). - Use
exc(notE) inexceptand proper error message. - Align response type with body: define response schema (e.g.
children,latest_change,parent_id) or fix declared type to match returned payload. - Verify
latest_change()yields global maxtrack_change; add unit test that it increases after reorder; useNodeChildren.objects.aggregate(Max("track_change"))if clearer. - Add
auth=formkit_authand permission check to matchcreate_or_update_node(with test already in place).
Code quality
- Single responsibility: view handles HTTP;
reorder_children(payload)does validation and persistence. - Explicit error paths: 400 bad payload, 409 conflict, 500 unexpected.
- Do not add
poetry.lock(project uses uv). Run black, isort, flake8 on changed files.
Order of work
- Add missing tests (409, validation failure, success, auth).
- Handle
reorder_childrenreturn value in view. - Align response schema and fix docstrings/typos.
- Verify/fix
latest_change()and add auth. - Clean up lockfiles and run formatters/linters.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels