diff options
author | Alexander NeonXP Kiryukhin <i@neonxp.ru> | 2024-07-21 19:26:56 +0300 |
---|---|---|
committer | Alexander NeonXP Kiryukhin <i@neonxp.ru> | 2024-07-21 19:28:56 +0300 |
commit | ce3111b0efe91e275ce070f9511b5b1b9801a46d (patch) | |
tree | 09fa4f10dfb1e17761339c798eefa73c6b18484f /repository | |
parent | e9a64f3b41b5eae47dec7c0ecfd1caae83136abc (diff) |
Множество улучшенийv0.0.2
Diffstat (limited to 'repository')
-rw-r--r-- | repository/node.go | 10 | ||||
-rw-r--r-- | repository/user.go | 9 |
2 files changed, 13 insertions, 6 deletions
diff --git a/repository/node.go b/repository/node.go index d5794b6..27282af 100644 --- a/repository/node.go +++ b/repository/node.go @@ -42,17 +42,17 @@ func (t *Node) Get(ctx context.Context, topicID int) (*models.Node, error) { Model(node). Where(`n.id = ?`, topicID). Relation("Author"). + Relation("Parent"). Scan(ctx) } -func (t *Node) List(ctx context.Context, topicID int) ([]*models.Node, int, error) { +func (t *Node) List(ctx context.Context, topicID int) ([]*models.Node, error) { posts := make([]*models.Node, 0) - count, err := t.db.NewSelect(). + return posts, t.db.NewSelect(). Model(&posts). Where(`parent_id = ?`, topicID). Relation("Author"). - ScanAndCount(ctx) - - return posts, count, err + Relation("Children"). + Scan(ctx) } 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) +} |