move auth feature from container to profile

This commit is contained in:
Fabian Freund
2026-02-12 10:25:44 +01:00
parent 9f7637dd06
commit 45f54ef092
28 changed files with 903 additions and 455 deletions
+17 -4
View File
@@ -22,6 +22,7 @@ import 'package:fast_equatable/fast_equatable.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:uuid/uuid_value.dart';
import 'package:weblibre/core/uuid.dart';
import 'package:weblibre/features/user/data/models/auth_settings.dart';
part 'profile.g.dart';
@@ -31,19 +32,31 @@ class Profile with FastEquatable {
@CopyWithField(immutable: true)
final String id;
final String name;
final AuthSettings authSettings;
late final uuidValue = UuidValue.fromString(id);
static String getNewProfileId() => uuid.v7();
Profile({required this.id, required this.name});
Profile({
required this.id,
required this.name,
AuthSettings? authSettings,
}) : authSettings = authSettings ?? AuthSettings.withDefaults();
factory Profile.create({required String name}) {
return Profile(id: getNewProfileId(), name: name);
factory Profile.create({
required String name,
AuthSettings? authSettings,
}) {
return Profile(
id: getNewProfileId(),
name: name,
authSettings: authSettings,
);
}
@override
List<Object?> get hashParameters => [id, name];
List<Object?> get hashParameters => [id, name, authSettings];
factory Profile.fromJson(Map<String, dynamic> json) =>
_$ProfileFromJson(json);
+23 -4
View File
@@ -9,6 +9,8 @@ part of 'profile.dart';
abstract class _$ProfileCWProxy {
Profile name(String name);
Profile authSettings(AuthSettings? authSettings);
/// Creates a new instance with the provided field values.
/// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `Profile(...).copyWith.fieldName(value)`.
///
@@ -16,7 +18,7 @@ abstract class _$ProfileCWProxy {
/// ```dart
/// Profile(...).copyWith(id: 12, name: "My name")
/// ```
Profile call({String name});
Profile call({String name, AuthSettings? authSettings});
}
/// Callable proxy for `copyWith` functionality.
@@ -29,6 +31,10 @@ class _$ProfileCWProxyImpl implements _$ProfileCWProxy {
@override
Profile name(String name) => call(name: name);
@override
Profile authSettings(AuthSettings? authSettings) =>
call(authSettings: authSettings);
@override
/// Creates a new instance with the provided field values.
/// Passing `null` to a nullable field nullifies it, while `null` for a non-nullable field is ignored. To update a single field use `Profile(...).copyWith.fieldName(value)`.
@@ -37,13 +43,20 @@ class _$ProfileCWProxyImpl implements _$ProfileCWProxy {
/// ```dart
/// Profile(...).copyWith(id: 12, name: "My name")
/// ```
Profile call({Object? name = const $CopyWithPlaceholder()}) {
Profile call({
Object? name = const $CopyWithPlaceholder(),
Object? authSettings = const $CopyWithPlaceholder(),
}) {
return Profile(
id: _value.id,
name: name == const $CopyWithPlaceholder() || name == null
? _value.name
// ignore: cast_nullable_to_non_nullable
: name as String,
authSettings: authSettings == const $CopyWithPlaceholder()
? _value.authSettings
// ignore: cast_nullable_to_non_nullable
: authSettings as AuthSettings?,
);
}
}
@@ -59,10 +72,16 @@ extension $ProfileCopyWith on Profile {
// JsonSerializableGenerator
// **************************************************************************
Profile _$ProfileFromJson(Map<String, dynamic> json) =>
Profile(id: json['id'] as String, name: json['name'] as String);
Profile _$ProfileFromJson(Map<String, dynamic> json) => Profile(
id: json['id'] as String,
name: json['name'] as String,
authSettings: json['authSettings'] == null
? null
: AuthSettings.fromJson(json['authSettings'] as Map<String, dynamic>),
);
Map<String, dynamic> _$ProfileToJson(Profile instance) => <String, dynamic>{
'id': instance.id,
'name': instance.name,
'authSettings': instance.authSettings.toJson(),
};