From 5792cb053e7df2f79281b19b70b27c7ef565442a Mon Sep 17 00:00:00 2001 From: yokowu <18836617@qq.com> Date: Wed, 10 Sep 2025 18:08:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E4=BF=AE=E6=94=B9=20?= =?UTF-8?q?admin=20=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/internal/user/repo/user.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/backend/internal/user/repo/user.go b/backend/internal/user/repo/user.go index 2dc26c4..64117fa 100644 --- a/backend/internal/user/repo/user.go +++ b/backend/internal/user/repo/user.go @@ -54,18 +54,20 @@ func NewUserRepo( } func (r *UserRepo) InitAdmin(ctx context.Context, username, password string) error { - _, err := r.AdminByName(ctx, username) + admin, err := r.AdminByName(ctx, username) if db.IsNotFound(err) { - _, err = r.CreateAdmin(ctx, &db.Admin{ + if _, err := r.CreateAdmin(ctx, &db.Admin{ Username: username, Password: password, Status: consts.AdminStatusActive, - }, 1) + }, 1); err != nil { + return err + } } if err != nil { return err } - return nil + return r.db.Admin.UpdateOneID(admin.ID).SetPassword(password).Exec(ctx) } func (r *UserRepo) CreateAdmin(ctx context.Context, admin *db.Admin, roleID int64) (*db.Admin, error) {