feat(posts): add post reference/internal linking functionality
Add support for referencing other posts within messages through a new post_ref segment type. Includes new PostReference model to track relationships, PostRefService for processing references, and new endpoints for post suggestions, related posts, and reference click tracking.
This commit is contained in:
40
internal/model/post_reference.go
Normal file
40
internal/model/post_reference.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type PostReferenceStatus string
|
||||
|
||||
const (
|
||||
PostRefActive PostReferenceStatus = "active"
|
||||
PostRefDead PostReferenceStatus = "dead"
|
||||
PostRefHidden PostReferenceStatus = "hidden"
|
||||
)
|
||||
|
||||
type PostReference struct {
|
||||
ID string `json:"id" gorm:"type:varchar(36);primaryKey"`
|
||||
SourcePostID string `json:"source_post_id" gorm:"type:varchar(36);not null;uniqueIndex:uq_source_target;index:idx_source_post"`
|
||||
TargetPostID string `json:"target_post_id" gorm:"type:varchar(36);not null;uniqueIndex:uq_source_target;index:idx_target_post;index:idx_target_status"`
|
||||
Status PostReferenceStatus `json:"status" gorm:"type:varchar(20);default:active;index:idx_target_status"`
|
||||
ClickCount int `json:"click_count" gorm:"default:0"`
|
||||
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
|
||||
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime:false"`
|
||||
|
||||
SourcePost *Post `json:"source_post,omitempty" gorm:"foreignKey:SourcePostID"`
|
||||
TargetPost *Post `json:"target_post,omitempty" gorm:"foreignKey:TargetPostID"`
|
||||
}
|
||||
|
||||
func (pr *PostReference) BeforeCreate(tx *gorm.DB) error {
|
||||
if pr.ID == "" {
|
||||
pr.ID = uuid.New().String()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (PostReference) TableName() string {
|
||||
return "post_references"
|
||||
}
|
||||
Reference in New Issue
Block a user