refactor: reorganize modules and add Linux build tooling
This commit is contained in:
20
module/social/feed/internal/models/feed_comment.go
Normal file
20
module/social/feed/internal/models/feed_comment.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/types"
|
||||
|
||||
// feed评论表
|
||||
type FeedComment struct {
|
||||
types.Std_IICUDS
|
||||
types.Std_Passport
|
||||
PostIdentity string `gorm:"column:post_identity;type:varchar(36);index;" json:"post_identity"` // 推文唯一码
|
||||
ParentIdentity string `gorm:"column:parent_identity;type:varchar(36);index;" json:"parent_identity"` // 上级评论唯一码
|
||||
Content string `gorm:"column:content;type:text;default:'';" json:"content"` // 正文
|
||||
SubComment []FeedComment `gorm:"foreignkey:parent_identity;"` // 子评论唯一码
|
||||
CntLike int64 `gorm:"column:cnt_like;type:int;default:0" json:"cnt_like"` // 点赞数
|
||||
CntUnlike int64 `gorm:"column:cnt_unlike;type:int;default:0" json:"cnt_unlike"` // 点踩数
|
||||
CntComment int64 `gorm:"column:cnt_comment;type:int;default:0" json:"cnt_comment"` // 评论数
|
||||
}
|
||||
|
||||
func (table *FeedComment) TableName() string {
|
||||
return "feed_comment"
|
||||
}
|
||||
22
module/social/feed/internal/models/feed_post.go
Normal file
22
module/social/feed/internal/models/feed_post.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/types"
|
||||
)
|
||||
|
||||
// feed推文表
|
||||
type FeedPost struct {
|
||||
types.Std_IICUDS
|
||||
types.Std_Passport
|
||||
Content string `gorm:"column:content;type:text;default:'';" json:"content"` // 正文
|
||||
IsOpen bool `gorm:"column:is_open;default:true;" json:"is_open"` // 默认为true-公开,false-不公开
|
||||
CntLike int64 `gorm:"column:cnt_like;type:int;default:0;" json:"cnt_like"` // 点赞数
|
||||
CntUnlike int64 `gorm:"column:cnt_unlike;type:int;default:0;" json:"cnt_unlike"` // 点踩数
|
||||
CntComment int64 `gorm:"column:cnt_comment;type:int;default:0;" json:"cnt_comment"` // 评论数
|
||||
Attachs []FeedRelateAttach `gorm:"-"`
|
||||
Tags []FeedRelateTags `gorm:"-"`
|
||||
}
|
||||
|
||||
func (c *FeedPost) TableName() string {
|
||||
return "feed_post"
|
||||
}
|
||||
16
module/social/feed/internal/models/feed_relate_attachs.go
Normal file
16
module/social/feed/internal/models/feed_relate_attachs.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/types"
|
||||
|
||||
// feed 关联附件表
|
||||
type FeedRelateAttach struct {
|
||||
types.Std_IDIdentity
|
||||
Identity string `gorm:"column:identity;type:varchar(36);uniqueIndex;"`
|
||||
PostIdentity string `gorm:"column:post_identity;type:varchar(36);index;" json:"post_identity"` // 推文唯一码
|
||||
AttachType string `gorm:"column:attach_type;type:varchar(36);index;" json:"attach_type"` // 附件类型
|
||||
Url string `gorm:"column:url;type:varchar(255);index;" json:"url"` // 附件地址
|
||||
}
|
||||
|
||||
func (table *FeedRelateAttach) TableName() string {
|
||||
return "feed_relate_attach"
|
||||
}
|
||||
15
module/social/feed/internal/models/feed_relate_tags.go
Normal file
15
module/social/feed/internal/models/feed_relate_tags.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package models
|
||||
|
||||
import "git.apinb.com/bsm-sdk/core/types"
|
||||
|
||||
// feed 关联标签表
|
||||
type FeedRelateTags struct {
|
||||
types.Std_IDIdentity
|
||||
PostIdentity string `gorm:"column:post_identity;type:varchar(36);index;" json:"post_identity"`
|
||||
Key string `gorm:"column:key;type:varchar(36);index;" json:"key"`
|
||||
Content string `gorm:"-"`
|
||||
}
|
||||
|
||||
func (table *FeedRelateTags) TableName() string {
|
||||
return "feed_relate_tags"
|
||||
}
|
||||
16
module/social/feed/internal/models/feed_tags.go
Normal file
16
module/social/feed/internal/models/feed_tags.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// feed标签表
|
||||
type FeedTags struct {
|
||||
gorm.Model
|
||||
Key string `gorm:"column:key;type:varchar(36);not null" json:"key"`
|
||||
Content string `gorm:"column:content;type:varchar(255);not null" json:"content"`
|
||||
}
|
||||
|
||||
func (c *FeedTags) TableName() string {
|
||||
return "feed_tags"
|
||||
}
|
||||
125
module/social/feed/internal/models/query.go
Normal file
125
module/social/feed/internal/models/query.go
Normal file
@@ -0,0 +1,125 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"bsm/full/module/social/feed/internal/impl"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func InitData() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreatePost(data *FeedPost) error {
|
||||
err := impl.DBService.Transaction(func(tx *gorm.DB) error {
|
||||
if err := tx.Create(&data).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Create(&data.Attachs).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if err := tx.Create(&data.Tags).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
return err
|
||||
}
|
||||
func ChargePost(data *FeedPost) error {
|
||||
err := impl.DBService.Where("identity = ?", data.Identity).Updates(&data).Error
|
||||
return err
|
||||
}
|
||||
func DeletePost(identity string) error {
|
||||
err := impl.DBService.Where("identity = ?", identity).Delete(&FeedPost{}).Error
|
||||
return err
|
||||
}
|
||||
|
||||
// 点赞/踩操作
|
||||
func LikeAction(action_op, action_type, identity string) (err error) {
|
||||
var column string
|
||||
tx := impl.DBService
|
||||
if action_type == "post" {
|
||||
tx = tx.Model(&FeedPost{})
|
||||
} else if action_type == "comment" {
|
||||
tx = tx.Model(&FeedComment{})
|
||||
}
|
||||
if action_op == "ilike" {
|
||||
column = "cnt_like"
|
||||
} else if action_type == "unlike" {
|
||||
column = "cnt_unlike"
|
||||
}
|
||||
if err = tx.Where("identity = ?", identity).UpdateColumn(column, gorm.Expr(fmt.Sprintf("%s + ?", column), 1)).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// PostList
|
||||
func PostList(page, size int64, tag string) (list []*FeedPost, cnt int64, err error) {
|
||||
tx := impl.DBService.Order("created_at desc")
|
||||
if tag != "" {
|
||||
tx = tx.Joins("join feed_relate_tags on feed_relate_tags.post_identity = feed_post.identity", impl.DBService.Where(&FeedRelateTags{Key: tag}))
|
||||
tx = tx.Where("key = ?", tag)
|
||||
}
|
||||
|
||||
tx.Limit(int(page)).Offset(int((page - 1) * size))
|
||||
err = tx.Find(&list).Count(&cnt).Error
|
||||
fmt.Print("posts", list)
|
||||
return
|
||||
}
|
||||
|
||||
func AddTags(data *[]FeedTags) (err error) {
|
||||
err = impl.DBService.Create(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return err
|
||||
}
|
||||
func ModifyTags(data *FeedTags) (err error) {
|
||||
err = impl.DBService.Where("identity = ?", data.Key).Save(data).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func DeleteTags(key string) (err error) {
|
||||
err = impl.DBService.Where("identity = ?", key).Delete(&FeedTags{}).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func TagsList() (list []*FeedTags, cnt int64, err error) {
|
||||
tags := make([]*FeedTags, 0)
|
||||
tx := impl.DBService.Order("created_at desc")
|
||||
err = tx.Find(&tags).Count(&cnt).Error
|
||||
return tags, cnt, err
|
||||
}
|
||||
|
||||
func AddComment(comment *FeedComment, authorIdentity string) (err error) {
|
||||
err = impl.DBService.Transaction(func(tx *gorm.DB) error {
|
||||
// 添加评论,更新文章评论量
|
||||
err := tx.Create(comment).Table("feed_post").Where("identity = ?", comment.PostIdentity).UpdateColumn("cnt_comment", gorm.Expr("cnt_comment + ?", 1)).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if comment.ParentIdentity != "" {
|
||||
//更新被评论的评论数
|
||||
err = tx.Where("identity = ?", comment.ParentIdentity).UpdateColumn("cnt_comment", gorm.Expr("cnt_comment + ?", 1)).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
func DeleteComment(identity string) (err error) {
|
||||
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user