From 96e2ce2e9d363a6296f9411ecb00168520258874 Mon Sep 17 00:00:00 2001 From: Alexander NeonXP Kiryukhin Date: Mon, 29 Jul 2024 02:47:35 +0300 Subject: Отказ от echo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/node.go | 59 +++++++++++++++++++++++----------------------------------- 1 file changed, 23 insertions(+), 36 deletions(-) (limited to 'models/node.go') diff --git a/models/node.go b/models/node.go index 98a8d4e..7d3f719 100644 --- a/models/node.go +++ b/models/node.go @@ -1,49 +1,36 @@ package models import ( - "context" "time" - - "github.com/uptrace/bun" ) -type Node struct { - bun.BaseModel `bun:"table:nodes,alias:n"` - - ID int `bun:"id,pk,autoincrement"` - Type NodeType - Text string - AuthorID int - Author *User `bun:"rel:belongs-to,join:author_id=id"` - ParentID int - Parent *Node `bun:"rel:belongs-to,join:parent_id=id"` - Permission int - CreatedAt int64 `bun:",nullzero,notnull,default:current_timestamp"` - UpdatedAt int64 `bun:",nullzero,notnull,default:current_timestamp"` - DeletedAt int64 - Children []*Node `bun:"rel:has-many,join:id=parent_id"` +type Topic struct { + ID uint64 `json:"id"` + Topic string `json:"topic"` + Text string `json:"text"` + AuthorID string `json:"author_id"` + Author *User `json:"-"` + ParentID uint64 `json:"parent_id"` + Parent *Topic `json:"-"` + Permission int `json:"permission"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + DeletedAt *time.Time `json:"deleted_at"` } -var _ bun.BeforeAppendModelHook = (*Node)(nil) - -func (m *Node) BeforeAppendModel(ctx context.Context, query bun.Query) error { - switch query.(type) { - case *bun.InsertQuery: - m.CreatedAt = time.Now().Unix() - m.UpdatedAt = time.Now().Unix() - case *bun.UpdateQuery: - m.UpdatedAt = time.Now().Unix() - } - return nil +type Post struct { + ID uint64 `json:"id"` + Text string `json:"text"` + AuthorID string `json:"author_id"` + Author *User `json:"-"` + ParentID uint64 `json:"parent_id"` + Parent *Post `json:"-"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + DeletedAt *time.Time `json:"deleted_at"` + Children []*Post `json:"-"` } -type NodeType int - -const ( - TopicType NodeType = iota - PostType -) - type Permission int const ( -- cgit v1.2.3