GetPreference 获取偏好
( ctx context.Context, userID string, category PreferenceCategory, key string, )
| 188 | |
| 189 | // GetPreference 获取偏好 |
| 190 | func (pm *PreferenceManager) GetPreference( |
| 191 | ctx context.Context, |
| 192 | userID string, |
| 193 | category PreferenceCategory, |
| 194 | key string, |
| 195 | ) (*Preference, error) { |
| 196 | pm.mu.RLock() |
| 197 | defer pm.mu.RUnlock() |
| 198 | |
| 199 | pref := pm.findExistingPreference(userID, category, key) |
| 200 | if pref == nil { |
| 201 | return nil, errors.New("preference not found") |
| 202 | } |
| 203 | |
| 204 | // 更新访问计数 |
| 205 | pref.AccessCount++ |
| 206 | |
| 207 | return pref, nil |
| 208 | } |
| 209 | |
| 210 | // ListPreferences 列出用户的所有偏好 |
| 211 | func (pm *PreferenceManager) ListPreferences( |