diff --git a/docs/v3-api.yaml b/docs/v3-api.yaml index d900e254f..059619cd8 100644 --- a/docs/v3-api.yaml +++ b/docs/v3-api.yaml @@ -6098,6 +6098,10 @@ components: uniqueItems: false items: type: string + bio: + type: string + description: 自己紹介(biography) + maxLength: 1000 BotTokens: title: BotTokens type: object @@ -6179,6 +6183,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 { diff --git a/router/v3/bots_test.go b/router/v3/bots_test.go index 6e434a517..693e7c958 100644 --- a/router/v3/bots_test.go +++ b/router/v3/bots_test.go @@ -531,6 +531,7 @@ func TestHandlers_EditBot(t *testing.T) { SubscribeEvents: map[model.BotEventType]struct{}{ event.Ping: {}, }, + Bio: optional.From("Bio"), }). Expect(). Status(http.StatusNoContent)