Files
backend/internal/model/post_reference.go
lafay 23d7f1151e
All checks were successful
Build Backend / build (push) Successful in 2m19s
Build Backend / build-docker (push) Successful in 1m18s
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.
2026-04-26 00:37:20 +08:00

41 lines
1.4 KiB
Go

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"
}