|
| 1 | +import "@typespec/http"; |
| 2 | +import "@typespec/openapi"; |
| 3 | + |
| 4 | +using Http; |
| 5 | + |
| 6 | +@tag("Forms") |
| 7 | +namespace CoreSystem.Forms { |
| 8 | + @doc("The request body for creating/updating a form.") |
| 9 | + model FormRequest { |
| 10 | + @doc("The title of the form.") |
| 11 | + title: string; |
| 12 | + |
| 13 | + @doc("The description of the form.") |
| 14 | + description: string; |
| 15 | + } |
| 16 | + |
| 17 | + @doc("The structure of a form.") |
| 18 | + model Form { |
| 19 | + @doc("The form's unique identifier.") |
| 20 | + id: uuid; |
| 21 | + |
| 22 | + @doc("The title of the form.") |
| 23 | + title: string; |
| 24 | + |
| 25 | + @doc("The description written in the form to show user info.") |
| 26 | + description: string; |
| 27 | + |
| 28 | + @doc("The user who last editted the form.") |
| 29 | + lastEdit: uuid; |
| 30 | + |
| 31 | + @doc("The creation timestamp of the form.") |
| 32 | + createdAt: utcDateTime; |
| 33 | + |
| 34 | + @doc("The last updated timestamp of the form") |
| 35 | + updatedAt: utcDateTime; |
| 36 | + } |
| 37 | + |
| 38 | + @doc("The current types of question") |
| 39 | + enum QuestionTypes { |
| 40 | + shortText: "short_text", |
| 41 | + longText: "long_text", |
| 42 | + singleChoice: "single_choice", |
| 43 | + multipleChoice: "multiple_choice", |
| 44 | + date: "date", |
| 45 | + } |
| 46 | + |
| 47 | + @doc("The structure of a question.") |
| 48 | + model Question { |
| 49 | + @doc("The question's unique identifier.") |
| 50 | + id: uuid; |
| 51 | + |
| 52 | + @doc("The form's id that the question belongs to. ") |
| 53 | + formId: uuid; |
| 54 | + |
| 55 | + @doc("Whether the question is required to answer or not.") |
| 56 | + required: boolean; |
| 57 | + |
| 58 | + @doc("The type of the question.") |
| 59 | + type: QuestionTypes; |
| 60 | + |
| 61 | + @doc("What is the question.") |
| 62 | + label: string; |
| 63 | + |
| 64 | + @doc("More details of this question.") |
| 65 | + description: string; |
| 66 | + |
| 67 | + @doc("What is the number of this question in the form.") |
| 68 | + order: int32; |
| 69 | + |
| 70 | + @doc("The creation timestamp of the question.") |
| 71 | + createdAt: utcDateTime; |
| 72 | + |
| 73 | + @doc("The updated timestamp of the question.") |
| 74 | + updatedAt: utcDateTime; |
| 75 | + } |
| 76 | + |
| 77 | + @doc("The request body for creating/updating a question.") |
| 78 | + model QuestionRequest { |
| 79 | + required: boolean; |
| 80 | + type: QuestionTypes; |
| 81 | + label: string; |
| 82 | + description: string; |
| 83 | + order: int32; |
| 84 | + } |
| 85 | + |
| 86 | + @doc("Create a new form.") |
| 87 | + @route("/forms") |
| 88 | + @post |
| 89 | + op createForm(@body createFormRequest: FormRequest): Form; |
| 90 | + |
| 91 | + @doc("Update an existing form by its unique identifier.") |
| 92 | + @route("/forms/{id}") |
| 93 | + @put |
| 94 | + op updateForm(@path id: uuid, @body updateFormRequest: FormRequest): Form; |
| 95 | + |
| 96 | + @doc("Delete an existing form by its unique identifier.") |
| 97 | + @route("/forms/{id}") |
| 98 | + @delete |
| 99 | + op deleteForm(@path id: uuid): { |
| 100 | + @statusCode statusCode: 204; |
| 101 | + }; |
| 102 | + |
| 103 | + @doc("Get a specific form by its unique identifier.") |
| 104 | + @route("/forms/{id}") |
| 105 | + @get |
| 106 | + op getFormById(@path id: uuid): Form; |
| 107 | + |
| 108 | + @doc("List all existing forms.") |
| 109 | + @route("/forms") |
| 110 | + @get |
| 111 | + op listForms(): Form[]; |
| 112 | + |
| 113 | + @doc("Create a new question for a specific form.") |
| 114 | + @route("/forms/{formId}/questions") |
| 115 | + @post |
| 116 | + op createQuestion(@path formId: uuid, @body q: QuestionRequest): Question; |
| 117 | + |
| 118 | + @doc("Update an existing question by its unique identifier.") |
| 119 | + @route("/forms/{formId}/questions/{questionId}") |
| 120 | + @put |
| 121 | + op updateQuestion( |
| 122 | + @path formId: uuid, |
| 123 | + @path questionId: uuid, |
| 124 | + @body q: QuestionRequest, |
| 125 | + ): Question; |
| 126 | + |
| 127 | + @doc("Delete an existing question by its unique identifier.") |
| 128 | + @route("/forms/{formId}/questions/{questionId}") |
| 129 | + @delete |
| 130 | + op deleteQuestion(@path formId: uuid, @path questionId: uuid): { |
| 131 | + @statusCode statusCode: 204; |
| 132 | + }; |
| 133 | + |
| 134 | + @doc("List all the questions of a specific form.") |
| 135 | + @route("/forms/{formId}/questions") |
| 136 | + @get |
| 137 | + op listQuestions(@path formId: uuid): Question[]; |
| 138 | +} |
0 commit comments