aboutsummaryrefslogtreecommitdiff
path: root/models/node.go
diff options
context:
space:
mode:
authorAlexander NeonXP Kiryukhin <i@neonxp.ru>2024-07-29 02:47:35 +0300
committerAlexander NeonXP Kiryukhin <i@neonxp.ru>2024-07-29 02:47:35 +0300
commit96e2ce2e9d363a6296f9411ecb00168520258874 (patch)
tree09aa7fffe10eab84ae0edd39e570355984ba0148 /models/node.go
parent12ed72e4e1da181a6c87319a50d3b4142788b4c0 (diff)
Отказ от echo
Diffstat (limited to 'models/node.go')
-rw-r--r--models/node.go59
1 files changed, 23 insertions, 36 deletions
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 (