responses.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. from datetime import datetime
  2. from enum import Enum
  3. from pydantic import UUID4, BaseModel, ConfigDict, EmailStr
  4. class BaseResponse(BaseModel):
  5. model_config = ConfigDict(from_attributes=True)
  6. class BaseObjectResponse(BaseResponse):
  7. id: UUID4
  8. created_at: datetime
  9. updated_at: datetime
  10. class AccessTokenResponse(BaseResponse):
  11. token_type: str
  12. access_token: str
  13. expires_at: int
  14. issued_at: int
  15. refresh_token: str
  16. refresh_token_expires_at: int
  17. refresh_token_issued_at: int
  18. # ---- Organization ----
  19. class OrganizationResponse(BaseResponse):
  20. id: str
  21. name: str
  22. class MembershipUserResponse(BaseResponse):
  23. id: str
  24. email: EmailStr
  25. name: str
  26. class OrganizationMembershipResponse(BaseResponse):
  27. user_id: str
  28. organization_id: str
  29. role: str
  30. user: MembershipUserResponse
  31. class OrganizationDetailResponse(OrganizationResponse):
  32. name: str
  33. memberships: list[OrganizationMembershipResponse] = []
  34. class UserOrganizationResponse(BaseResponse):
  35. organization_id: str
  36. organization: OrganizationResponse
  37. role: str
  38. class UserResponse(BaseResponse):
  39. id: str
  40. email: EmailStr
  41. name: str
  42. phone_number: str | None = None
  43. global_role: str
  44. organizations: list[UserOrganizationResponse] = []
  45. class CommissionContactResponse(BaseResponse):
  46. name: str
  47. phone_number: str | None = None
  48. class CommissionResponse(BaseObjectResponse):
  49. name: str
  50. contacts: list[CommissionContactResponse] = []
  51. templates_id: list[UUID4] = []
  52. class VolunteerGroupResponse(BaseObjectResponse):
  53. name: str
  54. color: str | None = None
  55. volunteers_id: list[UUID4] = []
  56. class VolunteerResponse(BaseObjectResponse):
  57. name: str
  58. surname: str
  59. email: str
  60. phone_number: str
  61. automatic_sms: bool
  62. slots_id: list[UUID4] = []
  63. groups_id: list[str] = []
  64. comment: str
  65. class SlotResponse(BaseObjectResponse):
  66. title: str
  67. starting_time: datetime
  68. ending_time: datetime
  69. required_volunteers: int
  70. volunteers_id: list[str] = []
  71. template_id: UUID4 | None
  72. class SMSResponse(BaseObjectResponse):
  73. volunteer_id: UUID4 | None
  74. content: str
  75. phone_number: str
  76. sending_time: datetime
  77. send_time: datetime | None
  78. class TemplateResponse(BaseObjectResponse):
  79. title: str
  80. description: str
  81. place: str
  82. responsible_override: str | None = None
  83. commission_id: str | None = None
  84. tags_id: list[UUID4] = []
  85. comment: str
  86. class TagResponse(BaseObjectResponse):
  87. title: str
  88. templates_id: list[str] = []
  89. class ProjectResponse(BaseObjectResponse):
  90. name: str
  91. organization_id: str
  92. volunteers: list[VolunteerResponse]
  93. sms: list[SMSResponse]
  94. slots: list[SlotResponse]
  95. tags: list[TagResponse]
  96. templates: list[TemplateResponse]
  97. groups: list[VolunteerGroupResponse] = []
  98. is_public: bool
  99. class ProjectListResponse(BaseResponse):
  100. id: UUID4
  101. created_at: datetime
  102. updated_at: datetime
  103. name: str
  104. organization_id: str
  105. is_public: bool
  106. class EnumServerStatus(Enum):
  107. ACTIVE = "active"
  108. INVALID = "invalid (heartbeat missing)"
  109. INACTIVE = "inactive (stale)"
  110. class SMSServerStatus(BaseResponse):
  111. updated_at: datetime
  112. host: str
  113. user_agent: str
  114. message: EnumServerStatus