From ce3111b0efe91e275ce070f9511b5b1b9801a46d Mon Sep 17 00:00:00 2001 From: Alexander NeonXP Kiryukhin Date: Sun, 21 Jul 2024 19:26:56 +0300 Subject: Множество улучшений MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- repository/user.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'repository/user.go') diff --git a/repository/user.go b/repository/user.go index ec3b702..5c3cce6 100644 --- a/repository/user.go +++ b/repository/user.go @@ -19,7 +19,7 @@ func NewUser(db *bun.DB) *User { } } -func (u *User) Create(ctx context.Context, email, password, username string) (int, error) { +func (u *User) Create(ctx context.Context, email, password, username string, role models.UserRole) (int, error) { hpassword, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost) if err != nil { @@ -30,6 +30,7 @@ func (u *User) Create(ctx context.Context, email, password, username string) (in Email: email, Password: string(hpassword), Username: username, + Role: role, } if _, err := u.db.NewInsert().Model(user).Returning("id").Exec(ctx); err != nil { @@ -52,3 +53,9 @@ func (u *User) Login(ctx context.Context, email, password string) (*models.User, return user, nil } + +func (u *User) List(ctx context.Context) ([]*models.User, error) { + ret := make([]*models.User, 0) + + return ret, u.db.NewSelect().Model(&ret).Scan(ctx) +} -- cgit v1.2.3