BatchUpdateLibrarySort 批量更新知识库排序
(eid int64, sortList []struct {
ID int64 `json:"id" binding:"required"`
Sort int64 `json:"sort" binding:"required"`
})
| 418 | |
| 419 | // BatchUpdateLibrarySort 批量更新知识库排序 |
| 420 | func BatchUpdateLibrarySort(eid int64, sortList []struct { |
| 421 | ID int64 `json:"id" binding:"required"` |
| 422 | Sort int64 `json:"sort" binding:"required"` |
| 423 | }) error { |
| 424 | tx := DB.Begin() |
| 425 | defer func() { |
| 426 | if r := recover(); r != nil { |
| 427 | tx.Rollback() |
| 428 | } |
| 429 | }() |
| 430 | |
| 431 | for _, item := range sortList { |
| 432 | if err := tx.Model(&Library{}).Where("eid = ? AND id = ?", eid, item.ID).Update("sort", item.Sort).Error; err != nil { |
| 433 | tx.Rollback() |
| 434 | return err |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | if err := tx.Commit().Error; err != nil { |
| 439 | return err |
| 440 | } |
| 441 | invalidateLibraryCache(eid) |
| 442 | return nil |
| 443 | } |
| 444 | |
| 445 | func GetRecentlyLibraries(eid int64, limit int) ([]Library, error) { |
| 446 | libraries, err := GetLibrariesByEidCached(eid) |
nothing calls this directly
no test coverage detected