diff --git a/src/endpoints/messages.tsp b/src/endpoints/messages.tsp new file mode 100644 index 0000000..ee22b98 --- /dev/null +++ b/src/endpoints/messages.tsp @@ -0,0 +1,63 @@ +import "@typespec/http"; +import "@typespec/rest"; +import "../models/errors.tsp"; +import "../models/user.tsp"; +import "../models/message.tsp"; + +using TypeSpec.Http; +using TypeSpec.Rest; + +namespace SeichiPortalApiSchema; + +@tag("Messages") +@route("/messages") +namespace Messages { + @post + @summary("メッセージの新規作成") + op create( + @header + contentType: "application/json", + + @body body: { + related_answer_id: uint32; + body: string; + }, + ): { + @statusCode statusCode: 201; + @body body: { + id: uint32; + }; + } | { + @statusCode statusCode: 400 | 401 | 403 | 500; + @body body: Error; + }; + + @get + @route("/{related_answer_id}") + @summary("メッセージの一覧取得") + op list( + @path + related_answer_id: uint32, + ): { + @statusCode statusCode: 200; + @body body: { + messages: Message[]; + }; + } | { + @statusCode statusCode: 400 | 401 | 403 | 500; + @body body: Error; + }; + + @delete + @route("/{message_id}") + @summary("メッセージの削除") + op delete( + @path + message_id: uint32, + ): { + @statusCode statusCode: 204; + } | { + @statusCode statusCode: 400 | 401 | 403 | 500; + @body body: Error; + }; +} diff --git a/src/main.tsp b/src/main.tsp index 84533fb..a1b15ce 100644 --- a/src/main.tsp +++ b/src/main.tsp @@ -1,4 +1,5 @@ import "./endpoints/forms.tsp"; +import "./endpoints/messages.tsp"; import "./endpoints/users.tsp"; import "./endpoints/session.tsp"; import "@typespec/openapi"; diff --git a/src/models/errors.tsp b/src/models/errors.tsp index ce46954..137a936 100644 --- a/src/models/errors.tsp +++ b/src/models/errors.tsp @@ -1,6 +1,7 @@ enum ErrorCode { FORM_NOT_FOUND, ANSWER_NOT_FOUND, + MESSAGE_NOT_FOUND, OUT_OF_PERIOD, DO_NOT_HAVE_PERMISSION_TO_POST_FORM_COMMENT, DO_NOT_HAVE_PERMISSION_TO_GET_ANSWERS, diff --git a/src/models/message.tsp b/src/models/message.tsp new file mode 100644 index 0000000..590badb --- /dev/null +++ b/src/models/message.tsp @@ -0,0 +1,7 @@ +import "../endpoints/users.tsp"; + +model Message { + body: string; + sender: User; + timestamp: utcDateTime; +}