feat(poll): reorder options without invalidating answers

This commit is contained in:
2026-07-22 03:22:04 +02:00
parent 38ecff60a5
commit 8292c9d709
4 changed files with 151 additions and 2 deletions

View File

@@ -11,6 +11,7 @@ from govoplan_core.core.poll import (
PollCreateCommand,
PollInvitationCommand,
PollInvitationRef,
PollOptionOrderCommand,
PollOptionRequest,
PollOptionRef,
PollOptionUpdateCommand,
@@ -70,6 +71,7 @@ from govoplan_poll.backend.service import (
poll_result_summary_by_id,
response_datetime,
remove_poll_option,
reorder_poll_options,
revoke_poll_invitation_with_replay,
set_poll_workflow_context,
submit_poll_response,
@@ -82,7 +84,13 @@ def _poll_ref(poll: object) -> PollRef:
return PollRef(
id=poll.id,
status=poll.status,
options=tuple(PollOptionRef(id=option.id, position=option.position) for option in poll.options),
options=tuple(
PollOptionRef(id=option.id, position=option.position)
for option in sorted(
(option for option in poll.options if option.deleted_at is None),
key=lambda item: (item.position, item.id),
)
),
)
@@ -610,6 +618,31 @@ class SqlPollSchedulingProvider(PollSchedulingProvider):
raise PollCapabilityError(str(exc)) from exc
return PollOptionRef(id=option.id, position=option.position)
def reorder_options(
self,
session: object,
*,
tenant_id: str,
poll_id: str,
command: PollOptionOrderCommand,
) -> PollRef:
try:
mutation_owner = _stored_owner(
session,
tenant_id=tenant_id,
poll_id=poll_id,
)
poll = reorder_poll_options(
session,
tenant_id=tenant_id,
poll_id=poll_id,
option_ids=command.option_ids,
mutation_owner=mutation_owner,
)
except PollError as exc:
raise PollCapabilityError(str(exc)) from exc
return _poll_ref(poll)
def open_poll(self, session: object, *, tenant_id: str, poll_id: str) -> PollRef:
return self._transition(open_poll, session, tenant_id=tenant_id, poll_id=poll_id)