add batch add ab from peer
add batch update ab tags
This commit is contained in:
@@ -3,6 +3,7 @@ package service
|
||||
import (
|
||||
"Gwen/global"
|
||||
"Gwen/model"
|
||||
"encoding/json"
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
"strings"
|
||||
@@ -116,6 +117,16 @@ func (s *AddressBookService) List(page, pageSize uint, where func(tx *gorm.DB))
|
||||
return
|
||||
}
|
||||
|
||||
func (s *AddressBookService) FromPeer(peer *model.Peer) (a *model.AddressBook) {
|
||||
a = &model.AddressBook{}
|
||||
a.Id = peer.Id
|
||||
a.Username = peer.Username
|
||||
a.Hostname = peer.Hostname
|
||||
a.UserId = peer.UserId
|
||||
a.Platform = s.PlatformFromOs(peer.Os)
|
||||
return a
|
||||
}
|
||||
|
||||
// Create 创建
|
||||
func (s *AddressBookService) Create(u *model.AddressBook) error {
|
||||
res := global.DB.Create(u).Error
|
||||
@@ -318,3 +329,12 @@ func (s *AddressBookService) CheckCollectionOwner(uid uint, cid uint) bool {
|
||||
p := s.CollectionInfoById(cid)
|
||||
return p.UserId == uid
|
||||
}
|
||||
|
||||
func (s *AddressBookService) BatchUpdateTags(abs []*model.AddressBook, tags []string) error {
|
||||
ids := make([]uint, 0)
|
||||
for _, ab := range abs {
|
||||
ids = append(ids, ab.RowId)
|
||||
}
|
||||
tagsv, _ := json.Marshal(tags)
|
||||
return global.DB.Model(&model.AddressBook{}).Where("row_id in ?", ids).Update("tags", tagsv).Error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user