Initial commit: Project documentation and git setup

This commit is contained in:
Tomas Dvorak
2026-01-03 18:35:35 +01:00
commit 1639de69d4
51 changed files with 5005 additions and 0 deletions
+81
View File
@@ -0,0 +1,81 @@
import 'package:equatable/equatable.dart';
class Goal extends Equatable {
final String id;
final String ownerId;
final String title;
final String? description;
final int progress;
final double? locationLat;
final double? locationLng;
final String? locationName;
final String? imageUrl;
final bool completed;
final DateTime createdAt;
final DateTime updatedAt;
const Goal({
required this.id,
required this.ownerId,
required this.title,
this.description,
this.progress = 0,
this.locationLat,
this.locationLng,
this.locationName,
this.imageUrl,
this.completed = false,
required this.createdAt,
required this.updatedAt,
});
bool get hasLocation => locationLat != null && locationLng != null;
bool get hasImage => imageUrl != null && imageUrl!.isNotEmpty;
Goal copyWith({
String? id,
String? ownerId,
String? title,
String? description,
int? progress,
double? locationLat,
double? locationLng,
String? locationName,
String? imageUrl,
bool? completed,
DateTime? createdAt,
DateTime? updatedAt,
}) {
return Goal(
id: id ?? this.id,
ownerId: ownerId ?? this.ownerId,
title: title ?? this.title,
description: description ?? this.description,
progress: progress ?? this.progress,
locationLat: locationLat ?? this.locationLat,
locationLng: locationLng ?? this.locationLng,
locationName: locationName ?? this.locationName,
imageUrl: imageUrl ?? this.imageUrl,
completed: completed ?? this.completed,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
);
}
@override
List<Object?> get props => [
id,
ownerId,
title,
description,
progress,
locationLat,
locationLng,
locationName,
imageUrl,
completed,
createdAt,
updatedAt,
];
}
+79
View File
@@ -0,0 +1,79 @@
import 'package:equatable/equatable.dart';
class User extends Equatable {
final String id;
final String username;
final String email;
final String? avatarUrl;
final String? bio;
final bool isPublicProfile;
final DateTime? countdownStartDate;
final DateTime? countdownEndDate;
final DateTime createdAt;
final DateTime updatedAt;
const User({
required this.id,
required this.username,
required this.email,
this.avatarUrl,
this.bio,
this.isPublicProfile = false,
this.countdownStartDate,
this.countdownEndDate,
required this.createdAt,
required this.updatedAt,
});
bool get hasCountdownStarted => countdownStartDate != null;
bool get isCountdownActive {
if (!hasCountdownStarted || countdownEndDate == null) return false;
return DateTime.now().isBefore(countdownEndDate!);
}
int? get daysRemaining {
if (!isCountdownActive) return null;
return countdownEndDate!.difference(DateTime.now()).inDays;
}
User copyWith({
String? id,
String? username,
String? email,
String? avatarUrl,
String? bio,
bool? isPublicProfile,
DateTime? countdownStartDate,
DateTime? countdownEndDate,
DateTime? createdAt,
DateTime? updatedAt,
}) {
return User(
id: id ?? this.id,
username: username ?? this.username,
email: email ?? this.email,
avatarUrl: avatarUrl ?? this.avatarUrl,
bio: bio ?? this.bio,
isPublicProfile: isPublicProfile ?? this.isPublicProfile,
countdownStartDate: countdownStartDate ?? this.countdownStartDate,
countdownEndDate: countdownEndDate ?? this.countdownEndDate,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
);
}
@override
List<Object?> get props => [
id,
username,
email,
avatarUrl,
bio,
isPublicProfile,
countdownStartDate,
countdownEndDate,
createdAt,
updatedAt,
];
}
@@ -0,0 +1,125 @@
import '../models/user_model.dart';
import '../../bootstrap/supabase_client.dart';
import 'package:supabase_flutter/supabase_flutter.dart' hide User;
class AuthRepository {
final SupabaseClient _client;
AuthRepository([SupabaseClient? client]) : _client = client ?? supabaseClient;
Stream<User?> get authStateChanges {
return _client.auth.onAuthStateChange.map((data) {
final session = data.session;
if (session?.user != null) {
return _mapSupabaseUserToAppUser(session!.user);
}
return null;
});
}
User? get currentUser {
final user = _client.auth.currentUser;
return user != null ? _mapSupabaseUserToAppUser(user) : null;
}
Future<void> signInWithEmail(String email, String password) async {
await _client.auth.signInWithPassword(email: email, password: password);
}
Future<void> signUpWithEmail(String email, String password, String username) async {
final response = await _client.auth.signUp(
email: email,
password: password,
data: {'username': username},
);
if (response.user != null) {
await _createUserProfile(response.user!.id, username, email);
}
}
Future<void> signInWithGoogle() async {
// TODO: Implement Google OAuth
// await _client.auth.signInWithOAuth(OAuthProvider.google);
throw UnimplementedError('Google OAuth not implemented yet');
}
Future<void> signInWithApple() async {
// TODO: Implement Apple OAuth
// await _client.auth.signInWithOAuth(OAuthProvider.apple);
throw UnimplementedError('Apple OAuth not implemented yet');
}
Future<void> signOut() async {
await _client.auth.signOut();
}
Future<void> resetPassword(String email) async {
await _client.auth.resetPasswordForEmail(email);
}
Future<void> updateProfile({
String? username,
String? bio,
String? avatarUrl,
bool? isPublicProfile,
}) async {
final userId = _client.auth.currentUser?.id;
if (userId == null) throw Exception('User not authenticated');
final updates = <String, dynamic>{};
if (username != null) updates['username'] = username;
if (bio != null) updates['bio'] = bio;
if (avatarUrl != null) updates['avatar_url'] = avatarUrl;
if (isPublicProfile != null) updates['is_public_profile'] = isPublicProfile;
updates['updated_at'] = DateTime.now().toIso8601String();
await _client
.from('users')
.update(updates)
.eq('id', userId);
}
Future<User> _createUserProfile(String userId, String username, String email) async {
final now = DateTime.now().toIso8601String();
final response = await _client.from('users').insert({
'id': userId,
'username': username,
'email': email,
'created_at': now,
'updated_at': now,
}).select().single();
return _mapSupabaseDataToUser(response);
}
User _mapSupabaseUserToAppUser(dynamic supabaseUser) {
return User(
id: supabaseUser.id,
username: supabaseUser.userMetadata?['username'] ?? '',
email: supabaseUser.email ?? '',
createdAt: DateTime.tryParse(supabaseUser.createdAt ?? '') ?? DateTime.now(),
updatedAt: DateTime.tryParse(supabaseUser.updatedAt ?? '') ?? DateTime.now(),
);
}
User _mapSupabaseDataToUser(Map<String, dynamic> data) {
return User(
id: data['id'],
username: data['username'],
email: data['email'],
avatarUrl: data['avatar_url'],
bio: data['bio'],
isPublicProfile: data['is_public_profile'] ?? false,
countdownStartDate: data['countdown_start_date'] != null
? DateTime.parse(data['countdown_start_date'])
: null,
countdownEndDate: data['countdown_end_date'] != null
? DateTime.parse(data['countdown_end_date'])
: null,
createdAt: DateTime.parse(data['created_at']),
updatedAt: DateTime.parse(data['updated_at']),
);
}
}