⬆️ Upgrade to support the latest version Hydrogen Project standard

This commit is contained in:
2024-06-22 17:29:53 +08:00
parent 52c864b11f
commit c79c8d3618
45 changed files with 538 additions and 279 deletions

View File

@ -0,0 +1,19 @@
package models
// Account profiles basically fetched from Hydrogen.Passport
// But cache at here for better usage
// At the same time this model can make relations between local models
type Account struct {
BaseModel
Name string `json:"name"`
Nick string `json:"nick"`
Avatar string `json:"avatar"`
Banner string `json:"banner"`
Description string `json:"description"`
EmailAddress string `json:"email_address"`
PowerLevel int `json:"power_level"`
Posts []Post `json:"posts" gorm:"foreignKey:AuthorID"`
Reactions []Reaction `json:"reactions"`
ExternalID uint `json:"external_id"`
}

View File

@ -0,0 +1,17 @@
package models
import (
"time"
"gorm.io/datatypes"
"gorm.io/gorm"
)
type JSONMap = datatypes.JSONType[map[string]any]
type BaseModel struct {
ID uint `json:"id" gorm:"primaryKey"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"`
}

View File

@ -0,0 +1,19 @@
package models
type Tag struct {
BaseModel
Alias string `json:"alias" gorm:"uniqueIndex" validate:"lowercase,alphanum,min=4,max=24"`
Name string `json:"name"`
Description string `json:"description"`
Posts []Post `json:"posts" gorm:"many2many:post_tags"`
}
type Category struct {
BaseModel
Alias string `json:"alias" gorm:"uniqueIndex" validate:"lowercase,alphanum,min=4,max=24"`
Name string `json:"name"`
Description string `json:"description"`
Posts []Post `json:"posts" gorm:"many2many:post_categories"`
}

View File

@ -0,0 +1,42 @@
package models
import (
"gorm.io/datatypes"
"time"
)
type PostReactInfo struct {
PostID uint `json:"post_id"`
LikeCount int64 `json:"like_count"`
DislikeCount int64 `json:"dislike_count"`
ReplyCount int64 `json:"reply_count"`
RepostCount int64 `json:"repost_count"`
}
type Post struct {
BaseModel
Alias string `json:"alias" gorm:"uniqueIndex"`
Content string `json:"content"`
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"`
Attachments datatypes.JSONSlice[uint] `json:"attachments"`
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"`
PublishedAt *time.Time `json:"published_at"`
AuthorID uint `json:"author_id"`
Author Account `json:"author"`
// Dynamic Calculated Values
ReplyCount int64 `json:"reply_count"`
ReactionCount int64 `json:"reaction_count"`
ReactionList map[string]int64 `json:"reaction_list" gorm:"-"`
}

View File

@ -0,0 +1,25 @@
package models
import (
"time"
)
type ReactionAttitude = uint8
const (
AttitudeNeutral = ReactionAttitude(iota)
AttitudePositive
AttitudeNegative
)
type Reaction struct {
ID uint `json:"id" gorm:"primaryKey"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Symbol string `json:"symbol"`
Attitude ReactionAttitude `json:"attitude"`
PostID *uint `json:"post_id"`
AccountID uint `json:"account_id"`
}

View File

@ -0,0 +1,15 @@
package models
// Realm profiles basically fetched from Hydrogen.Passport
// But cache at here for better usage and database relations
type Realm struct {
BaseModel
Alias string `json:"alias"`
Name string `json:"name"`
Description string `json:"description"`
Posts []Post `json:"posts"`
IsPublic bool `json:"is_public"`
IsCommunity bool `json:"is_community"`
ExternalID uint `json:"external_id"`
}