UpdatePreference 更新偏好
( ctx context.Context, userID string, category PreferenceCategory, key string, value string, )
| 228 | |
| 229 | // UpdatePreference 更新偏好 |
| 230 | func (pm *PreferenceManager) UpdatePreference( |
| 231 | ctx context.Context, |
| 232 | userID string, |
| 233 | category PreferenceCategory, |
| 234 | key string, |
| 235 | value string, |
| 236 | ) error { |
| 237 | pm.mu.Lock() |
| 238 | defer pm.mu.Unlock() |
| 239 | |
| 240 | pref := pm.findExistingPreference(userID, category, key) |
| 241 | if pref == nil { |
| 242 | return errors.New("preference not found") |
| 243 | } |
| 244 | |
| 245 | pref.Value = value |
| 246 | pref.UpdatedAt = time.Now() |
| 247 | |
| 248 | return nil |
| 249 | } |
| 250 | |
| 251 | // DeletePreference 删除偏好 |
| 252 | func (pm *PreferenceManager) DeletePreference( |