♻️ Moved account-based post to publisher-based post

This commit is contained in:
2024-10-31 22:41:32 +08:00
parent d889d22d11
commit 001c9a8140
39 changed files with 559 additions and 924 deletions

View File

@ -1,14 +0,0 @@
package models
import "git.solsynth.dev/hydrogen/dealer/pkg/hyper"
type Account struct {
hyper.BaseUser
Posts []Post `json:"posts" gorm:"foreignKey:AuthorID"`
Reactions []Reaction `json:"reactions"`
Subscriptions []Subscription `json:"subscriptions" gorm:"foreginKey:FollowerID"`
TotalUpvote int `json:"total_upvote"`
TotalDownvote int `json:"total_downvote"`
}

View File

@ -1,9 +1,9 @@
package models
import "git.solsynth.dev/hydrogen/dealer/pkg/hyper"
import "git.solsynth.dev/hypernet/nexus/pkg/nex/cruda"
type Tag struct {
hyper.BaseModel
cruda.BaseModel
Alias string `json:"alias" gorm:"uniqueIndex" validate:"lowercase"`
Name string `json:"name"`
@ -12,7 +12,7 @@ type Tag struct {
}
type Category struct {
hyper.BaseModel
cruda.BaseModel
Alias string `json:"alias" gorm:"uniqueIndex" validate:"lowercase,alphanum"`
Name string `json:"name"`

View File

@ -1,9 +1,10 @@
package models
import (
"git.solsynth.dev/hypernet/nexus/pkg/nex/cruda"
authm "git.solsynth.dev/hypernet/passport/pkg/authkit/models"
"time"
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
"gorm.io/datatypes"
)
@ -23,23 +24,21 @@ const (
)
type Post struct {
hyper.BaseModel
cruda.BaseModel
Type string `json:"type"`
Body datatypes.JSONMap `json:"body" gorm:"index:,type:gin"`
Language string `json:"language"`
Alias *string `json:"alias"`
AreaAlias *string `json:"area_alias"`
Tags []Tag `json:"tags" gorm:"many2many:post_tags"`
Categories []Category `json:"categories" gorm:"many2many:post_categories"`
Reactions []Reaction `json:"reactions"`
Replies []Post `json:"replies" gorm:"foreignKey:ReplyID"`
ReplyID *uint `json:"reply_id"`
RepostID *uint `json:"repost_id"`
RealmID *uint `json:"realm_id"`
ReplyTo *Post `json:"reply_to" gorm:"foreignKey:ReplyID"`
RepostTo *Post `json:"repost_to" gorm:"foreignKey:RepostID"`
Realm *Realm `json:"realm"`
Type string `json:"type"`
Body datatypes.JSONMap `json:"body" gorm:"index:,type:gin"`
Language string `json:"language"`
Alias *string `json:"alias"`
AliasPrefix *string `json:"alias_prefix"`
Tags []Tag `json:"tags" gorm:"many2many:post_tags"`
Categories []Category `json:"categories" gorm:"many2many:post_categories"`
Reactions []Reaction `json:"reactions"`
Replies []Post `json:"replies" gorm:"foreignKey:ReplyID"`
ReplyID *uint `json:"reply_id"`
RepostID *uint `json:"repost_id"`
ReplyTo *Post `json:"reply_to" gorm:"foreignKey:ReplyID"`
RepostTo *Post `json:"repost_to" gorm:"foreignKey:RepostID"`
VisibleUsers datatypes.JSONSlice[uint] `json:"visible_users_list"`
InvisibleUsers datatypes.JSONSlice[uint] `json:"invisible_users_list"`
@ -56,8 +55,11 @@ type Post struct {
TotalUpvote int `json:"total_upvote"`
TotalDownvote int `json:"total_downvote"`
AuthorID uint `json:"author_id"`
Author Account `json:"author"`
RealmID *uint `json:"realm_id"`
Realm *authm.Realm `json:"realm" gorm:"-"`
PublisherID uint `json:"publisher_id"`
Publisher Publisher `json:"publisher"`
Metric PostMetric `json:"metric" gorm:"-"`
}

View File

@ -0,0 +1,31 @@
package models
import "git.solsynth.dev/hypernet/nexus/pkg/nex/cruda"
const (
PublisherTypePersonal = iota
PublisherTypeOrganization
PublisherTypeAnonymous
)
type Publisher struct {
cruda.BaseModel
Type int `json:"type"`
Name string `json:"name" gorm:"uniqueIndex"`
Nick string `json:"nick"`
Description string `json:"description"`
Avatar string `json:"avatar"`
Banner string `json:"banner"`
Posts []Post `json:"posts" gorm:"foreignKey:AuthorID"`
Reactions []Reaction `json:"reactions"`
Subscriptions []Subscription `json:"subscriptions" gorm:"foreginKey:FollowerID"`
TotalUpvote int `json:"total_upvote"`
TotalDownvote int `json:"total_downvote"`
RealmID *uint `json:"realm_id"`
AccountID *uint `json:"account_id"`
}

View File

@ -20,6 +20,6 @@ type Reaction struct {
Symbol string `json:"symbol"`
Attitude ReactionAttitude `json:"attitude"`
PostID *uint `json:"post_id"`
AccountID uint `json:"account_id"`
PostID uint `json:"post_id"`
AccountID uint `json:"account_id"`
}

View File

@ -1,9 +0,0 @@
package models
import "git.solsynth.dev/hydrogen/dealer/pkg/hyper"
type Realm struct {
hyper.BaseRealm
Posts []Post `json:"posts"`
}

View File

@ -1,18 +1,16 @@
package models
import "git.solsynth.dev/hydrogen/dealer/pkg/hyper"
import "git.solsynth.dev/hypernet/nexus/pkg/nex/cruda"
type Subscription struct {
hyper.BaseModel
cruda.BaseModel
FollowerID uint `json:"follower_id"`
Follower Account `json:"follower"`
AccountID *uint `json:"account_id,omitempty"`
Account *Account `json:"account,omitempty"`
TagID *uint `json:"tag_id,omitempty"`
Tag Tag `json:"tag,omitempty"`
CategoryID *uint `json:"category_id,omitempty"`
Category Category `json:"category,omitempty"`
RealmID *uint `json:"realm_id,omitempty"`
Realm Realm `json:"realm,omitempty"`
FollowerID uint `json:"follower_id"`
Follower Publisher `json:"follower"`
AccountID *uint `json:"account_id,omitempty"`
Account *Publisher `json:"account,omitempty"`
TagID *uint `json:"tag_id,omitempty"`
Tag Tag `json:"tag,omitempty"`
CategoryID *uint `json:"category_id,omitempty"`
Category Category `json:"category,omitempty"`
}