- Introduced new endpoints for contact discovery, including scanning, listing, and managing discovered contacts. - Implemented retry logic for handling missing DAV credentials during contact operations. - Added public share functionality for drive API, allowing users to manage public shares, including upload, delete, and rename operations. - Updated Nextcloud configuration to support public share links and improved error handling for public share permissions. - Enhanced logging and validation across contact and drive APIs for better error tracking and user feedback. - Added tests for new contact matching and ranking functionalities to ensure accuracy and reliability.
63 lines
1.7 KiB
Go
63 lines
1.7 KiB
Go
package discovery
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
"github.com/ultisuite/ulti-backend/internal/websearch"
|
|
)
|
|
|
|
func (s *Service) GetSearchSettings(ctx context.Context, externalUserID string) (websearch.Settings, error) {
|
|
return s.loadSearchSettings(ctx, externalUserID)
|
|
}
|
|
|
|
func (s *Service) UpdateSearchSettings(ctx context.Context, externalUserID string, settings websearch.Settings) (websearch.Settings, error) {
|
|
if s.db == nil {
|
|
return websearch.Settings{}, fmt.Errorf("database unavailable")
|
|
}
|
|
raw, err := json.Marshal(settings)
|
|
if err != nil {
|
|
return websearch.Settings{}, err
|
|
}
|
|
_, err = s.db.Exec(ctx, `
|
|
INSERT INTO settings (user_id, preferences)
|
|
VALUES (
|
|
(SELECT id FROM users WHERE external_id = $1),
|
|
jsonb_build_object('search', $2::jsonb)
|
|
)
|
|
ON CONFLICT (user_id) DO UPDATE SET
|
|
preferences = jsonb_set(
|
|
COALESCE(settings.preferences, '{}'::jsonb),
|
|
'{search}',
|
|
$2::jsonb
|
|
),
|
|
updated_at = NOW()
|
|
`, externalUserID, string(raw))
|
|
if err != nil {
|
|
return websearch.Settings{}, err
|
|
}
|
|
return s.loadSearchSettings(ctx, externalUserID)
|
|
}
|
|
|
|
func (s *Service) loadSearchSettings(ctx context.Context, externalUserID string) (websearch.Settings, error) {
|
|
var raw []byte
|
|
err := s.db.QueryRow(ctx, `
|
|
SELECT COALESCE(s.preferences->'search', '{}'::jsonb)
|
|
FROM users u
|
|
LEFT JOIN settings s ON s.user_id = u.id
|
|
WHERE u.external_id = $1
|
|
`, externalUserID).Scan(&raw)
|
|
if err != nil {
|
|
return websearch.Settings{}, err
|
|
}
|
|
var settings websearch.Settings
|
|
_ = json.Unmarshal(raw, &settings)
|
|
return settings, nil
|
|
}
|
|
|
|
func searchSettingsConfigured(settings websearch.Settings) bool {
|
|
_, err := websearch.ResolveProvider(settings)
|
|
return err == nil
|
|
}
|