Skip to content

Commit

Permalink
Merge pull request #2483 from traPtitech/issue2035
Browse files Browse the repository at this point in the history
BotのPACHにbioフィールドを追加
  • Loading branch information
pikachu0310 committed Jul 23, 2024
2 parents 4884284 + 36c8db1 commit 9918b0c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/v3-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6098,6 +6098,10 @@ components:
uniqueItems: false
items:
type: string
bio:
type: string
description: 自己紹介(biography)
maxLength: 1000
BotTokens:
title: BotTokens
type: object
Expand Down Expand Up @@ -6179,6 +6183,7 @@ components:
- endpoint
- privileged
- channels
- bio
BotEventLog:
title: BotEventLog
type: object
Expand Down
1 change: 1 addition & 0 deletions repository/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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情報取得用クエリ
Expand Down
12 changes: 12 additions & 0 deletions repository/gorm/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions router/v3/bots.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)),
)
}

Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions router/v3/bots_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9918b0c

Please sign in to comment.