From f3efde100ddc87c3459e4ec37863a7273b733a01 Mon Sep 17 00:00:00 2001 From: rito528 <39003544+rito528@users.noreply.github.com> Date: Sat, 26 Oct 2024 16:43:42 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E3=83=A1=E3=83=83=E3=82=BB=E3=83=BC?= =?UTF-8?q?=E3=82=B8=E6=93=8D=E4=BD=9C=E7=94=A8=20API=20=E5=AE=9A=E7=BE=A9?= =?UTF-8?q?=E3=81=AE=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/endpoints/messages.tsp | 63 ++++++++++++++++++++++++++++++++++++++ src/main.tsp | 1 + src/models/errors.tsp | 1 + src/models/message.tsp | 7 +++++ 4 files changed, 72 insertions(+) create mode 100644 src/endpoints/messages.tsp create mode 100644 src/models/message.tsp 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; +}