You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
paopao-ce/internal/dao/comment_content.go

51 lines
1.3 KiB

2 years ago
package dao
import "github.com/rocboss/paopao-ce/internal/model"
2 years ago
func (d *Dao) GetCommentContentsByIDs(ids []int64) ([]*model.CommentContent, error) {
commentContent := &model.CommentContent{}
return commentContent.List(d.engine, &model.ConditionsT{
"comment_id IN ?": ids,
}, 0, 0)
}
func (d *Dao) GetCommentRepliesByID(ids []int64) ([]*model.CommentReplyFormated, error) {
CommentReply := &model.CommentReply{}
replies, err := CommentReply.List(d.engine, &model.ConditionsT{
"comment_id IN ?": ids,
}, 0, 0)
if err != nil {
return nil, err
}
userIds := []int64{}
for _, reply := range replies {
userIds = append(userIds, reply.UserID, reply.AtUserID)
}
users, err := d.GetUsersByIDs(userIds)
if err != nil {
return nil, err
}
repliesFormated := []*model.CommentReplyFormated{}
for _, reply := range replies {
replyFormated := reply.Format()
for _, user := range users {
if reply.UserID == user.ID {
replyFormated.User = user.Format()
}
if reply.AtUserID == user.ID {
replyFormated.AtUser = user.Format()
}
}
repliesFormated = append(repliesFormated, replyFormated)
}
return repliesFormated, nil
}
func (d *Dao) CreateCommentContent(content *model.CommentContent) (*model.CommentContent, error) {
return content.Create(d.engine)
}