diff options
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) +} |