implemented user service (no auth!)

This commit is contained in:
2025-01-01 18:33:53 +00:00
parent 0ded723bb9
commit 8559b1c44e
34 changed files with 1437 additions and 158 deletions
@@ -0,0 +1,51 @@
import 'package:backend_dart/domain/interface/error.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'error_code.dart';
part 'app_error.freezed.dart';
@freezed
class AppError with _$AppError implements IError {
const factory AppError({
required ErrorCode code,
required String message,
Map<String, String>? details,
StackTrace? stackTrace,
Object? originalError,
}) = _AppError;
factory AppError.fromException(Exception e) {
return AppError(
code: ErrorCode.exception,
message: e.toString(),
originalError: e,
);
}
factory AppError.fromErrorCode(ErrorCode code, {String? message}) {
return AppError(
code: code,
message: message ?? "No message",
stackTrace: StackTrace.current);
}
factory AppError.notFound(String? message) {
return AppError.fromErrorCode(ErrorCode.notFound, message: message);
}
factory AppError.mappingError({String? message}) {
return AppError.fromErrorCode(ErrorCode.mappingError, message: message);
}
factory AppError.databaseError({String? message}) {
return AppError.fromErrorCode(ErrorCode.databaseError, message: message);
}
factory AppError.validationError({String? message}) {
return AppError.fromErrorCode(ErrorCode.validationError, message: message);
}
factory AppError.inputError({String? message}) {
return AppError.fromErrorCode(ErrorCode.inputError, message: message);
}
}
@@ -0,0 +1,239 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'app_error.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models');
/// @nodoc
mixin _$AppError {
ErrorCode get code => throw _privateConstructorUsedError;
String get message => throw _privateConstructorUsedError;
Map<String, String>? get details => throw _privateConstructorUsedError;
StackTrace? get stackTrace => throw _privateConstructorUsedError;
Object? get originalError => throw _privateConstructorUsedError;
/// Create a copy of AppError
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$AppErrorCopyWith<AppError> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $AppErrorCopyWith<$Res> {
factory $AppErrorCopyWith(AppError value, $Res Function(AppError) then) =
_$AppErrorCopyWithImpl<$Res, AppError>;
@useResult
$Res call(
{ErrorCode code,
String message,
Map<String, String>? details,
StackTrace? stackTrace,
Object? originalError});
}
/// @nodoc
class _$AppErrorCopyWithImpl<$Res, $Val extends AppError>
implements $AppErrorCopyWith<$Res> {
_$AppErrorCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of AppError
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? code = null,
Object? message = null,
Object? details = freezed,
Object? stackTrace = freezed,
Object? originalError = freezed,
}) {
return _then(_value.copyWith(
code: null == code
? _value.code
: code // ignore: cast_nullable_to_non_nullable
as ErrorCode,
message: null == message
? _value.message
: message // ignore: cast_nullable_to_non_nullable
as String,
details: freezed == details
? _value.details
: details // ignore: cast_nullable_to_non_nullable
as Map<String, String>?,
stackTrace: freezed == stackTrace
? _value.stackTrace
: stackTrace // ignore: cast_nullable_to_non_nullable
as StackTrace?,
originalError:
freezed == originalError ? _value.originalError : originalError,
) as $Val);
}
}
/// @nodoc
abstract class _$$AppErrorImplCopyWith<$Res>
implements $AppErrorCopyWith<$Res> {
factory _$$AppErrorImplCopyWith(
_$AppErrorImpl value, $Res Function(_$AppErrorImpl) then) =
__$$AppErrorImplCopyWithImpl<$Res>;
@override
@useResult
$Res call(
{ErrorCode code,
String message,
Map<String, String>? details,
StackTrace? stackTrace,
Object? originalError});
}
/// @nodoc
class __$$AppErrorImplCopyWithImpl<$Res>
extends _$AppErrorCopyWithImpl<$Res, _$AppErrorImpl>
implements _$$AppErrorImplCopyWith<$Res> {
__$$AppErrorImplCopyWithImpl(
_$AppErrorImpl _value, $Res Function(_$AppErrorImpl) _then)
: super(_value, _then);
/// Create a copy of AppError
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? code = null,
Object? message = null,
Object? details = freezed,
Object? stackTrace = freezed,
Object? originalError = freezed,
}) {
return _then(_$AppErrorImpl(
code: null == code
? _value.code
: code // ignore: cast_nullable_to_non_nullable
as ErrorCode,
message: null == message
? _value.message
: message // ignore: cast_nullable_to_non_nullable
as String,
details: freezed == details
? _value._details
: details // ignore: cast_nullable_to_non_nullable
as Map<String, String>?,
stackTrace: freezed == stackTrace
? _value.stackTrace
: stackTrace // ignore: cast_nullable_to_non_nullable
as StackTrace?,
originalError:
freezed == originalError ? _value.originalError : originalError,
));
}
}
/// @nodoc
class _$AppErrorImpl implements _AppError {
const _$AppErrorImpl(
{required this.code,
required this.message,
final Map<String, String>? details,
this.stackTrace,
this.originalError})
: _details = details;
@override
final ErrorCode code;
@override
final String message;
final Map<String, String>? _details;
@override
Map<String, String>? get details {
final value = _details;
if (value == null) return null;
if (_details is EqualUnmodifiableMapView) return _details;
// ignore: implicit_dynamic_type
return EqualUnmodifiableMapView(value);
}
@override
final StackTrace? stackTrace;
@override
final Object? originalError;
@override
String toString() {
return 'AppError(code: $code, message: $message, details: $details, stackTrace: $stackTrace, originalError: $originalError)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$AppErrorImpl &&
(identical(other.code, code) || other.code == code) &&
(identical(other.message, message) || other.message == message) &&
const DeepCollectionEquality().equals(other._details, _details) &&
(identical(other.stackTrace, stackTrace) ||
other.stackTrace == stackTrace) &&
const DeepCollectionEquality()
.equals(other.originalError, originalError));
}
@override
int get hashCode => Object.hash(
runtimeType,
code,
message,
const DeepCollectionEquality().hash(_details),
stackTrace,
const DeepCollectionEquality().hash(originalError));
/// Create a copy of AppError
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$AppErrorImplCopyWith<_$AppErrorImpl> get copyWith =>
__$$AppErrorImplCopyWithImpl<_$AppErrorImpl>(this, _$identity);
}
abstract class _AppError implements AppError {
const factory _AppError(
{required final ErrorCode code,
required final String message,
final Map<String, String>? details,
final StackTrace? stackTrace,
final Object? originalError}) = _$AppErrorImpl;
@override
ErrorCode get code;
@override
String get message;
@override
Map<String, String>? get details;
@override
StackTrace? get stackTrace;
@override
Object? get originalError;
/// Create a copy of AppError
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$AppErrorImplCopyWith<_$AppErrorImpl> get copyWith =>
throw _privateConstructorUsedError;
}
@@ -0,0 +1,15 @@
enum ErrorCode {
networkError, // Fehler bei der Netzwerkkommunikation
validationError, // Eingabevalidierungsfehler
unexpectedError, // Unerwarteter Fehler
authenticationError, // Authentifizierungsfehler
permissionDenied, // Berechtigungsfehler
notFound, // Ressource nicht gefunden
exception, // Ausnahme
mappingError, // Fehler beim Zuordnen von Daten
databaseError, // Datenbankfehler
inputError, // Eingabefehler
outputError, // Ausgabefehler
internalError, // Interner Fehler
unknownError, // Unbekannter Fehler
}