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

3 years ago
package dao
import "github.com/rocboss/paopao-ce/internal/model"
3 years ago
func (d *dataServant) GetCommentContentsByIDs(ids []int64) ([]*model.CommentContent, error) {
3 years ago
commentContent := &model.CommentContent{}
return commentContent.List(d.engine, &model.ConditionsT{
"comment_id IN ?": ids,
}, 0, 0)
}
func (d *dataServant) GetCommentRepliesByID(ids []int64) ([]*model.CommentReplyFormated, error) {
3 years ago
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 *dataServant) CreateCommentContent(content *model.CommentContent) (*model.CommentContent, error) {
3 years ago
return content.Create(d.engine)
}