From 6f6d4b5c97345cbeb6339b4fd4584c6cedfed126 Mon Sep 17 00:00:00 2001 From: UnABC Date: Fri, 12 Jul 2024 10:22:13 +0900 Subject: [PATCH 1/4] =?UTF-8?q?Bot=E3=81=AEPACH=E3=81=ABbio=E3=83=95?= =?UTF-8?q?=E3=82=A3=E3=83=BC=E3=83=AB=E3=83=89=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/v3-api.yaml | 5 +++++ repository/bot.go | 1 + repository/gorm/bot.go | 12 ++++++++++++ router/v3/bots.go | 3 +++ 4 files changed, 21 insertions(+) diff --git a/docs/v3-api.yaml b/docs/v3-api.yaml index 3462beac6..fb81e509d 100644 --- a/docs/v3-api.yaml +++ b/docs/v3-api.yaml @@ -6130,6 +6130,10 @@ components: items: type: string format: uuid + bio: + type: string + description: 自己紹介(biography) + maxLength: 1000 required: - id - updatedAt @@ -6144,6 +6148,7 @@ components: - endpoint - privileged - channels + - bio BotEventLog: title: BotEventLog type: object diff --git a/repository/bot.go b/repository/bot.go index b58adf5a3..7a0fcad0a 100644 --- a/repository/bot.go +++ b/repository/bot.go @@ -19,6 +19,7 @@ type UpdateBotArgs struct { Privileged optional.Of[bool] CreatorID optional.Of[uuid.UUID] SubscribeEvents model.BotEventTypes + Bio optional.Of[string] } // BotsQuery Bot情報取得用クエリ diff --git a/repository/gorm/bot.go b/repository/gorm/bot.go index 9c2e528ec..2382e0023 100644 --- a/repository/gorm/bot.go +++ b/repository/gorm/bot.go @@ -93,6 +93,7 @@ func (repo *Repository) UpdateBot(id uuid.UUID, args repository.UpdateBotArgs) e return repository.ErrNilID } var ( + u model.User b model.Bot updated bool userUpdated bool @@ -137,6 +138,17 @@ func (repo *Repository) UpdateBot(id uuid.UUID, args repository.UpdateBotArgs) e } userUpdated = true } + + if args.Bio.Valid { + if err := tx.Preload("Profile").First(&u, model.User{ID: b.BotUserID}).Error; err != nil { + return convertError(err) + } + + if err := tx.Model(u.Profile).Update("bio", args.Bio.V).Error; err != nil { + return err + } + userUpdated = true + } return nil }) if err != nil { diff --git a/router/v3/bots.go b/router/v3/bots.go index 970e38b39..74103ff7e 100644 --- a/router/v3/bots.go +++ b/router/v3/bots.go @@ -144,6 +144,7 @@ type PatchBotRequest struct { Privileged optional.Of[bool] `json:"privileged"` DeveloperID optional.Of[uuid.UUID] `json:"developerId"` SubscribeEvents model.BotEventTypes `json:"subscribeEvents"` + Bio optional.Of[string] `json:"bio"` } func (r PatchBotRequest) ValidateWithContext(ctx context.Context) error { @@ -154,6 +155,7 @@ func (r PatchBotRequest) ValidateWithContext(ctx context.Context) error { vd.Field(&r.Endpoint, is.URL, validator.NotInternalURL), vd.Field(&r.DeveloperID, validator.NotNilUUID, utils.IsActiveHumanUserID), vd.Field(&r.SubscribeEvents, utils.IsValidBotEvents), + vd.Field(&r.Bio, vd.RuneLength(0, 1000)), ) } @@ -184,6 +186,7 @@ func (h *Handlers) EditBot(c echo.Context) error { Privileged: req.Privileged, CreatorID: req.DeveloperID, SubscribeEvents: req.SubscribeEvents, + Bio: req.Bio, } if err := h.Repo.UpdateBot(b.ID, args); err != nil { From 4e85cb1132065b96640e606d95bf71c8a075f5e5 Mon Sep 17 00:00:00 2001 From: UnABC Date: Wed, 17 Jul 2024 00:33:34 +0900 Subject: [PATCH 2/4] =?UTF-8?q?component=E3=81=AE=E6=9B=B8=E3=81=8D?= =?UTF-8?q?=E6=8F=9B=E3=81=88=E3=81=8C=E9=96=93=E9=81=95=E3=81=A3=E3=81=A6?= =?UTF-8?q?=E3=81=84=E3=81=9F=E3=81=AE=E3=81=A7=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/v3-api.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/v3-api.yaml b/docs/v3-api.yaml index fb81e509d..3614ac269 100644 --- a/docs/v3-api.yaml +++ b/docs/v3-api.yaml @@ -6063,6 +6063,10 @@ components: uniqueItems: false items: type: string + bio: + type: string + description: 自己紹介(biography) + maxLength: 1000 BotTokens: title: BotTokens type: object @@ -6130,10 +6134,6 @@ components: items: type: string format: uuid - bio: - type: string - description: 自己紹介(biography) - maxLength: 1000 required: - id - updatedAt From d9afa9f614ff7c0a3b847855e3077c12488c9e61 Mon Sep 17 00:00:00 2001 From: UnABC Date: Wed, 17 Jul 2024 01:08:20 +0900 Subject: [PATCH 3/4] =?UTF-8?q?bots=5Ftest.go=E3=81=AE=E3=81=9D=E3=82=8C?= =?UTF-8?q?=E3=81=A3=E3=81=BD=E3=81=84=E3=81=A8=E3=81=93=E3=82=8D=E3=81=AB?= =?UTF-8?q?Bio=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- router/v3/bots_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/router/v3/bots_test.go b/router/v3/bots_test.go index 6e434a517..e798fac3e 100644 --- a/router/v3/bots_test.go +++ b/router/v3/bots_test.go @@ -237,6 +237,7 @@ func TestHandlers_CreateBot(t *testing.T) { obj.Value("endpoint").String().IsEqual("https://example.com") obj.Value("privileged").Boolean().IsFalse() obj.Value("channels").Array().Length().IsEqual(0) + obj.Value("bio").String().IsEmpty() }) t.Run("success with WebSocket mode", func(t *testing.T) { @@ -531,6 +532,7 @@ func TestHandlers_EditBot(t *testing.T) { SubscribeEvents: map[model.BotEventType]struct{}{ event.Ping: {}, }, + Bio: optional.From("Bio"), }). Expect(). Status(http.StatusNoContent) From 36c8db138e275c6d57ca2fed36801878354ea9df Mon Sep 17 00:00:00 2001 From: UnABC Date: Wed, 17 Jul 2024 09:30:30 +0900 Subject: [PATCH 4/4] =?UTF-8?q?bots=5Ftest.go=E3=81=A7=E3=81=AE=E3=82=A8?= =?UTF-8?q?=E3=83=A9=E3=83=BC=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- router/v3/bots_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/router/v3/bots_test.go b/router/v3/bots_test.go index e798fac3e..693e7c958 100644 --- a/router/v3/bots_test.go +++ b/router/v3/bots_test.go @@ -237,7 +237,6 @@ func TestHandlers_CreateBot(t *testing.T) { obj.Value("endpoint").String().IsEqual("https://example.com") obj.Value("privileged").Boolean().IsFalse() obj.Value("channels").Array().Length().IsEqual(0) - obj.Value("bio").String().IsEmpty() }) t.Run("success with WebSocket mode", func(t *testing.T) {