article.go 1005 字节
package models

import (
	"time"

	"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
	"gorm.io/gorm"
)

type Article struct {
	Id           int64
	CreatedAt    time.Time
	UpdatedAt    time.Time
	DeletedAt    gorm.DeletedAt
	AuthorId     int64             // 发布人
	Author       domain.UserSimple // 发布人
	Title        string            // 文章标题
	Images       []domain.Image    // 图片
	WhoRead      []int64           // 谁可以看
	WhoReview    []int64           // 评论人
	Location     domain.Location   // 坐标
	CountLove    int               // 点赞数量
	CountComment int               // 评论数量
	Tags         []int             // 标签
	// ...more
}

func (m *Article) TableName() string {
	return "article"
}

func (m *Article) BeforeCreate(tx *gorm.DB) (err error) {
	m.CreatedAt = time.Now()
	m.UpdatedAt = time.Now()
	return
}

func (m *Article) BeforeUpdate(tx *gorm.DB) (err error) {
	m.UpdatedAt = time.Now()
	return
}