From e2d6284d7b06c0d6fb49c8fe689db91f987b9fce Mon Sep 17 00:00:00 2001 From: Alter Date: Wed, 31 Jan 2024 23:48:19 +0900 Subject: [PATCH 1/6] =?UTF-8?q?swagger=E3=81=AE=E5=B0=8E=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/README.md => README.md | 1 + Server.md | 3 + server/docs/openapi.yaml | 117 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+) rename ui/README.md => README.md (98%) create mode 100644 Server.md create mode 100644 server/docs/openapi.yaml diff --git a/ui/README.md b/README.md similarity index 98% rename from ui/README.md rename to README.md index 37e4327..79c1837 100644 --- a/ui/README.md +++ b/README.md @@ -2,6 +2,7 @@ traQ Database viewer traQでの発言履歴,発言数,スタンプ数など"話題性"につながる指標を抽出し、traQにおける発言の傾向および勢いを分析するためのデータを提供する。 収集されたデータを見やすい形でまとめ,利用しやすい形で提供することも目標とする。 +[サーバ](./Server.md) ## やりたいこと diff --git a/Server.md b/Server.md new file mode 100644 index 0000000..a2c82de --- /dev/null +++ b/Server.md @@ -0,0 +1,3 @@ +# Server + +あああ diff --git a/server/docs/openapi.yaml b/server/docs/openapi.yaml new file mode 100644 index 0000000..a11f98e --- /dev/null +++ b/server/docs/openapi.yaml @@ -0,0 +1,117 @@ +openapi: 3.0.3 +info: + title: traQer + description: Information about traQ usage + version: 0.0.5 +externalDocs: + description: 仕様書 + url: https://md.trap.jp/9uTJhTIRS-WbUzdtRM2-5Q +servers: + - url: https://yaranai.trap.show/api +tags: + - name: user + description: ユーザ紐付き情報 + +paths: + /ping: + get: + tags: + - user + summary: 疎通を確認 + description: 疎通を確認するためのものエンドポイント + operationId: ping + responses: + "200": + description: 成功 + content: + application/json: + schema: + $ref: "#/components/schemas/ping" + + + + +components: + schemas: + ping: + type: string + example: pong + taskWithoutId: + type: object + required: + - title + - description + - condition + - difficulty + - dueDate + properties: + title: + type: string + example: 単位認定の申請 + description: + type: string + example: スコアレポートを教務課に提出する + condition: + type: integer + example: 2 + description: タスクが出来る状況の状況ID(デフォルト=いつでもできるタスクは0) + difficulty: + type: integer + example: 2 + description: "1:気軽にできる, 2: 普通, 3: ハードルが高い" + dueDate: + type: string + format: date + example: 2021-01-01 + task: + type: object + required: + - id + - title + - description + - condition + - difficulty + - dueDate + properties: + id: + type: integer + example: 1 + title: + type: string + example: 単位認定の申請 + description: + type: string + example: スコアレポートを教務課に提出する + condition: + type: integer + example: 2 + description: タスクが出来る状況の状況ID(デフォルト=いつでもできるタスクは0) + difficulty: + type: integer + example: 2 + description: "1:気軽にできる, 2: 普通, 3: ハードルが高い" + dueDate: + type: string + format: date + example: 2021-01-01 + tasks: + type: array + items: + $ref: "#/components/schemas/task" + condition: + type: object + required: + - id + - name + properties: + id: + type: integer + example: 1 + name: + type: string + example: どこでもできる + conditions: + type: array + items: + $ref: "#/components/schemas/condition" + \ No newline at end of file From 88fa5ce5a2c9d455d7b262e489ddb2a0217a30c2 Mon Sep 17 00:00:00 2001 From: Alter Date: Thu, 1 Feb 2024 23:09:15 +0900 Subject: [PATCH 2/6] =?UTF-8?q?openapi=E4=BB=95=E6=A7=98=E6=9B=B8=E3=81=AE?= =?UTF-8?q?=E7=B7=A8=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/docs/openapi.yaml | 230 ++++++++++++++++++++++++++------------- 1 file changed, 156 insertions(+), 74 deletions(-) diff --git a/server/docs/openapi.yaml b/server/docs/openapi.yaml index a11f98e..6e2f6cf 100644 --- a/server/docs/openapi.yaml +++ b/server/docs/openapi.yaml @@ -2,24 +2,31 @@ openapi: 3.0.3 info: title: traQer description: Information about traQ usage - version: 0.0.5 + version: 0.1.0 externalDocs: - description: 仕様書 - url: https://md.trap.jp/9uTJhTIRS-WbUzdtRM2-5Q + description: github + url: https://github.com/alter334/traQer + servers: - - url: https://yaranai.trap.show/api + - url: https://traqer.trap.show/ tags: + - name: ping + description: pong - name: user description: ユーザ紐付き情報 + - name: channel + description: チャンネル紐付き情報 + - name: stamp + description: スタンプ紐付き情報(次ver以降で実装) + - name: me + description: 自己情報(次ver以降で実装) paths: /ping: get: tags: - - user + - ping summary: 疎通を確認 - description: 疎通を確認するためのものエンドポイント - operationId: ping responses: "200": description: 成功 @@ -27,6 +34,74 @@ paths: application/json: schema: $ref: "#/components/schemas/ping" + /user: + get: + tags: + - user + summary: 全ユーザメッセージ数取得 + responses: + "200": + description: 成功 + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/userData" + /user/{userid}: + get: + tags: + - user + summary: ユーザ毎メッセージ数取得 + responses: + "200": + description: 成功 + content: + application/json: + schema: + type: object + $ref: "#/components/schemas/userData" + /user/group/{groupid}: + get: + tags: + - user + summary: グループ毎メッセージ数取得 + responses: + "200": + description: 成功 + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/userData" + /channel: + get: + tags: + - channel + summary: 全ユーザメッセージ数取得 + responses: + "200": + description: 成功 + content: + application/json: + schema: + type: array + items: + $ref: "#/components/schemas/userData" + /channel/{channelid}: + get: + tags: + - channel + summary: ユーザ毎メッセージ数取得 + responses: + "200": + description: 成功 + content: + application/json: + schema: + type: object + $ref: "#/components/schemas/userData" @@ -36,82 +111,89 @@ components: ping: type: string example: pong - taskWithoutId: + userData: type: object - required: - - title - - description - - condition - - difficulty - - dueDate properties: - title: + userId: type: string - example: 単位認定の申請 - description: + description: ユーザUUID + userName: type: string - example: スコアレポートを教務課に提出する - condition: - type: integer - example: 2 - description: タスクが出来る状況の状況ID(デフォルト=いつでもできるタスクは0) - difficulty: - type: integer - example: 2 - description: "1:気軽にできる, 2: 普通, 3: ハードルが高い" - dueDate: - type: string - format: date - example: 2021-01-01 - task: - type: object - required: - - id - - title - - description - - condition - - difficulty - - dueDate - properties: - id: - type: integer - example: 1 - title: + description: ユーザtraQID + displayName: type: string - example: 単位認定の申請 - description: + description: ユーザ表示名 + homeChannelId: type: string - example: スコアレポートを教務課に提出する - condition: + description: ホームチャンネルUUID + totalPostCount: type: integer - example: 2 - description: タスクが出来る状況の状況ID(デフォルト=いつでもできるタスクは0) - difficulty: + description: 総投稿数 + dailyPostCount: type: integer - example: 2 - description: "1:気軽にできる, 2: 普通, 3: ハードルが高い" - dueDate: - type: string - format: date - example: 2021-01-01 - tasks: - type: array - items: - $ref: "#/components/schemas/task" - condition: + description: 日投稿数 + + channelData: type: object - required: - - id - - name properties: - id: - type: integer - example: 1 - name: + userId: type: string - example: どこでもできる - conditions: - type: array - items: - $ref: "#/components/schemas/condition" + description: チャンネルUUID + totalPostCount: + type: integer + description: 総投稿数 + dailyPostCount: + type: integer + description: 日投稿数 + # task: + # type: object + # required: + # - id + # - title + # - description + # - condition + # - difficulty + # - dueDate + # properties: + # id: + # type: integer + # example: 1 + # title: + # type: string + # example: 単位認定の申請 + # description: + # type: string + # example: スコアレポートを教務課に提出する + # condition: + # type: integer + # example: 2 + # description: タスクが出来る状況の状況ID(デフォルト=いつでもできるタスクは0) + # difficulty: + # type: integer + # example: 2 + # description: "1:気軽にできる, 2: 普通, 3: ハードルが高い" + # dueDate: + # type: string + # format: date + # example: 2021-01-01 + # tasks: + # type: array + # items: + # $ref: "#/components/schemas/task" + # condition: + # type: object + # required: + # - id + # - name + # properties: + # id: + # type: integer + # example: 1 + # name: + # type: string + # example: どこでもできる + # conditions: + # type: array + # items: + # $ref: "#/components/schemas/condition" \ No newline at end of file From 0df4886ec5eeeaccf1ee417da5e11f67bc57c85b Mon Sep 17 00:00:00 2001 From: Alter Date: Fri, 2 Feb 2024 23:57:31 +0900 Subject: [PATCH 3/6] =?UTF-8?q?modelmd=E3=81=AE=E9=80=B2=E6=8D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/model.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 server/model.md diff --git a/server/model.md b/server/model.md new file mode 100644 index 0000000..69e17c5 --- /dev/null +++ b/server/model.md @@ -0,0 +1,37 @@ +# サーバ設計関連資料 + +## パッケージ +- [readme](../README.md)参照 + +## struct関連 +- メソッドは略 + +### Server +``` +type struct Server{ + bot *Bot // Bot関連 + db *DB // db関連 + service *Service // 具体的機能 + traQapi *traQapi // traqApi関連 + serverData ServerData // 保持しておくデータ +} +``` + +### ServerData +``` +type struct ServerData{ + lastTrackId traq.Message // 最後に取得したメッセージ + // 増えたらここに書く +} +``` + +### Bot +type struct Bot{ + bot *traqwsbot.Bot // traqBot +} + +### traQapi +type struct traQapi{ + auth context.Context // 認証関連 + client *traq.APIClient // traqAPIClient +} From 616dd10252968962d969cc48e51d7dc076f23918 Mon Sep 17 00:00:00 2001 From: Alter Date: Fri, 2 Feb 2024 23:57:55 +0900 Subject: [PATCH 4/6] =?UTF-8?q?=E3=82=B5=E3=83=BC=E3=83=90=E9=96=A2?= =?UTF-8?q?=E9=80=A3=E6=83=85=E5=A0=B1=E3=81=AE=E8=BF=BD=E8=A8=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/README.md b/README.md index 79c1837..ede2765 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,41 @@ traQでの発言履歴,発言数,スタンプ数など"話題性"につながる 収集されたデータを見やすい形でまとめ,利用しやすい形で提供することも目標とする。 [サーバ](./Server.md) +## Server パッケージ構成の見直し + +## mainパッケージ(もしくはsetup) +- 実行系のスクリプト + - main.go + - cron.go(定時実行関連) + - root.go(ルーティング関連) + - record.go(アプリ内情報保持関連) + +## serviceパッケージ +- サービスそのものを書くイメージ 情報の整理,整形は基本このパッケージ + - User.go(ユーザーごと情報取得,整理) + - Channel.go + - Stamp.go + +## botパッケージ +- traQBOT関連のパッケージ + - bot.go(セットアップ関連) + - command.go(コマンド対応系) + +## dbパッケージ +- db関連パッケージ + - テーブル毎に処理を書く + - e.g.)messagecount.go + - dbセットアップもここ + +## traQAPIパッケージ +- traQAPIを叩くパッケージ + - どこまでを含めるかは要検討 + - メッセージならその取得まではこのパッケージでやりたい(serviceパッケージではこちらで定義したmodelですべて対応したい) + - ID<->displayname変換などの処理もここ + - BOTのメッセージ投稿も実際にはここにAPIを実装する(botパッケージではBotSimplePostのようなものを叩かせる) + +## 今後具体的なクラス相当の設計を考える + ## やりたいこと ### traQ発言数量データの収集>>traQAPIの利用 フロント実装だけでいけると思う From 8b74dde200da2f7a393f26086c4dfc7fe9b336e4 Mon Sep 17 00:00:00 2001 From: Alter Date: Sat, 3 Feb 2024 18:57:12 +0900 Subject: [PATCH 5/6] =?UTF-8?q?=E5=90=84=E7=A8=AE=E3=83=8F=E3=83=B3?= =?UTF-8?q?=E3=83=89=E3=83=A9=E3=81=AE=E5=AE=9F=E8=A3=85(bot)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/handler/bot/handler.go | 7 +++++++ server/handler/bot/model.go | 7 +++++++ server/model.md | 22 ++++++++++++++++++---- 3 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 server/handler/bot/handler.go create mode 100644 server/handler/bot/model.go diff --git a/server/handler/bot/handler.go b/server/handler/bot/handler.go new file mode 100644 index 0000000..f57594c --- /dev/null +++ b/server/handler/bot/handler.go @@ -0,0 +1,7 @@ +package bot + +import traqwsbot "github.com/traPtitech/traq-ws-bot" + +func NewBotHandler(bot *traqwsbot.Bot) *Bot { + return &Bot{bot: bot} +} diff --git a/server/handler/bot/model.go b/server/handler/bot/model.go new file mode 100644 index 0000000..3536118 --- /dev/null +++ b/server/handler/bot/model.go @@ -0,0 +1,7 @@ +package bot + +import traqwsbot "github.com/traPtitech/traq-ws-bot" + +type Bot struct { + bot *traqwsbot.Bot +} diff --git a/server/model.md b/server/model.md index 69e17c5..973dae9 100644 --- a/server/model.md +++ b/server/model.md @@ -5,10 +5,11 @@ ## struct関連 - メソッドは略 +- 各パッケージにhandler.goを用意しそこにインスタンス化を定義 model.goも用意 ### Server ``` -type struct Server{ +type Server struct{ bot *Bot // Bot関連 db *DB // db関連 service *Service // 具体的機能 @@ -19,19 +20,32 @@ type struct Server{ ### ServerData ``` -type struct ServerData{ +type ServerData struct { lastTrackId traq.Message // 最後に取得したメッセージ + lastTrackTime time.Time // 最後の取得日時 // 増えたらここに書く } ``` ### Bot -type struct Bot{ +``` +type Bot struct { bot *traqwsbot.Bot // traqBot } +``` + +### DB +``` +type DB struct{ + db *sqlx.DB // sqlx.db +} +``` ### traQapi -type struct traQapi{ +``` +type traQapi struct { auth context.Context // 認証関連 client *traq.APIClient // traqAPIClient } +``` + From c1a0f818b5cc7570c84c9da84dfa486984b66908 Mon Sep 17 00:00:00 2001 From: Alter Date: Sat, 3 Feb 2024 19:16:48 +0900 Subject: [PATCH 6/6] =?UTF-8?q?=E3=83=87=E3=82=A3=E3=83=AC=E3=82=AF?= =?UTF-8?q?=E3=83=88=E3=83=AA=E3=81=AE=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/handler/db/handler.go | 7 +++++++ server/handler/db/model.go | 7 +++++++ server/handler/service/handler.go | 7 +++++++ server/handler/service/model.go | 7 +++++++ server/handler/traqapi/handler.go | 7 +++++++ server/handler/traqapi/model.go | 7 +++++++ server/setup/setup.go | 1 + 7 files changed, 43 insertions(+) create mode 100644 server/handler/db/handler.go create mode 100644 server/handler/db/model.go create mode 100644 server/handler/service/handler.go create mode 100644 server/handler/service/model.go create mode 100644 server/handler/traqapi/handler.go create mode 100644 server/handler/traqapi/model.go create mode 100644 server/setup/setup.go diff --git a/server/handler/db/handler.go b/server/handler/db/handler.go new file mode 100644 index 0000000..82baf01 --- /dev/null +++ b/server/handler/db/handler.go @@ -0,0 +1,7 @@ +package db + +import traqwsbot "github.com/traPtitech/traq-ws-bot" + +func NewBotHandler(bot *traqwsbot.Bot) *Bot { + return &Bot{bot: bot} +} diff --git a/server/handler/db/model.go b/server/handler/db/model.go new file mode 100644 index 0000000..44eb570 --- /dev/null +++ b/server/handler/db/model.go @@ -0,0 +1,7 @@ +package db + +import traqwsbot "github.com/traPtitech/traq-ws-bot" + +type Bot struct { + bot *traqwsbot.Bot +} diff --git a/server/handler/service/handler.go b/server/handler/service/handler.go new file mode 100644 index 0000000..3ff18f5 --- /dev/null +++ b/server/handler/service/handler.go @@ -0,0 +1,7 @@ +package service + +import traqwsbot "github.com/traPtitech/traq-ws-bot" + +func NewBotHandler(bot *traqwsbot.Bot) *Bot { + return &Bot{bot: bot} +} diff --git a/server/handler/service/model.go b/server/handler/service/model.go new file mode 100644 index 0000000..e091271 --- /dev/null +++ b/server/handler/service/model.go @@ -0,0 +1,7 @@ +package service + +import traqwsbot "github.com/traPtitech/traq-ws-bot" + +type Bot struct { + bot *traqwsbot.Bot +} diff --git a/server/handler/traqapi/handler.go b/server/handler/traqapi/handler.go new file mode 100644 index 0000000..ea98180 --- /dev/null +++ b/server/handler/traqapi/handler.go @@ -0,0 +1,7 @@ +package traqapi + +import traqwsbot "github.com/traPtitech/traq-ws-bot" + +func NewBotHandler(bot *traqwsbot.Bot) *Bot { + return &Bot{bot: bot} +} diff --git a/server/handler/traqapi/model.go b/server/handler/traqapi/model.go new file mode 100644 index 0000000..3d36efd --- /dev/null +++ b/server/handler/traqapi/model.go @@ -0,0 +1,7 @@ +package traqapi + +import traqwsbot "github.com/traPtitech/traq-ws-bot" + +type Bot struct { + bot *traqwsbot.Bot +} diff --git a/server/setup/setup.go b/server/setup/setup.go new file mode 100644 index 0000000..9bca696 --- /dev/null +++ b/server/setup/setup.go @@ -0,0 +1 @@ +package setup