Update 更新知识库信息
()
| 113 | |
| 114 | // Update 更新知识库信息 |
| 115 | func (library *Library) Update() error { |
| 116 | if library.Name == "" { |
| 117 | return errors.New("library name is required") |
| 118 | } |
| 119 | |
| 120 | // 检查名称重复(排除自己) |
| 121 | existingLibrary, err := GetLibraryByName(library.SpaceID, library.Name) |
| 122 | if err == nil && existingLibrary != nil && existingLibrary.ID != library.ID { |
| 123 | return errors.New("library name already exists in this space") |
| 124 | } |
| 125 | |
| 126 | // 明确指定要更新的字段,确保零值也能被更新,在原来的基础上加上 Visibility |
| 127 | result := DB.Model(library).Select("Name", "Description", "Icon", "SpaceID", "Visibility").Updates(library) |
| 128 | if result.Error != nil { |
| 129 | return result.Error |
| 130 | } |
| 131 | invalidateLibraryCache(library.Eid) |
| 132 | return nil |
| 133 | } |
| 134 | |
| 135 | func (library *Library) IsPersonalLibrary() bool { |
| 136 | return library != nil && library.LibraryKind == LIBRARY_KIND_PERSONAL_USER |
nothing calls this directly
no test coverage detected