Improve collection permission.

This commit is contained in:
2025-08-01 17:30:12 +08:00
parent 63b3a075c8
commit 0c841f2723
4 changed files with 31 additions and 25 deletions

View File

@@ -35,16 +35,21 @@ func CreateCollection(uid uint, title string, article string, images []uint, pub
func UpdateCollection(id uint, title string, article string, images []uint, public bool) error {
return db.Transaction(func(tx *gorm.DB) error {
collection := &model.Collection{
Model: gorm.Model{
ID: id,
},
Title: title,
Article: article,
Public: public, // 新增
collection := &model.Collection{}
// First find the existing collection
if err := tx.Where("id = ?", id).First(collection).Error; err != nil {
return err
}
if err := tx.Model(collection).Updates(collection).Error; err != nil {
// Update the fields
updates := map[string]interface{}{
"title": title,
"article": article,
"public": public,
}
if err := tx.Model(collection).Updates(updates).Error; err != nil {
return err
}