✨ New datasets
This commit is contained in:
@ -8,19 +8,24 @@ import "time"
|
||||
type Account struct {
|
||||
BaseModel
|
||||
|
||||
Name string `json:"name"`
|
||||
Nick string `json:"nick"`
|
||||
Avatar string `json:"avatar"`
|
||||
Description string `json:"description"`
|
||||
EmailAddress string `json:"email_address"`
|
||||
PowerLevel int `json:"power_level"`
|
||||
Posts []Post `json:"posts" gorm:"foreignKey:AuthorID"`
|
||||
Attachments []Attachment `json:"attachments" gorm:"foreignKey:AuthorID"`
|
||||
LikedPosts []PostLike `json:"liked_posts"`
|
||||
DislikedPosts []PostDislike `json:"disliked_posts"`
|
||||
RealmIdentities []RealmMember `json:"identities"`
|
||||
Realms []Realm `json:"realms"`
|
||||
ExternalID uint `json:"external_id"`
|
||||
Name string `json:"name"`
|
||||
Nick string `json:"nick"`
|
||||
Avatar string `json:"avatar"`
|
||||
Description string `json:"description"`
|
||||
EmailAddress string `json:"email_address"`
|
||||
PowerLevel int `json:"power_level"`
|
||||
Moments []Moment `json:"moments" gorm:"foreignKey:AuthorID"`
|
||||
Articles []Article `json:"articles" gorm:"foreignKey:AuthorID"`
|
||||
Attachments []Attachment `json:"attachments" gorm:"foreignKey:AuthorID"`
|
||||
LikedMoments []MomentLike `json:"liked_moments"`
|
||||
DislikedMoments []MomentDislike `json:"disliked_moments"`
|
||||
LikedArticles []ArticleLike `json:"liked_articles"`
|
||||
DislikedArticles []ArticleDislike `json:"disliked_articles"`
|
||||
LikedComments []CommentLike `json:"liked_comments"`
|
||||
DislikedComments []CommentDislike `json:"disliked_comments"`
|
||||
RealmIdentities []RealmMember `json:"identities"`
|
||||
Realms []Realm `json:"realms"`
|
||||
ExternalID uint `json:"external_id"`
|
||||
}
|
||||
|
||||
type AccountMembership struct {
|
||||
|
41
pkg/models/articles.go
Normal file
41
pkg/models/articles.go
Normal file
@ -0,0 +1,41 @@
|
||||
package models
|
||||
|
||||
type Article struct {
|
||||
PostBase
|
||||
|
||||
Title string `json:"title"`
|
||||
Hashtags []Tag `json:"tags" gorm:"many2many:article_tags"`
|
||||
Categories []Category `json:"categories" gorm:"many2many:article_categories"`
|
||||
LikedAccounts []ArticleLike `json:"liked_accounts"`
|
||||
DislikedAccounts []ArticleDislike `json:"disliked_accounts"`
|
||||
Description string `json:"description"`
|
||||
Content string `json:"content"`
|
||||
RealmID *uint `json:"realm_id"`
|
||||
Realm *Realm `json:"realm"`
|
||||
|
||||
Comments []Comment `json:"comments" gorm:"foreignKey:ArticleID"`
|
||||
}
|
||||
|
||||
func (p Article) GetReplyTo() PostInterface {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p Article) GetRepostTo() PostInterface {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p Article) GetHashtags() []Tag {
|
||||
return p.Hashtags
|
||||
}
|
||||
|
||||
func (p Article) GetCategories() []Category {
|
||||
return p.Categories
|
||||
}
|
||||
|
||||
func (p Article) SetHashtags(tags []Tag) {
|
||||
p.Hashtags = tags
|
||||
}
|
||||
|
||||
func (p Article) SetCategories(categories []Category) {
|
||||
p.Categories = categories
|
||||
}
|
@ -6,18 +6,29 @@ import (
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type AttachmentType = uint8
|
||||
|
||||
const (
|
||||
AttachmentOthers = AttachmentType(iota)
|
||||
AttachmentPhoto
|
||||
AttachmentVideo
|
||||
AttachmentAudio
|
||||
)
|
||||
|
||||
type Attachment struct {
|
||||
BaseModel
|
||||
|
||||
FileID string `json:"file_id"`
|
||||
Filesize int64 `json:"filesize"`
|
||||
Filename string `json:"filename"`
|
||||
Mimetype string `json:"mimetype"`
|
||||
ExternalUrl string `json:"external_url"`
|
||||
Post *Post `json:"post"`
|
||||
Author Account `json:"author"`
|
||||
PostID *uint `json:"post_id"`
|
||||
AuthorID uint `json:"author_id"`
|
||||
FileID string `json:"file_id"`
|
||||
Filesize int64 `json:"filesize"`
|
||||
Filename string `json:"filename"`
|
||||
Mimetype string `json:"mimetype"`
|
||||
Type AttachmentType `json:"type"`
|
||||
ExternalUrl string `json:"external_url"`
|
||||
Author Account `json:"author"`
|
||||
ArticleID *uint `json:"article_id"`
|
||||
MomentID *uint `json:"moment_id"`
|
||||
CommentID *uint `json:"comment_id"`
|
||||
AuthorID uint `json:"author_id"`
|
||||
}
|
||||
|
||||
func (v Attachment) GetStoragePath() string {
|
||||
|
@ -3,17 +3,21 @@ 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"`
|
||||
Alias string `json:"alias" gorm:"uniqueIndex" validate:"lowercase,alphanum,min=4,max=24"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Articles []Article `json:"articles" gorm:"many2many:article_tags"`
|
||||
Moments []Moment `json:"moments" gorm:"many2many:moment_tags"`
|
||||
Comments []Comment `json:"comments" gorm:"many2many:comment_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:"categories" gorm:"many2many:post_categories"`
|
||||
Alias string `json:"alias" gorm:"uniqueIndex" validate:"lowercase,alphanum,min=4,max=24"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Articles []Article `json:"articles" gorm:"many2many:article_categories"`
|
||||
Moments []Moment `json:"moments" gorm:"many2many:moment_categories"`
|
||||
Comments []Comment `json:"comments" gorm:"many2many:comment_categories"`
|
||||
}
|
||||
|
38
pkg/models/comments.go
Normal file
38
pkg/models/comments.go
Normal file
@ -0,0 +1,38 @@
|
||||
package models
|
||||
|
||||
type Comment struct {
|
||||
PostBase
|
||||
|
||||
Content string `json:"content"`
|
||||
Hashtags []Tag `json:"tags" gorm:"many2many:comment_tags"`
|
||||
Categories []Category `json:"categories" gorm:"many2many:comment_categories"`
|
||||
LikedAccounts []CommentLike `json:"liked_accounts"`
|
||||
DislikedAccounts []CommentDislike `json:"disliked_accounts"`
|
||||
ReplyID *uint `json:"reply_id"`
|
||||
ReplyTo *Comment `json:"reply_to" gorm:"foreignKey:ReplyID"`
|
||||
|
||||
ArticleID *uint `json:"article_id"`
|
||||
MomentID *uint `json:"moment_id"`
|
||||
Article *Article `json:"article"`
|
||||
Moment *Moment `json:"moment"`
|
||||
}
|
||||
|
||||
func (p Comment) GetReplyTo() PostInterface {
|
||||
return p.ReplyTo
|
||||
}
|
||||
|
||||
func (p Comment) GetHashtags() []Tag {
|
||||
return p.Hashtags
|
||||
}
|
||||
|
||||
func (p Comment) GetCategories() []Category {
|
||||
return p.Categories
|
||||
}
|
||||
|
||||
func (p Comment) SetHashtags(tags []Tag) {
|
||||
p.Hashtags = tags
|
||||
}
|
||||
|
||||
func (p Comment) SetCategories(categories []Category) {
|
||||
p.Categories = categories
|
||||
}
|
41
pkg/models/moments.go
Normal file
41
pkg/models/moments.go
Normal file
@ -0,0 +1,41 @@
|
||||
package models
|
||||
|
||||
type Moment struct {
|
||||
PostBase
|
||||
|
||||
Content string `json:"content"`
|
||||
Hashtags []Tag `json:"tags" gorm:"many2many:moment_tags"`
|
||||
Categories []Category `json:"categories" gorm:"many2many:moment_categories"`
|
||||
LikedAccounts []MomentLike `json:"liked_accounts"`
|
||||
DislikedAccounts []MomentDislike `json:"disliked_accounts"`
|
||||
RealmID *uint `json:"realm_id"`
|
||||
RepostID *uint `json:"repost_id"`
|
||||
Realm *Realm `json:"realm"`
|
||||
RepostTo *Moment `json:"repost_to" gorm:"foreignKey:RepostID"`
|
||||
|
||||
Comments []Comment `json:"comments" gorm:"foreignKey:MomentID"`
|
||||
}
|
||||
|
||||
func (p Moment) GetRepostTo() PostInterface {
|
||||
return p.RepostTo
|
||||
}
|
||||
|
||||
func (p Moment) GetRealm() *Realm {
|
||||
return p.Realm
|
||||
}
|
||||
|
||||
func (p Moment) GetHashtags() []Tag {
|
||||
return p.Hashtags
|
||||
}
|
||||
|
||||
func (p Moment) GetCategories() []Category {
|
||||
return p.Categories
|
||||
}
|
||||
|
||||
func (p Moment) SetHashtags(tags []Tag) {
|
||||
p.Hashtags = tags
|
||||
}
|
||||
|
||||
func (p Moment) SetCategories(categories []Category) {
|
||||
p.Categories = categories
|
||||
}
|
@ -1,26 +1,26 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Post struct {
|
||||
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 PostBase struct {
|
||||
BaseModel
|
||||
|
||||
Content string `json:"content"`
|
||||
Hashtags []Tag `json:"tags" gorm:"many2many:post_tags"`
|
||||
Categories []Category `json:"categories" gorm:"many2many:post_categories"`
|
||||
Attachments []Attachment `json:"attachments"`
|
||||
LikedAccounts []PostLike `json:"liked_accounts"`
|
||||
DislikedAccounts []PostDislike `json:"disliked_accounts"`
|
||||
RepostTo *Post `json:"repost_to" gorm:"foreignKey:RepostID"`
|
||||
ReplyTo *Post `json:"reply_to" gorm:"foreignKey:ReplyID"`
|
||||
PinnedAt *time.Time `json:"pinned_at"`
|
||||
EditedAt *time.Time `json:"edited_at"`
|
||||
PublishedAt time.Time `json:"published_at"`
|
||||
RepostID *uint `json:"repost_id"`
|
||||
ReplyID *uint `json:"reply_id"`
|
||||
RealmID *uint `json:"realm_id"`
|
||||
AuthorID uint `json:"author_id"`
|
||||
Author Account `json:"author"`
|
||||
Alias string `json:"alias" gorm:"uniqueIndex"`
|
||||
Attachments []Attachment `json:"attachments"`
|
||||
PublishedAt *time.Time `json:"published_at"`
|
||||
|
||||
AuthorID uint `json:"author_id"`
|
||||
Author Account `json:"author"`
|
||||
|
||||
// Dynamic Calculating Values
|
||||
LikeCount int64 `json:"like_count" gorm:"-"`
|
||||
@ -28,3 +28,44 @@ type Post struct {
|
||||
ReplyCount int64 `json:"reply_count" gorm:"-"`
|
||||
RepostCount int64 `json:"repost_count" gorm:"-"`
|
||||
}
|
||||
|
||||
func (p PostBase) GetID() uint {
|
||||
return p.ID
|
||||
}
|
||||
|
||||
func (p PostBase) GetReplyTo() PostInterface {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p PostBase) GetRepostTo() PostInterface {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p PostBase) GetAuthor() Account {
|
||||
return p.Author
|
||||
}
|
||||
|
||||
func (p PostBase) GetRealm() *Realm {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p PostBase) SetReactInfo(info PostReactInfo) {
|
||||
p.LikeCount = info.LikeCount
|
||||
p.DislikeCount = info.DislikeCount
|
||||
p.ReplyCount = info.ReplyCount
|
||||
p.RepostCount = info.RepostCount
|
||||
}
|
||||
|
||||
type PostInterface interface {
|
||||
GetID() uint
|
||||
GetHashtags() []Tag
|
||||
GetCategories() []Category
|
||||
GetReplyTo() PostInterface
|
||||
GetRepostTo() PostInterface
|
||||
GetAuthor() Account
|
||||
GetRealm() *Realm
|
||||
|
||||
SetHashtags([]Tag)
|
||||
SetCategories([]Category)
|
||||
SetReactInfo(PostReactInfo)
|
||||
}
|
||||
|
@ -2,18 +2,62 @@ package models
|
||||
|
||||
import "time"
|
||||
|
||||
type PostLike struct {
|
||||
type CommentLike struct {
|
||||
ID uint `json:"id" gorm:"primaryKey"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
PostID uint `json:"post_id"`
|
||||
ArticleID *uint `json:"article_id"`
|
||||
MomentID *uint `json:"moment_id"`
|
||||
CommentID *uint `json:"comment_id"`
|
||||
AccountID uint `json:"account_id"`
|
||||
}
|
||||
|
||||
type PostDislike struct {
|
||||
type CommentDislike struct {
|
||||
ID uint `json:"id" gorm:"primaryKey"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
PostID uint `json:"post_id"`
|
||||
ArticleID *uint `json:"article_id"`
|
||||
MomentID *uint `json:"moment_id"`
|
||||
CommentID *uint `json:"comment_id"`
|
||||
AccountID uint `json:"account_id"`
|
||||
}
|
||||
|
||||
type MomentLike struct {
|
||||
ID uint `json:"id" gorm:"primaryKey"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
ArticleID *uint `json:"article_id"`
|
||||
MomentID *uint `json:"moment_id"`
|
||||
CommentID *uint `json:"comment_id"`
|
||||
AccountID uint `json:"account_id"`
|
||||
}
|
||||
|
||||
type MomentDislike struct {
|
||||
ID uint `json:"id" gorm:"primaryKey"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
ArticleID *uint `json:"article_id"`
|
||||
MomentID *uint `json:"moment_id"`
|
||||
CommentID *uint `json:"comment_id"`
|
||||
AccountID uint `json:"account_id"`
|
||||
}
|
||||
|
||||
type ArticleLike struct {
|
||||
ID uint `json:"id" gorm:"primaryKey"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
ArticleID *uint `json:"article_id"`
|
||||
MomentID *uint `json:"moment_id"`
|
||||
CommentID *uint `json:"comment_id"`
|
||||
AccountID uint `json:"account_id"`
|
||||
}
|
||||
|
||||
type ArticleDislike struct {
|
||||
ID uint `json:"id" gorm:"primaryKey"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
ArticleID *uint `json:"article_id"`
|
||||
MomentID *uint `json:"moment_id"`
|
||||
CommentID *uint `json:"comment_id"`
|
||||
AccountID uint `json:"account_id"`
|
||||
}
|
||||
|
@ -5,7 +5,8 @@ type Realm struct {
|
||||
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Posts []Post `json:"posts"`
|
||||
Articles []Article `json:"article"`
|
||||
Moments []Moment `json:"moments"`
|
||||
Members []RealmMember `json:"members"`
|
||||
IsPublic bool `json:"is_public"`
|
||||
AccountID uint `json:"account_id"`
|
||||
|
Reference in New Issue
Block a user