✨ Articles & Article CRUD APIs
This commit is contained in:
32
pkg/internal/models/articles.go
Normal file
32
pkg/internal/models/articles.go
Normal file
@ -0,0 +1,32 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/datatypes"
|
||||
)
|
||||
|
||||
type Article struct {
|
||||
BaseModel
|
||||
|
||||
Alias string `json:"alias" gorm:"uniqueIndex"`
|
||||
Title string `json:"title"`
|
||||
Description string `json:"description"`
|
||||
Content string `json:"content"`
|
||||
Tags []Tag `json:"tags" gorm:"many2many:article_tags"`
|
||||
Categories []Category `json:"categories" gorm:"many2many:article_categories"`
|
||||
Reactions []Reaction `json:"reactions"`
|
||||
Attachments datatypes.JSONSlice[uint] `json:"attachments"`
|
||||
RealmID *uint `json:"realm_id"`
|
||||
Realm *Realm `json:"realm"`
|
||||
|
||||
IsDraft bool `json:"is_draft"`
|
||||
PublishedAt *time.Time `json:"published_at"`
|
||||
|
||||
AuthorID uint `json:"author_id"`
|
||||
Author Account `json:"author"`
|
||||
|
||||
// Dynamic Calculated Values
|
||||
ReactionCount int64 `json:"reaction_count"`
|
||||
ReactionList map[string]int64 `json:"reaction_list" gorm:"-"`
|
||||
}
|
@ -3,17 +3,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"`
|
||||
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"`
|
||||
Articles []Article `json:"articles" gorm:"many2many:article_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"`
|
||||
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"`
|
||||
Articles []Article `json:"articles" gorm:"many2many:article_categories"`
|
||||
}
|
||||
|
@ -1,17 +1,10 @@
|
||||
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"`
|
||||
}
|
||||
"gorm.io/datatypes"
|
||||
)
|
||||
|
||||
type Post struct {
|
||||
BaseModel
|
||||
@ -30,6 +23,7 @@ type Post struct {
|
||||
RepostTo *Post `json:"repost_to" gorm:"foreignKey:RepostID"`
|
||||
Realm *Realm `json:"realm"`
|
||||
|
||||
IsDraft bool `json:"is_draft"`
|
||||
PublishedAt *time.Time `json:"published_at"`
|
||||
|
||||
AuthorID uint `json:"author_id"`
|
||||
|
@ -21,5 +21,6 @@ type Reaction struct {
|
||||
Attitude ReactionAttitude `json:"attitude"`
|
||||
|
||||
PostID *uint `json:"post_id"`
|
||||
ArticleID *uint `json:"article_id"`
|
||||
AccountID uint `json:"account_id"`
|
||||
}
|
||||
|
Reference in New Issue
Block a user