feat(scheduling): harden poll-backed request flows
This commit is contained in:
@@ -5,13 +5,12 @@ from typing import Any, Literal
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field, model_validator
|
||||
|
||||
from govoplan_poll.backend.schemas import PollResultSummaryResponse
|
||||
|
||||
|
||||
SchedulingStatus = Literal["draft", "collecting", "closed", "decided", "handed_off", "cancelled", "archived"]
|
||||
SchedulingParticipantType = Literal["internal", "external", "resource"]
|
||||
SchedulingParticipantStatus = Literal["draft", "invited", "responded", "declined", "removed"]
|
||||
SchedulingResultVisibility = Literal["organizer", "after_response", "after_close", "public"]
|
||||
SchedulingAvailabilityValue = Literal["available", "maybe", "unavailable"]
|
||||
|
||||
|
||||
class SchedulingCalendarPreferences(BaseModel):
|
||||
@@ -164,9 +163,48 @@ class SchedulingDecisionRequest(BaseModel):
|
||||
handoff_to_calendar: bool | None = None
|
||||
|
||||
|
||||
class SchedulingAvailabilityAnswerInput(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
|
||||
slot_id: str
|
||||
value: SchedulingAvailabilityValue
|
||||
|
||||
|
||||
class SchedulingAvailabilityResponseRequest(BaseModel):
|
||||
model_config = ConfigDict(extra="forbid")
|
||||
|
||||
answers: list[SchedulingAvailabilityAnswerInput] = Field(min_length=1)
|
||||
|
||||
@model_validator(mode="after")
|
||||
def validate_unique_slots(self) -> "SchedulingAvailabilityResponseRequest":
|
||||
slot_ids = [answer.slot_id for answer in self.answers]
|
||||
if len(slot_ids) != len(set(slot_ids)):
|
||||
raise ValueError("Each scheduling slot can be answered only once")
|
||||
return self
|
||||
|
||||
|
||||
class SchedulingPollOptionResultResponse(BaseModel):
|
||||
option_id: str
|
||||
option_key: str
|
||||
label: str
|
||||
count: int = 0
|
||||
score: int = 0
|
||||
values: dict[str, int] = Field(default_factory=dict)
|
||||
ranks: dict[int, int] = Field(default_factory=dict)
|
||||
|
||||
|
||||
class SchedulingPollSummaryResponse(BaseModel):
|
||||
poll_id: str
|
||||
kind: str
|
||||
status: str
|
||||
response_count: int
|
||||
option_results: list[SchedulingPollOptionResultResponse] = Field(default_factory=list)
|
||||
leading_option_ids: list[str] = Field(default_factory=list)
|
||||
|
||||
|
||||
class SchedulingSummaryResponse(BaseModel):
|
||||
request: SchedulingRequestResponse
|
||||
poll_summary: PollResultSummaryResponse
|
||||
poll_summary: SchedulingPollSummaryResponse
|
||||
|
||||
|
||||
class SchedulingCalendarActionResponse(BaseModel):
|
||||
|
||||
Reference in New Issue
Block a user