spark-server/internal/module/moment/model/row.go
2026-09-18 17:51:42 +08:00

197 lines
7.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package model
import (
"time"
"spark-server/internal/module/moment/entity"
)
// Post maps table moment_posts.
type Post struct {
ID int64 `gorm:"column:id;primaryKey;comment:Snowflake 帖 id,Feed/相册游标"`
UserID int64 `gorm:"column:user_id;comment:作者 users.id"`
Kind int16 `gorm:"column:kind;comment:1纯文 2图 3视频"`
Text string `gorm:"column:text;comment:正文,可空;与媒体至少有一项"`
Content []byte `gorm:"column:content;type:blob;comment:图/视频 JSON 字节,不存媒体二进制"`
POILat float64 `gorm:"column:poi_lat;comment:地点纬度,无地点为 0"`
POILng float64 `gorm:"column:poi_lng;comment:地点经度,无地点为 0"`
POIName string `gorm:"column:poi_name;comment:地点名称"`
POIAddress string `gorm:"column:poi_address;comment:地点地址"`
Visibility int16 `gorm:"column:visibility;comment:0好友公开 1私密 2白名单 3黑名单"`
Status int16 `gorm:"column:status;comment:0正常 1已删"`
LikeCount int `gorm:"column:like_count;comment:点赞数,与 moment_likes 同事务维护"`
CommentCount int `gorm:"column:comment_count;comment:未删评论数,与 moment_comments 同事务维护"`
CreatedAt time.Time `gorm:"column:created_at;comment:发帖时间,visible_days 按此裁剪"`
}
func (Post) TableName() string { return "moment_posts" }
func (r *Post) Entity() *entity.Post {
if r == nil {
return nil
}
return &entity.Post{
ID: r.ID, UserID: r.UserID, Kind: entity.Kind(r.Kind), Text: r.Text, Content: r.Content,
POI: entity.POI{Lat: r.POILat, Lng: r.POILng, Name: r.POIName, Address: r.POIAddress},
Visibility: entity.Visibility(r.Visibility), Status: entity.Status(r.Status),
LikeCount: r.LikeCount, CommentCount: r.CommentCount, CreatedAtMS: r.CreatedAt.UnixMilli(),
}
}
func postFrom(p *entity.Post) *Post {
if p == nil {
return nil
}
row := &Post{
ID: p.ID, UserID: p.UserID, Kind: int16(p.Kind), Text: p.Text, Content: p.Content,
POILat: p.POI.Lat, POILng: p.POI.Lng, POIName: p.POI.Name, POIAddress: p.POI.Address,
Visibility: int16(p.Visibility), Status: int16(p.Status),
LikeCount: p.LikeCount, CommentCount: p.CommentCount,
}
if p.CreatedAtMS > 0 {
row.CreatedAt = time.UnixMilli(p.CreatedAtMS)
}
return row
}
// Audience maps table moment_audience.
type Audience struct {
PostID int64 `gorm:"column:post_id;primaryKey;comment:帖 id"`
PeerID int64 `gorm:"column:peer_id;primaryKey;comment:白名单能看 / 黑名单不能看 的好友 uid"`
}
func (Audience) TableName() string { return "moment_audience" }
// Like maps table moment_likes.
type Like struct {
PostID int64 `gorm:"column:post_id;primaryKey;comment:帖 id"`
UserID int64 `gorm:"column:user_id;primaryKey;comment:点赞人"`
CreatedAt time.Time `gorm:"column:created_at;comment:点赞时间"`
}
func (Like) TableName() string { return "moment_likes" }
func (r *Like) Entity() *entity.Like {
if r == nil {
return nil
}
return &entity.Like{PostID: r.PostID, UserID: r.UserID, CreatedAtMS: r.CreatedAt.UnixMilli()}
}
// Comment maps table moment_comments.
type Comment struct {
ID int64 `gorm:"column:id;primaryKey;comment:Snowflake 评论 id"`
PostID int64 `gorm:"column:post_id;comment:帖 id"`
UserID int64 `gorm:"column:user_id;comment:评论人"`
ReplyToID int64 `gorm:"column:reply_to_id;comment:父评论 id,0 表示直接评帖"`
ReplyToUID int64 `gorm:"column:reply_to_uid;comment:被回复用户,0 表示直接评帖"`
Text string `gorm:"column:text;comment:评论文本"`
Status int16 `gorm:"column:status;comment:0正常 1已删"`
CreatedAt time.Time `gorm:"column:created_at;comment:评论时间"`
}
func (Comment) TableName() string { return "moment_comments" }
func (r *Comment) Entity() *entity.Comment {
if r == nil {
return nil
}
return &entity.Comment{
ID: r.ID, PostID: r.PostID, UserID: r.UserID, ReplyToID: r.ReplyToID, ReplyToUID: r.ReplyToUID,
Text: r.Text, Status: entity.Status(r.Status), CreatedAtMS: r.CreatedAt.UnixMilli(),
}
}
func commentFrom(c *entity.Comment) *Comment {
if c == nil {
return nil
}
row := &Comment{
ID: c.ID, PostID: c.PostID, UserID: c.UserID, ReplyToID: c.ReplyToID, ReplyToUID: c.ReplyToUID,
Text: c.Text, Status: int16(c.Status),
}
if c.CreatedAtMS > 0 {
row.CreatedAt = time.UnixMilli(c.CreatedAtMS)
}
return row
}
// Notice maps table moment_notices.
type Notice struct {
ID int64 `gorm:"column:id;primaryKey;comment:Snowflake 通知 id,列表游标"`
ToUserID int64 `gorm:"column:to_user_id;comment:接收人"`
FromUserID int64 `gorm:"column:from_user_id;comment:动作发起人"`
Kind int16 `gorm:"column:kind;comment:1赞 2评论 3回复"`
PostID int64 `gorm:"column:post_id;comment:帖 id"`
CommentID int64 `gorm:"column:comment_id;comment:评论 id,赞为 0"`
ReadAt *time.Time `gorm:"column:read_at;comment:已读时间,空表示未读"`
CreatedAt time.Time `gorm:"column:created_at;comment:通知时间"`
}
func (Notice) TableName() string { return "moment_notices" }
func (r *Notice) Entity() *entity.Notice {
if r == nil {
return nil
}
n := &entity.Notice{
ID: r.ID, ToUserID: r.ToUserID, FromUserID: r.FromUserID, Kind: entity.NoticeKind(r.Kind),
PostID: r.PostID, CommentID: r.CommentID, CreatedAtMS: r.CreatedAt.UnixMilli(),
}
if r.ReadAt != nil {
n.ReadAtMS = r.ReadAt.UnixMilli()
}
return n
}
// Setting maps table moment_settings.
type Setting struct {
UserID int64 `gorm:"column:user_id;primaryKey;comment:用户 users.id"`
CoverKey string `gorm:"column:cover_key;comment:封面 object_key,空表示未设"`
VisibleDays int16 `gorm:"column:visible_days;comment:允许朋友查看范围:0全部 3/30/180 天"`
LastReadPostID int64 `gorm:"column:last_read_post_id;comment:发现页红点水位,只增不减"`
UpdatedAt time.Time `gorm:"column:updated_at;comment:最近更新时间"`
}
func (Setting) TableName() string { return "moment_settings" }
func (r *Setting) Entity() *entity.Settings {
if r == nil {
return nil
}
return &entity.Settings{
UserID: r.UserID, CoverKey: r.CoverKey, VisibleDays: entity.VisibleDays(r.VisibleDays),
LastReadPostID: r.LastReadPostID, UpdatedAtMS: r.UpdatedAt.UnixMilli(),
}
}
func settingFrom(s *entity.Settings) *Setting {
if s == nil {
return nil
}
row := &Setting{
UserID: s.UserID, CoverKey: s.CoverKey, VisibleDays: int16(s.VisibleDays), LastReadPostID: s.LastReadPostID,
}
if s.UpdatedAtMS > 0 {
row.UpdatedAt = time.UnixMilli(s.UpdatedAtMS)
}
return row
}
// Hide maps table moment_hides.
type Hide struct {
UserID int64 `gorm:"column:user_id;primaryKey;comment:设置方"`
PeerID int64 `gorm:"column:peer_id;primaryKey;comment:对方"`
HideHim bool `gorm:"column:hide_him;comment:1=不看他(Feed 去掉对方)"`
HideMe bool `gorm:"column:hide_me;comment:1=不让他看"`
}
func (Hide) TableName() string { return "moment_hides" }
func (r *Hide) Entity() *entity.Hide {
if r == nil {
return nil
}
return &entity.Hide{UserID: r.UserID, PeerID: r.PeerID, HideHim: r.HideHim, HideMe: r.HideMe}
}