Skip to content

Commit

Permalink
Merge pull request #171 from GiganticMinecraft/feat/message-api
Browse files Browse the repository at this point in the history
feat: メッセージ操作用 API 定義の実装
  • Loading branch information
rito528 authored Oct 26, 2024
2 parents 21c9562 + f3efde1 commit 27fc926
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/endpoints/messages.tsp
Original file line number Diff line number Diff line change
@@ -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;
};
}
1 change: 1 addition & 0 deletions src/main.tsp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "./endpoints/forms.tsp";
import "./endpoints/messages.tsp";
import "./endpoints/users.tsp";
import "./endpoints/session.tsp";
import "@typespec/openapi";
Expand Down
1 change: 1 addition & 0 deletions src/models/errors.tsp
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
7 changes: 7 additions & 0 deletions src/models/message.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import "../endpoints/users.tsp";

model Message {
body: string;
sender: User;
timestamp: utcDateTime;
}

0 comments on commit 27fc926

Please sign in to comment.