Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BotのPACHにbioフィールドを追加 #2483

Merged
merged 4 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/v3-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6063,6 +6063,10 @@ components:
uniqueItems: false
items:
type: string
bio:
type: string
description: 自己紹介(biography)
maxLength: 1000
BotTokens:
title: BotTokens
type: object
Expand Down Expand Up @@ -6144,6 +6148,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)),
pikachu0310 marked this conversation as resolved.
Show resolved Hide resolved
)
}

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
Loading