Skip to content

Commit 9918b0c

Browse files
authored
Merge pull request #2483 from traPtitech/issue2035
BotのPACHにbioフィールドを追加
2 parents 4884284 + 36c8db1 commit 9918b0c

File tree

5 files changed

+22
-0
lines changed

5 files changed

+22
-0
lines changed

docs/v3-api.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6098,6 +6098,10 @@ components:
60986098
uniqueItems: false
60996099
items:
61006100
type: string
6101+
bio:
6102+
type: string
6103+
description: 自己紹介(biography)
6104+
maxLength: 1000
61016105
BotTokens:
61026106
title: BotTokens
61036107
type: object
@@ -6179,6 +6183,7 @@ components:
61796183
- endpoint
61806184
- privileged
61816185
- channels
6186+
- bio
61826187
BotEventLog:
61836188
title: BotEventLog
61846189
type: object

repository/bot.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type UpdateBotArgs struct {
1919
Privileged optional.Of[bool]
2020
CreatorID optional.Of[uuid.UUID]
2121
SubscribeEvents model.BotEventTypes
22+
Bio optional.Of[string]
2223
}
2324

2425
// BotsQuery Bot情報取得用クエリ

repository/gorm/bot.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ func (repo *Repository) UpdateBot(id uuid.UUID, args repository.UpdateBotArgs) e
9393
return repository.ErrNilID
9494
}
9595
var (
96+
u model.User
9697
b model.Bot
9798
updated bool
9899
userUpdated bool
@@ -137,6 +138,17 @@ func (repo *Repository) UpdateBot(id uuid.UUID, args repository.UpdateBotArgs) e
137138
}
138139
userUpdated = true
139140
}
141+
142+
if args.Bio.Valid {
143+
if err := tx.Preload("Profile").First(&u, model.User{ID: b.BotUserID}).Error; err != nil {
144+
return convertError(err)
145+
}
146+
147+
if err := tx.Model(u.Profile).Update("bio", args.Bio.V).Error; err != nil {
148+
return err
149+
}
150+
userUpdated = true
151+
}
140152
return nil
141153
})
142154
if err != nil {

router/v3/bots.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ type PatchBotRequest struct {
144144
Privileged optional.Of[bool] `json:"privileged"`
145145
DeveloperID optional.Of[uuid.UUID] `json:"developerId"`
146146
SubscribeEvents model.BotEventTypes `json:"subscribeEvents"`
147+
Bio optional.Of[string] `json:"bio"`
147148
}
148149

149150
func (r PatchBotRequest) ValidateWithContext(ctx context.Context) error {
@@ -154,6 +155,7 @@ func (r PatchBotRequest) ValidateWithContext(ctx context.Context) error {
154155
vd.Field(&r.Endpoint, is.URL, validator.NotInternalURL),
155156
vd.Field(&r.DeveloperID, validator.NotNilUUID, utils.IsActiveHumanUserID),
156157
vd.Field(&r.SubscribeEvents, utils.IsValidBotEvents),
158+
vd.Field(&r.Bio, vd.RuneLength(0, 1000)),
157159
)
158160
}
159161

@@ -184,6 +186,7 @@ func (h *Handlers) EditBot(c echo.Context) error {
184186
Privileged: req.Privileged,
185187
CreatorID: req.DeveloperID,
186188
SubscribeEvents: req.SubscribeEvents,
189+
Bio: req.Bio,
187190
}
188191

189192
if err := h.Repo.UpdateBot(b.ID, args); err != nil {

router/v3/bots_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ func TestHandlers_EditBot(t *testing.T) {
531531
SubscribeEvents: map[model.BotEventType]struct{}{
532532
event.Ping: {},
533533
},
534+
Bio: optional.From("Bio"),
534535
}).
535536
Expect().
536537
Status(http.StatusNoContent)

0 commit comments

Comments
 (0)