migrate from github
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package document_repo
|
||||
|
||||
import (
|
||||
"github.com/XingfenD/yoresee_doc/internal/model"
|
||||
)
|
||||
|
||||
func (r *DocumentRepository) MGetByIDs(ids []int64) ([]*model.Document, error) {
|
||||
if len(ids) == 0 {
|
||||
return []*model.Document{}, nil
|
||||
}
|
||||
|
||||
var docs []*model.Document
|
||||
if err := r.db.Model(&model.Document{}).Where("id IN ?", ids).Find(&docs).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
docMap := make(map[int64]*model.Document, len(docs))
|
||||
for _, doc := range docs {
|
||||
docMap[doc.ID] = doc
|
||||
}
|
||||
|
||||
ordered := make([]*model.Document, 0, len(ids))
|
||||
for _, id := range ids {
|
||||
if doc, ok := docMap[id]; ok {
|
||||
ordered = append(ordered, doc)
|
||||
}
|
||||
}
|
||||
return ordered, nil
|
||||
}
|
||||
Reference in New Issue
Block a user