aboutsummaryrefslogtreecommitdiff
path: root/repository/user.go
diff options
context:
space:
mode:
authorAlexander NeonXP Kiryukhin <i@neonxp.ru>2024-07-21 19:26:56 +0300
committerAlexander NeonXP Kiryukhin <i@neonxp.ru>2024-07-21 19:28:56 +0300
commitce3111b0efe91e275ce070f9511b5b1b9801a46d (patch)
tree09fa4f10dfb1e17761339c798eefa73c6b18484f /repository/user.go
parente9a64f3b41b5eae47dec7c0ecfd1caae83136abc (diff)
Множество улучшенийv0.0.2
Diffstat (limited to 'repository/user.go')
-rw-r--r--repository/user.go9
1 files changed, 8 insertions, 1 deletions
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)
+}