Files
1356/lifetimer/lib/data/repositories/user_repository.dart
T
Tomas Dvorak 37ffb93923 feat: Complete Phase 1 - Full Flutter app implementation with comprehensive features
Version: 1.1.0

Major changes:
- Implemented complete Flutter app structure with all core features
- Added comprehensive UI screens for auth, countdown, goals, profile, settings, and social features
- Integrated Supabase backend with authentication and data repositories
- Added offline support with Hive caching and local storage
- Implemented comprehensive routing with go_router
- Added location services with Google Maps integration
- Implemented notifications and home widget support
- Added voice recording capabilities and AI chat features
- Created comprehensive test suite and documentation
- Added Android and iOS platform configurations
- Implemented achievements system and social features
- Added calendar integration and bucket list functionality

This represents a complete Phase 1 milestone with 3,775 additions across 31 files.
2026-01-04 14:33:54 +01:00

92 lines
2.5 KiB
Dart

import 'package:supabase_flutter/supabase_flutter.dart' as supabase;
import '../models/user_model.dart' as app;
import '../../core/errors/failure.dart';
class UserRepository {
final supabase.SupabaseClient _client;
UserRepository(this._client);
Future<app.User> getProfile(String userId) async {
try {
final response = await _client
.from('users')
.select()
.eq('id', userId)
.single();
return app.User.fromJson(response);
} catch (e) {
throw _handleError(e);
}
}
Future<app.User> updateProfile({
required String userId,
String? username,
String? avatarUrl,
String? bio,
bool? isPublicProfile,
String? twitterHandle,
String? instagramHandle,
String? tiktokHandle,
String? websiteUrl,
}) async {
try {
final updates = <String, dynamic>{};
if (username != null) updates['username'] = username;
if (avatarUrl != null) updates['avatar_url'] = avatarUrl;
if (bio != null) updates['bio'] = bio;
if (isPublicProfile != null) updates['is_public_profile'] = isPublicProfile;
if (twitterHandle != null) updates['twitter_handle'] = twitterHandle;
if (instagramHandle != null) updates['instagram_handle'] = instagramHandle;
if (tiktokHandle != null) updates['tiktok_handle'] = tiktokHandle;
if (websiteUrl != null) updates['website_url'] = websiteUrl;
updates['updated_at'] = DateTime.now().toIso8601String();
final response = await _client
.from('users')
.update(updates)
.eq('id', userId)
.select()
.single();
return app.User.fromJson(response);
} catch (e) {
throw _handleError(e);
}
}
Future<bool> isUsernameAvailable(String username) async {
try {
final response = await _client
.from('users')
.select('id')
.eq('username', username)
.maybeSingle();
return response == null;
} catch (e) {
throw _handleError(e);
}
}
Future<void> deleteAccount(String userId) async {
try {
await _client.from('users').delete().eq('id', userId);
} catch (e) {
throw _handleError(e);
}
}
Failure _handleError(dynamic error) {
if (error is supabase.PostgrestException) {
if (error.code == '23505') {
return const ValidationFailure('Username already taken');
}
return ServerFailure(error.message);
}
return UnknownFailure(error.toString());
}
}