diff options
author | Alexander NeonXP Kiryukhin <i@neonxp.ru> | 2024-07-29 02:47:35 +0300 |
---|---|---|
committer | Alexander NeonXP Kiryukhin <i@neonxp.ru> | 2024-07-29 02:47:35 +0300 |
commit | 96e2ce2e9d363a6296f9411ecb00168520258874 (patch) | |
tree | 09aa7fffe10eab84ae0edd39e570355984ba0148 /repository/node.go | |
parent | 12ed72e4e1da181a6c87319a50d3b4142788b4c0 (diff) |
Отказ от echo
Diffstat (limited to 'repository/node.go')
-rw-r--r-- | repository/node.go | 58 |
1 files changed, 0 insertions, 58 deletions
diff --git a/repository/node.go b/repository/node.go deleted file mode 100644 index 27282af..0000000 --- a/repository/node.go +++ /dev/null @@ -1,58 +0,0 @@ -package repository - -import ( - "context" - - "github.com/uptrace/bun" - "gitrepo.ru/neonxp/gorum/models" -) - -type Node struct { - db *bun.DB -} - -func NewNode(db *bun.DB) *Node { - return &Node{ - db: db, - } -} - -func (t *Node) Create( - ctx context.Context, - ntype models.NodeType, - text string, - authorID int, - parentID int, -) (int, error) { - post := &models.Node{ - Type: ntype, - Text: text, - AuthorID: authorID, - ParentID: parentID, - } - _, err := t.db.NewInsert().Model(post).Returning("id").Exec(ctx) - - return post.ID, err -} - -func (t *Node) Get(ctx context.Context, topicID int) (*models.Node, error) { - node := new(models.Node) - - return node, t.db.NewSelect(). - Model(node). - Where(`n.id = ?`, topicID). - Relation("Author"). - Relation("Parent"). - Scan(ctx) -} - -func (t *Node) List(ctx context.Context, topicID int) ([]*models.Node, error) { - posts := make([]*models.Node, 0) - - return posts, t.db.NewSelect(). - Model(&posts). - Where(`parent_id = ?`, topicID). - Relation("Author"). - Relation("Children"). - Scan(ctx) -} |