refactor user repo with helpers. better api validation etc.

This commit is contained in:
2025-01-01 19:58:19 +00:00
parent 8559b1c44e
commit 4d52186d21
23 changed files with 1802 additions and 237 deletions
@@ -6,15 +6,39 @@ part 'user_dto.g.dart';
@freezed
class UserDto with _$UserDto {
const factory UserDto({
String? id,
String? name,
String? email,
String? password,
required String id,
required String name,
required String email,
DateTime? createdAt,
DateTime? updatedAt,
}) = _UserDto;
/// JSON-Serialisierung
factory UserDto.fromJson(Map<String, dynamic> json) =>
_$UserDtoFromJson(json);
factory UserDto.fromJson(Map<String, dynamic> json) => _$UserDtoFromJson(json);
}
@freezed
class UserCreateDto with _$UserCreateDto {
const factory UserCreateDto({
required String name,
required String email,
required String password,
}) = _UserCreateDto;
/// JSON-Serialisierung
factory UserCreateDto.fromJson(Map<String, dynamic> json) =>
_$UserCreateDtoFromJson(json);
}
@freezed
class UserUpdateDto with _$UserUpdateDto {
const factory UserUpdateDto({
String? name,
String? email,
String? password,
}) = _UserUpdateDto;
/// JSON-Serialisierung
factory UserUpdateDto.fromJson(Map<String, dynamic> json) =>
_$UserUpdateDtoFromJson(json);
}
@@ -20,10 +20,9 @@ UserDto _$UserDtoFromJson(Map<String, dynamic> json) {
/// @nodoc
mixin _$UserDto {
String? get id => throw _privateConstructorUsedError;
String? get name => throw _privateConstructorUsedError;
String? get email => throw _privateConstructorUsedError;
String? get password => throw _privateConstructorUsedError;
String get id => throw _privateConstructorUsedError;
String get name => throw _privateConstructorUsedError;
String get email => throw _privateConstructorUsedError;
DateTime? get createdAt => throw _privateConstructorUsedError;
DateTime? get updatedAt => throw _privateConstructorUsedError;
@@ -42,10 +41,9 @@ abstract class $UserDtoCopyWith<$Res> {
_$UserDtoCopyWithImpl<$Res, UserDto>;
@useResult
$Res call(
{String? id,
String? name,
String? email,
String? password,
{String id,
String name,
String email,
DateTime? createdAt,
DateTime? updatedAt});
}
@@ -65,30 +63,25 @@ class _$UserDtoCopyWithImpl<$Res, $Val extends UserDto>
@pragma('vm:prefer-inline')
@override
$Res call({
Object? id = freezed,
Object? name = freezed,
Object? email = freezed,
Object? password = freezed,
Object? id = null,
Object? name = null,
Object? email = null,
Object? createdAt = freezed,
Object? updatedAt = freezed,
}) {
return _then(_value.copyWith(
id: freezed == id
id: null == id
? _value.id
: id // ignore: cast_nullable_to_non_nullable
as String?,
name: freezed == name
as String,
name: null == name
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String?,
email: freezed == email
as String,
email: null == email
? _value.email
: email // ignore: cast_nullable_to_non_nullable
as String?,
password: freezed == password
? _value.password
: password // ignore: cast_nullable_to_non_nullable
as String?,
as String,
createdAt: freezed == createdAt
? _value.createdAt
: createdAt // ignore: cast_nullable_to_non_nullable
@@ -109,10 +102,9 @@ abstract class _$$UserDtoImplCopyWith<$Res> implements $UserDtoCopyWith<$Res> {
@override
@useResult
$Res call(
{String? id,
String? name,
String? email,
String? password,
{String id,
String name,
String email,
DateTime? createdAt,
DateTime? updatedAt});
}
@@ -130,30 +122,25 @@ class __$$UserDtoImplCopyWithImpl<$Res>
@pragma('vm:prefer-inline')
@override
$Res call({
Object? id = freezed,
Object? name = freezed,
Object? email = freezed,
Object? password = freezed,
Object? id = null,
Object? name = null,
Object? email = null,
Object? createdAt = freezed,
Object? updatedAt = freezed,
}) {
return _then(_$UserDtoImpl(
id: freezed == id
id: null == id
? _value.id
: id // ignore: cast_nullable_to_non_nullable
as String?,
name: freezed == name
as String,
name: null == name
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String?,
email: freezed == email
as String,
email: null == email
? _value.email
: email // ignore: cast_nullable_to_non_nullable
as String?,
password: freezed == password
? _value.password
: password // ignore: cast_nullable_to_non_nullable
as String?,
as String,
createdAt: freezed == createdAt
? _value.createdAt
: createdAt // ignore: cast_nullable_to_non_nullable
@@ -170,10 +157,9 @@ class __$$UserDtoImplCopyWithImpl<$Res>
@JsonSerializable()
class _$UserDtoImpl implements _UserDto {
const _$UserDtoImpl(
{this.id,
this.name,
this.email,
this.password,
{required this.id,
required this.name,
required this.email,
this.createdAt,
this.updatedAt});
@@ -181,13 +167,11 @@ class _$UserDtoImpl implements _UserDto {
_$$UserDtoImplFromJson(json);
@override
final String? id;
final String id;
@override
final String? name;
final String name;
@override
final String? email;
@override
final String? password;
final String email;
@override
final DateTime? createdAt;
@override
@@ -195,7 +179,7 @@ class _$UserDtoImpl implements _UserDto {
@override
String toString() {
return 'UserDto(id: $id, name: $name, email: $email, password: $password, createdAt: $createdAt, updatedAt: $updatedAt)';
return 'UserDto(id: $id, name: $name, email: $email, createdAt: $createdAt, updatedAt: $updatedAt)';
}
@override
@@ -206,8 +190,6 @@ class _$UserDtoImpl implements _UserDto {
(identical(other.id, id) || other.id == id) &&
(identical(other.name, name) || other.name == name) &&
(identical(other.email, email) || other.email == email) &&
(identical(other.password, password) ||
other.password == password) &&
(identical(other.createdAt, createdAt) ||
other.createdAt == createdAt) &&
(identical(other.updatedAt, updatedAt) ||
@@ -217,7 +199,7 @@ class _$UserDtoImpl implements _UserDto {
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode =>
Object.hash(runtimeType, id, name, email, password, createdAt, updatedAt);
Object.hash(runtimeType, id, name, email, createdAt, updatedAt);
/// Create a copy of UserDto
/// with the given fields replaced by the non-null parameter values.
@@ -237,23 +219,20 @@ class _$UserDtoImpl implements _UserDto {
abstract class _UserDto implements UserDto {
const factory _UserDto(
{final String? id,
final String? name,
final String? email,
final String? password,
{required final String id,
required final String name,
required final String email,
final DateTime? createdAt,
final DateTime? updatedAt}) = _$UserDtoImpl;
factory _UserDto.fromJson(Map<String, dynamic> json) = _$UserDtoImpl.fromJson;
@override
String? get id;
String get id;
@override
String? get name;
String get name;
@override
String? get email;
@override
String? get password;
String get email;
@override
DateTime? get createdAt;
@override
@@ -266,3 +245,374 @@ abstract class _UserDto implements UserDto {
_$$UserDtoImplCopyWith<_$UserDtoImpl> get copyWith =>
throw _privateConstructorUsedError;
}
UserCreateDto _$UserCreateDtoFromJson(Map<String, dynamic> json) {
return _UserCreateDto.fromJson(json);
}
/// @nodoc
mixin _$UserCreateDto {
String get name => throw _privateConstructorUsedError;
String get email => throw _privateConstructorUsedError;
String get password => throw _privateConstructorUsedError;
/// Serializes this UserCreateDto to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
/// Create a copy of UserCreateDto
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$UserCreateDtoCopyWith<UserCreateDto> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $UserCreateDtoCopyWith<$Res> {
factory $UserCreateDtoCopyWith(
UserCreateDto value, $Res Function(UserCreateDto) then) =
_$UserCreateDtoCopyWithImpl<$Res, UserCreateDto>;
@useResult
$Res call({String name, String email, String password});
}
/// @nodoc
class _$UserCreateDtoCopyWithImpl<$Res, $Val extends UserCreateDto>
implements $UserCreateDtoCopyWith<$Res> {
_$UserCreateDtoCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of UserCreateDto
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? name = null,
Object? email = null,
Object? password = null,
}) {
return _then(_value.copyWith(
name: null == name
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String,
email: null == email
? _value.email
: email // ignore: cast_nullable_to_non_nullable
as String,
password: null == password
? _value.password
: password // ignore: cast_nullable_to_non_nullable
as String,
) as $Val);
}
}
/// @nodoc
abstract class _$$UserCreateDtoImplCopyWith<$Res>
implements $UserCreateDtoCopyWith<$Res> {
factory _$$UserCreateDtoImplCopyWith(
_$UserCreateDtoImpl value, $Res Function(_$UserCreateDtoImpl) then) =
__$$UserCreateDtoImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({String name, String email, String password});
}
/// @nodoc
class __$$UserCreateDtoImplCopyWithImpl<$Res>
extends _$UserCreateDtoCopyWithImpl<$Res, _$UserCreateDtoImpl>
implements _$$UserCreateDtoImplCopyWith<$Res> {
__$$UserCreateDtoImplCopyWithImpl(
_$UserCreateDtoImpl _value, $Res Function(_$UserCreateDtoImpl) _then)
: super(_value, _then);
/// Create a copy of UserCreateDto
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? name = null,
Object? email = null,
Object? password = null,
}) {
return _then(_$UserCreateDtoImpl(
name: null == name
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String,
email: null == email
? _value.email
: email // ignore: cast_nullable_to_non_nullable
as String,
password: null == password
? _value.password
: password // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// @nodoc
@JsonSerializable()
class _$UserCreateDtoImpl implements _UserCreateDto {
const _$UserCreateDtoImpl(
{required this.name, required this.email, required this.password});
factory _$UserCreateDtoImpl.fromJson(Map<String, dynamic> json) =>
_$$UserCreateDtoImplFromJson(json);
@override
final String name;
@override
final String email;
@override
final String password;
@override
String toString() {
return 'UserCreateDto(name: $name, email: $email, password: $password)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$UserCreateDtoImpl &&
(identical(other.name, name) || other.name == name) &&
(identical(other.email, email) || other.email == email) &&
(identical(other.password, password) ||
other.password == password));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType, name, email, password);
/// Create a copy of UserCreateDto
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$UserCreateDtoImplCopyWith<_$UserCreateDtoImpl> get copyWith =>
__$$UserCreateDtoImplCopyWithImpl<_$UserCreateDtoImpl>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$$UserCreateDtoImplToJson(
this,
);
}
}
abstract class _UserCreateDto implements UserCreateDto {
const factory _UserCreateDto(
{required final String name,
required final String email,
required final String password}) = _$UserCreateDtoImpl;
factory _UserCreateDto.fromJson(Map<String, dynamic> json) =
_$UserCreateDtoImpl.fromJson;
@override
String get name;
@override
String get email;
@override
String get password;
/// Create a copy of UserCreateDto
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$UserCreateDtoImplCopyWith<_$UserCreateDtoImpl> get copyWith =>
throw _privateConstructorUsedError;
}
UserUpdateDto _$UserUpdateDtoFromJson(Map<String, dynamic> json) {
return _UserUpdateDto.fromJson(json);
}
/// @nodoc
mixin _$UserUpdateDto {
String? get name => throw _privateConstructorUsedError;
String? get email => throw _privateConstructorUsedError;
String? get password => throw _privateConstructorUsedError;
/// Serializes this UserUpdateDto to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
/// Create a copy of UserUpdateDto
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$UserUpdateDtoCopyWith<UserUpdateDto> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $UserUpdateDtoCopyWith<$Res> {
factory $UserUpdateDtoCopyWith(
UserUpdateDto value, $Res Function(UserUpdateDto) then) =
_$UserUpdateDtoCopyWithImpl<$Res, UserUpdateDto>;
@useResult
$Res call({String? name, String? email, String? password});
}
/// @nodoc
class _$UserUpdateDtoCopyWithImpl<$Res, $Val extends UserUpdateDto>
implements $UserUpdateDtoCopyWith<$Res> {
_$UserUpdateDtoCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of UserUpdateDto
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? name = freezed,
Object? email = freezed,
Object? password = freezed,
}) {
return _then(_value.copyWith(
name: freezed == name
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String?,
email: freezed == email
? _value.email
: email // ignore: cast_nullable_to_non_nullable
as String?,
password: freezed == password
? _value.password
: password // ignore: cast_nullable_to_non_nullable
as String?,
) as $Val);
}
}
/// @nodoc
abstract class _$$UserUpdateDtoImplCopyWith<$Res>
implements $UserUpdateDtoCopyWith<$Res> {
factory _$$UserUpdateDtoImplCopyWith(
_$UserUpdateDtoImpl value, $Res Function(_$UserUpdateDtoImpl) then) =
__$$UserUpdateDtoImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({String? name, String? email, String? password});
}
/// @nodoc
class __$$UserUpdateDtoImplCopyWithImpl<$Res>
extends _$UserUpdateDtoCopyWithImpl<$Res, _$UserUpdateDtoImpl>
implements _$$UserUpdateDtoImplCopyWith<$Res> {
__$$UserUpdateDtoImplCopyWithImpl(
_$UserUpdateDtoImpl _value, $Res Function(_$UserUpdateDtoImpl) _then)
: super(_value, _then);
/// Create a copy of UserUpdateDto
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? name = freezed,
Object? email = freezed,
Object? password = freezed,
}) {
return _then(_$UserUpdateDtoImpl(
name: freezed == name
? _value.name
: name // ignore: cast_nullable_to_non_nullable
as String?,
email: freezed == email
? _value.email
: email // ignore: cast_nullable_to_non_nullable
as String?,
password: freezed == password
? _value.password
: password // ignore: cast_nullable_to_non_nullable
as String?,
));
}
}
/// @nodoc
@JsonSerializable()
class _$UserUpdateDtoImpl implements _UserUpdateDto {
const _$UserUpdateDtoImpl({this.name, this.email, this.password});
factory _$UserUpdateDtoImpl.fromJson(Map<String, dynamic> json) =>
_$$UserUpdateDtoImplFromJson(json);
@override
final String? name;
@override
final String? email;
@override
final String? password;
@override
String toString() {
return 'UserUpdateDto(name: $name, email: $email, password: $password)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$UserUpdateDtoImpl &&
(identical(other.name, name) || other.name == name) &&
(identical(other.email, email) || other.email == email) &&
(identical(other.password, password) ||
other.password == password));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType, name, email, password);
/// Create a copy of UserUpdateDto
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$UserUpdateDtoImplCopyWith<_$UserUpdateDtoImpl> get copyWith =>
__$$UserUpdateDtoImplCopyWithImpl<_$UserUpdateDtoImpl>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$$UserUpdateDtoImplToJson(
this,
);
}
}
abstract class _UserUpdateDto implements UserUpdateDto {
const factory _UserUpdateDto(
{final String? name,
final String? email,
final String? password}) = _$UserUpdateDtoImpl;
factory _UserUpdateDto.fromJson(Map<String, dynamic> json) =
_$UserUpdateDtoImpl.fromJson;
@override
String? get name;
@override
String? get email;
@override
String? get password;
/// Create a copy of UserUpdateDto
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$UserUpdateDtoImplCopyWith<_$UserUpdateDtoImpl> get copyWith =>
throw _privateConstructorUsedError;
}
@@ -8,10 +8,9 @@ part of 'user_dto.dart';
_$UserDtoImpl _$$UserDtoImplFromJson(Map<String, dynamic> json) =>
_$UserDtoImpl(
id: json['id'] as String?,
name: json['name'] as String?,
email: json['email'] as String?,
password: json['password'] as String?,
id: json['id'] as String,
name: json['name'] as String,
email: json['email'] as String,
createdAt: json['createdAt'] == null
? null
: DateTime.parse(json['createdAt'] as String),
@@ -25,7 +24,34 @@ Map<String, dynamic> _$$UserDtoImplToJson(_$UserDtoImpl instance) =>
'id': instance.id,
'name': instance.name,
'email': instance.email,
'password': instance.password,
'createdAt': instance.createdAt?.toIso8601String(),
'updatedAt': instance.updatedAt?.toIso8601String(),
};
_$UserCreateDtoImpl _$$UserCreateDtoImplFromJson(Map<String, dynamic> json) =>
_$UserCreateDtoImpl(
name: json['name'] as String,
email: json['email'] as String,
password: json['password'] as String,
);
Map<String, dynamic> _$$UserCreateDtoImplToJson(_$UserCreateDtoImpl instance) =>
<String, dynamic>{
'name': instance.name,
'email': instance.email,
'password': instance.password,
};
_$UserUpdateDtoImpl _$$UserUpdateDtoImplFromJson(Map<String, dynamic> json) =>
_$UserUpdateDtoImpl(
name: json['name'] as String?,
email: json['email'] as String?,
password: json['password'] as String?,
);
Map<String, dynamic> _$$UserUpdateDtoImplToJson(_$UserUpdateDtoImpl instance) =>
<String, dynamic>{
'name': instance.name,
'email': instance.email,
'password': instance.password,
};