如何对会议注册表单自定义问题及答收场景进行技术建模?
Alright, let's break down how to technically model this custom question creation and answer collection feature for conference registration forms. I'll cover data modeling, backend APIs, frontend components, and core workflows to make sure all your requirements are addressed.
First off, let's nail down the database entities—this is the foundation of the whole system. These should be normalized to avoid redundancy while keeping relationships clear:
- Conference
- Fields:
id(primary key),name,start_date,end_date,creator_id, and other basic conference metadata
- Fields:
- RegistrationType
- Fields:
id(primary key),conference_id(foreign key to Conference),name(e.g., "Early Bird", "VIP"),price, etc.
- Fields:
- Question
- Fields:
id(primary key),text(the actual question, like "What's your phone number?"),type(optional—e.g., "text", "single-select" for future expansion),is_global(boolean: marks if it's a pre-built system question or a conference-specific custom one)
- Fields:
- ConferenceQuestionMapping
- Fields:
id(primary key),conference_id,registration_type_id,question_id,is_required(optional: lets creators mark questions as mandatory for a registration type)
- Fields:
- RegistrationAnswer
- Fields:
id(primary key),registration_id(foreign key to a Registration entity linking a user to a conference/type),question_id,answer_value(stores the user's response)
- Fields:
You'll need these endpoints to power frontend interactions and data persistence:
GET /conferences/{conferenceId}/questions- Returns: All global questions + custom questions tied to the conference, plus their current mappings to each registration type
- Use case: Load initial data when the creator opens the edit page
POST /conferences/{conferenceId}/questions- Request body:
{ "text": "What's your phone number?", "type": "text" } - Returns: The newly created custom question entity
- Use case: Handle the "Add custom questions" button click to create a conference-specific question
- Request body:
PUT /conferences/{conferenceId}/question-mappings- Request body:
[{ "registration_type_id": 2, "question_id": 5, "is_required": true }, ...] - Use case: Update associations between registration types and questions when the creator toggles checkboxes
- Request body:
POST /registrations/{registrationId}/answers- Request body:
[{ "question_id": 5, "answer_value": "+1234567890" }, ...] - Use case: Collect answers from users during registration
- Request body:
The edit page should be split into modular, maintainable components:
- ConferenceHeader: Displays basic conference info (name, dates) so the creator knows which event they're editing
- RegistrationQuestionMatrix: The core component for mapping questions to registration types
- Renders a table with rows as questions (global + custom) and columns as the conference's registration types
- Each cell has a checkbox (and optional "Required" toggle) to link the question to that type
- Syncs checkbox state with mapping data from the backend
- CustomQuestionCreator: A form triggered by the "Add custom questions" button
- Includes a text input for the question, a dropdown for question type (if supporting multiple formats), and a "Save" button
- On submission, calls the
POSTendpoint and dynamically adds the new question to the matrix
- SaveChangesButton: A top-level button that triggers the
PUTendpoint to save all mapping updates to the backend
Let's walk through the main user flows to ensure the model covers all scenarios:
Page Initialization
- When the creator navigates to the edit page, the frontend calls
GET /conferences/{id}/questions - The backend fetches the conference's registration types, relevant questions, and existing mappings
- The frontend renders the matrix with checkboxes pre-checked based on existing mappings
- When the creator navigates to the edit page, the frontend calls
Associating Existing Questions with Registration Types
- The creator toggles checkboxes; the frontend tracks changes locally (e.g., via React Context or Vuex)
- On clicking "Save Changes", the frontend sends updated mappings to the
PUTendpoint - The backend updates the
ConferenceQuestionMappingtable (creates new entries for checked boxes, deletes entries for unchecked ones)
Adding a Custom Question
- The creator clicks "Add custom questions" to open the form
- They enter the question text and submit
- The frontend calls the
POSTendpoint, which creates a newQuestionwithis_global = falselinked to the conference - The new question is automatically added to the matrix, ready to be mapped to registration types
Collecting Answers During Registration
- When a user registers, the frontend fetches questions mapped to their selected registration type
- The user fills out the form, and their answers are sent to the
POST /registrations/{id}/answersendpoint, which stores them in theRegistrationAnswertable
- Validation: Add backend checks to ensure custom question text isn't empty, and mappings don't duplicate entries for the same registration type + question pair
- Versioning: If you need to track form changes after registrations start, add a
versionfield toConferenceQuestionMappingso old answers stay linked to the correct question version - UI/UX: Add inline feedback (success messages for new questions, loading spinners during API calls) to improve the creator's experience
内容的提问来源于stack exchange,提问作者user9289573

