Game Prize and Logout
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:data_channel/data_channel.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
|
||||
import '../../../common/api/api_client.dart';
|
||||
import '../../../common/api/api_failure.dart';
|
||||
import '../../../common/function/app_function.dart';
|
||||
import '../../../common/url/api_path.dart';
|
||||
import '../../../domain/game/game.dart';
|
||||
import '../game_dtos.dart';
|
||||
|
||||
@injectable
|
||||
class GameRemoteDataProvider {
|
||||
final ApiClient _apiClient;
|
||||
final String _logName = "GameRemoteDataProvider";
|
||||
|
||||
GameRemoteDataProvider(this._apiClient);
|
||||
|
||||
Future<DC<GameFailure, List<GamePrizeDto>>> gamePrizeByGameId({
|
||||
required String id,
|
||||
}) async {
|
||||
try {
|
||||
final response = await _apiClient.get(
|
||||
'${ApiPath.gamePrizeByGameId}/$id',
|
||||
headers: getAuthorizationHeader(),
|
||||
);
|
||||
|
||||
if (response.data['code'] == 401) {
|
||||
return DC.error(
|
||||
GameFailure.serverError(ApiFailure.unauthorized('Session Expired')),
|
||||
);
|
||||
}
|
||||
|
||||
if (response.data['status'] == false) {
|
||||
return DC.error(
|
||||
GameFailure.dynamicErrorMessage('Terjadi kesalahan coba lagi nanti'),
|
||||
);
|
||||
}
|
||||
|
||||
final dto = (response.data['data'] as List)
|
||||
.map((e) => GamePrizeDto.fromJson(e))
|
||||
.toList();
|
||||
return DC.data(dto);
|
||||
} on ApiFailure catch (e, s) {
|
||||
log('gamePrizeByGameId', name: _logName, error: e, stackTrace: s);
|
||||
return DC.error(GameFailure.serverError(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
part of '../game_dtos.dart';
|
||||
|
||||
@freezed
|
||||
class GameDto with _$GameDto {
|
||||
const factory GameDto({
|
||||
@JsonKey(name: 'id') String? id,
|
||||
@JsonKey(name: 'name') String? name,
|
||||
@JsonKey(name: 'type') String? type,
|
||||
@JsonKey(name: 'is_active') bool? isActive,
|
||||
@JsonKey(name: 'metadata') Map<String, dynamic>? metadata,
|
||||
@JsonKey(name: 'created_at') String? createdAt,
|
||||
@JsonKey(name: 'updated_at') String? updatedAt,
|
||||
}) = _GameDto;
|
||||
|
||||
factory GameDto.fromJson(Map<String, dynamic> json) =>
|
||||
_$GameDtoFromJson(json);
|
||||
|
||||
const GameDto._();
|
||||
|
||||
Game toDomain() => Game(
|
||||
id: id ?? '',
|
||||
name: name ?? '',
|
||||
type: type ?? '',
|
||||
isActive: isActive ?? false,
|
||||
metadata: metadata ?? const {},
|
||||
createdAt: createdAt ?? '',
|
||||
updatedAt: updatedAt ?? '',
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
part of '../game_dtos.dart';
|
||||
|
||||
@freezed
|
||||
class GamePrizeDto with _$GamePrizeDto {
|
||||
const factory GamePrizeDto({
|
||||
@JsonKey(name: 'id') String? id,
|
||||
@JsonKey(name: 'game_id') String? gameId,
|
||||
@JsonKey(name: 'name') String? name,
|
||||
@JsonKey(name: 'weight') int? weight,
|
||||
@JsonKey(name: 'stock') int? stock,
|
||||
@JsonKey(name: 'max_stock') int? maxStock,
|
||||
@JsonKey(name: 'threshold') int? threshold,
|
||||
@JsonKey(name: 'metadata') Map<String, dynamic>? metadata,
|
||||
@JsonKey(name: 'game') GameDto? game,
|
||||
@JsonKey(name: 'created_at') String? createdAt,
|
||||
@JsonKey(name: 'updated_at') String? updatedAt,
|
||||
}) = _GamePrizeDto;
|
||||
|
||||
factory GamePrizeDto.fromJson(Map<String, dynamic> json) =>
|
||||
_$GamePrizeDtoFromJson(json);
|
||||
|
||||
const GamePrizeDto._();
|
||||
|
||||
/// mapping ke domain
|
||||
GamePrize toDomain() => GamePrize(
|
||||
id: id ?? '',
|
||||
gameId: gameId ?? '',
|
||||
name: name ?? '',
|
||||
weight: weight ?? 0,
|
||||
stock: stock ?? 0,
|
||||
maxStock: maxStock ?? 0,
|
||||
threshold: threshold ?? 0,
|
||||
metadata: metadata ?? const {},
|
||||
game: game?.toDomain() ?? Game.empty(),
|
||||
createdAt: createdAt ?? '',
|
||||
updatedAt: updatedAt ?? '',
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
import '../../domain/game/game.dart';
|
||||
|
||||
part 'game_dtos.freezed.dart';
|
||||
part 'game_dtos.g.dart';
|
||||
|
||||
part 'dto/game_dto.dart';
|
||||
part 'dto/game_prize_dto.dart';
|
||||
@@ -0,0 +1,779 @@
|
||||
// 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 'game_dtos.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',
|
||||
);
|
||||
|
||||
GameDto _$GameDtoFromJson(Map<String, dynamic> json) {
|
||||
return _GameDto.fromJson(json);
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$GameDto {
|
||||
@JsonKey(name: 'id')
|
||||
String? get id => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: 'name')
|
||||
String? get name => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: 'type')
|
||||
String? get type => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: 'is_active')
|
||||
bool? get isActive => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: 'metadata')
|
||||
Map<String, dynamic>? get metadata => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: 'created_at')
|
||||
String? get createdAt => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: 'updated_at')
|
||||
String? get updatedAt => throw _privateConstructorUsedError;
|
||||
|
||||
/// Serializes this GameDto to a JSON map.
|
||||
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
|
||||
|
||||
/// Create a copy of GameDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
$GameDtoCopyWith<GameDto> get copyWith => throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $GameDtoCopyWith<$Res> {
|
||||
factory $GameDtoCopyWith(GameDto value, $Res Function(GameDto) then) =
|
||||
_$GameDtoCopyWithImpl<$Res, GameDto>;
|
||||
@useResult
|
||||
$Res call({
|
||||
@JsonKey(name: 'id') String? id,
|
||||
@JsonKey(name: 'name') String? name,
|
||||
@JsonKey(name: 'type') String? type,
|
||||
@JsonKey(name: 'is_active') bool? isActive,
|
||||
@JsonKey(name: 'metadata') Map<String, dynamic>? metadata,
|
||||
@JsonKey(name: 'created_at') String? createdAt,
|
||||
@JsonKey(name: 'updated_at') String? updatedAt,
|
||||
});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$GameDtoCopyWithImpl<$Res, $Val extends GameDto>
|
||||
implements $GameDtoCopyWith<$Res> {
|
||||
_$GameDtoCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
/// Create a copy of GameDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? id = freezed,
|
||||
Object? name = freezed,
|
||||
Object? type = freezed,
|
||||
Object? isActive = freezed,
|
||||
Object? metadata = freezed,
|
||||
Object? createdAt = freezed,
|
||||
Object? updatedAt = freezed,
|
||||
}) {
|
||||
return _then(
|
||||
_value.copyWith(
|
||||
id: freezed == id
|
||||
? _value.id
|
||||
: id // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
name: freezed == name
|
||||
? _value.name
|
||||
: name // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
type: freezed == type
|
||||
? _value.type
|
||||
: type // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
isActive: freezed == isActive
|
||||
? _value.isActive
|
||||
: isActive // ignore: cast_nullable_to_non_nullable
|
||||
as bool?,
|
||||
metadata: freezed == metadata
|
||||
? _value.metadata
|
||||
: metadata // ignore: cast_nullable_to_non_nullable
|
||||
as Map<String, dynamic>?,
|
||||
createdAt: freezed == createdAt
|
||||
? _value.createdAt
|
||||
: createdAt // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
updatedAt: freezed == updatedAt
|
||||
? _value.updatedAt
|
||||
: updatedAt // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
)
|
||||
as $Val,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$GameDtoImplCopyWith<$Res> implements $GameDtoCopyWith<$Res> {
|
||||
factory _$$GameDtoImplCopyWith(
|
||||
_$GameDtoImpl value,
|
||||
$Res Function(_$GameDtoImpl) then,
|
||||
) = __$$GameDtoImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({
|
||||
@JsonKey(name: 'id') String? id,
|
||||
@JsonKey(name: 'name') String? name,
|
||||
@JsonKey(name: 'type') String? type,
|
||||
@JsonKey(name: 'is_active') bool? isActive,
|
||||
@JsonKey(name: 'metadata') Map<String, dynamic>? metadata,
|
||||
@JsonKey(name: 'created_at') String? createdAt,
|
||||
@JsonKey(name: 'updated_at') String? updatedAt,
|
||||
});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$GameDtoImplCopyWithImpl<$Res>
|
||||
extends _$GameDtoCopyWithImpl<$Res, _$GameDtoImpl>
|
||||
implements _$$GameDtoImplCopyWith<$Res> {
|
||||
__$$GameDtoImplCopyWithImpl(
|
||||
_$GameDtoImpl _value,
|
||||
$Res Function(_$GameDtoImpl) _then,
|
||||
) : super(_value, _then);
|
||||
|
||||
/// Create a copy of GameDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? id = freezed,
|
||||
Object? name = freezed,
|
||||
Object? type = freezed,
|
||||
Object? isActive = freezed,
|
||||
Object? metadata = freezed,
|
||||
Object? createdAt = freezed,
|
||||
Object? updatedAt = freezed,
|
||||
}) {
|
||||
return _then(
|
||||
_$GameDtoImpl(
|
||||
id: freezed == id
|
||||
? _value.id
|
||||
: id // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
name: freezed == name
|
||||
? _value.name
|
||||
: name // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
type: freezed == type
|
||||
? _value.type
|
||||
: type // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
isActive: freezed == isActive
|
||||
? _value.isActive
|
||||
: isActive // ignore: cast_nullable_to_non_nullable
|
||||
as bool?,
|
||||
metadata: freezed == metadata
|
||||
? _value._metadata
|
||||
: metadata // ignore: cast_nullable_to_non_nullable
|
||||
as Map<String, dynamic>?,
|
||||
createdAt: freezed == createdAt
|
||||
? _value.createdAt
|
||||
: createdAt // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
updatedAt: freezed == updatedAt
|
||||
? _value.updatedAt
|
||||
: updatedAt // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
class _$GameDtoImpl extends _GameDto {
|
||||
const _$GameDtoImpl({
|
||||
@JsonKey(name: 'id') this.id,
|
||||
@JsonKey(name: 'name') this.name,
|
||||
@JsonKey(name: 'type') this.type,
|
||||
@JsonKey(name: 'is_active') this.isActive,
|
||||
@JsonKey(name: 'metadata') final Map<String, dynamic>? metadata,
|
||||
@JsonKey(name: 'created_at') this.createdAt,
|
||||
@JsonKey(name: 'updated_at') this.updatedAt,
|
||||
}) : _metadata = metadata,
|
||||
super._();
|
||||
|
||||
factory _$GameDtoImpl.fromJson(Map<String, dynamic> json) =>
|
||||
_$$GameDtoImplFromJson(json);
|
||||
|
||||
@override
|
||||
@JsonKey(name: 'id')
|
||||
final String? id;
|
||||
@override
|
||||
@JsonKey(name: 'name')
|
||||
final String? name;
|
||||
@override
|
||||
@JsonKey(name: 'type')
|
||||
final String? type;
|
||||
@override
|
||||
@JsonKey(name: 'is_active')
|
||||
final bool? isActive;
|
||||
final Map<String, dynamic>? _metadata;
|
||||
@override
|
||||
@JsonKey(name: 'metadata')
|
||||
Map<String, dynamic>? get metadata {
|
||||
final value = _metadata;
|
||||
if (value == null) return null;
|
||||
if (_metadata is EqualUnmodifiableMapView) return _metadata;
|
||||
// ignore: implicit_dynamic_type
|
||||
return EqualUnmodifiableMapView(value);
|
||||
}
|
||||
|
||||
@override
|
||||
@JsonKey(name: 'created_at')
|
||||
final String? createdAt;
|
||||
@override
|
||||
@JsonKey(name: 'updated_at')
|
||||
final String? updatedAt;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'GameDto(id: $id, name: $name, type: $type, isActive: $isActive, metadata: $metadata, createdAt: $createdAt, updatedAt: $updatedAt)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$GameDtoImpl &&
|
||||
(identical(other.id, id) || other.id == id) &&
|
||||
(identical(other.name, name) || other.name == name) &&
|
||||
(identical(other.type, type) || other.type == type) &&
|
||||
(identical(other.isActive, isActive) ||
|
||||
other.isActive == isActive) &&
|
||||
const DeepCollectionEquality().equals(other._metadata, _metadata) &&
|
||||
(identical(other.createdAt, createdAt) ||
|
||||
other.createdAt == createdAt) &&
|
||||
(identical(other.updatedAt, updatedAt) ||
|
||||
other.updatedAt == updatedAt));
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
int get hashCode => Object.hash(
|
||||
runtimeType,
|
||||
id,
|
||||
name,
|
||||
type,
|
||||
isActive,
|
||||
const DeepCollectionEquality().hash(_metadata),
|
||||
createdAt,
|
||||
updatedAt,
|
||||
);
|
||||
|
||||
/// Create a copy of GameDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$GameDtoImplCopyWith<_$GameDtoImpl> get copyWith =>
|
||||
__$$GameDtoImplCopyWithImpl<_$GameDtoImpl>(this, _$identity);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$$GameDtoImplToJson(this);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _GameDto extends GameDto {
|
||||
const factory _GameDto({
|
||||
@JsonKey(name: 'id') final String? id,
|
||||
@JsonKey(name: 'name') final String? name,
|
||||
@JsonKey(name: 'type') final String? type,
|
||||
@JsonKey(name: 'is_active') final bool? isActive,
|
||||
@JsonKey(name: 'metadata') final Map<String, dynamic>? metadata,
|
||||
@JsonKey(name: 'created_at') final String? createdAt,
|
||||
@JsonKey(name: 'updated_at') final String? updatedAt,
|
||||
}) = _$GameDtoImpl;
|
||||
const _GameDto._() : super._();
|
||||
|
||||
factory _GameDto.fromJson(Map<String, dynamic> json) = _$GameDtoImpl.fromJson;
|
||||
|
||||
@override
|
||||
@JsonKey(name: 'id')
|
||||
String? get id;
|
||||
@override
|
||||
@JsonKey(name: 'name')
|
||||
String? get name;
|
||||
@override
|
||||
@JsonKey(name: 'type')
|
||||
String? get type;
|
||||
@override
|
||||
@JsonKey(name: 'is_active')
|
||||
bool? get isActive;
|
||||
@override
|
||||
@JsonKey(name: 'metadata')
|
||||
Map<String, dynamic>? get metadata;
|
||||
@override
|
||||
@JsonKey(name: 'created_at')
|
||||
String? get createdAt;
|
||||
@override
|
||||
@JsonKey(name: 'updated_at')
|
||||
String? get updatedAt;
|
||||
|
||||
/// Create a copy of GameDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
_$$GameDtoImplCopyWith<_$GameDtoImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
GamePrizeDto _$GamePrizeDtoFromJson(Map<String, dynamic> json) {
|
||||
return _GamePrizeDto.fromJson(json);
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$GamePrizeDto {
|
||||
@JsonKey(name: 'id')
|
||||
String? get id => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: 'game_id')
|
||||
String? get gameId => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: 'name')
|
||||
String? get name => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: 'weight')
|
||||
int? get weight => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: 'stock')
|
||||
int? get stock => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: 'max_stock')
|
||||
int? get maxStock => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: 'threshold')
|
||||
int? get threshold => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: 'metadata')
|
||||
Map<String, dynamic>? get metadata => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: 'game')
|
||||
GameDto? get game => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: 'created_at')
|
||||
String? get createdAt => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: 'updated_at')
|
||||
String? get updatedAt => throw _privateConstructorUsedError;
|
||||
|
||||
/// Serializes this GamePrizeDto to a JSON map.
|
||||
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
|
||||
|
||||
/// Create a copy of GamePrizeDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
$GamePrizeDtoCopyWith<GamePrizeDto> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $GamePrizeDtoCopyWith<$Res> {
|
||||
factory $GamePrizeDtoCopyWith(
|
||||
GamePrizeDto value,
|
||||
$Res Function(GamePrizeDto) then,
|
||||
) = _$GamePrizeDtoCopyWithImpl<$Res, GamePrizeDto>;
|
||||
@useResult
|
||||
$Res call({
|
||||
@JsonKey(name: 'id') String? id,
|
||||
@JsonKey(name: 'game_id') String? gameId,
|
||||
@JsonKey(name: 'name') String? name,
|
||||
@JsonKey(name: 'weight') int? weight,
|
||||
@JsonKey(name: 'stock') int? stock,
|
||||
@JsonKey(name: 'max_stock') int? maxStock,
|
||||
@JsonKey(name: 'threshold') int? threshold,
|
||||
@JsonKey(name: 'metadata') Map<String, dynamic>? metadata,
|
||||
@JsonKey(name: 'game') GameDto? game,
|
||||
@JsonKey(name: 'created_at') String? createdAt,
|
||||
@JsonKey(name: 'updated_at') String? updatedAt,
|
||||
});
|
||||
|
||||
$GameDtoCopyWith<$Res>? get game;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$GamePrizeDtoCopyWithImpl<$Res, $Val extends GamePrizeDto>
|
||||
implements $GamePrizeDtoCopyWith<$Res> {
|
||||
_$GamePrizeDtoCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
/// Create a copy of GamePrizeDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? id = freezed,
|
||||
Object? gameId = freezed,
|
||||
Object? name = freezed,
|
||||
Object? weight = freezed,
|
||||
Object? stock = freezed,
|
||||
Object? maxStock = freezed,
|
||||
Object? threshold = freezed,
|
||||
Object? metadata = freezed,
|
||||
Object? game = freezed,
|
||||
Object? createdAt = freezed,
|
||||
Object? updatedAt = freezed,
|
||||
}) {
|
||||
return _then(
|
||||
_value.copyWith(
|
||||
id: freezed == id
|
||||
? _value.id
|
||||
: id // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
gameId: freezed == gameId
|
||||
? _value.gameId
|
||||
: gameId // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
name: freezed == name
|
||||
? _value.name
|
||||
: name // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
weight: freezed == weight
|
||||
? _value.weight
|
||||
: weight // ignore: cast_nullable_to_non_nullable
|
||||
as int?,
|
||||
stock: freezed == stock
|
||||
? _value.stock
|
||||
: stock // ignore: cast_nullable_to_non_nullable
|
||||
as int?,
|
||||
maxStock: freezed == maxStock
|
||||
? _value.maxStock
|
||||
: maxStock // ignore: cast_nullable_to_non_nullable
|
||||
as int?,
|
||||
threshold: freezed == threshold
|
||||
? _value.threshold
|
||||
: threshold // ignore: cast_nullable_to_non_nullable
|
||||
as int?,
|
||||
metadata: freezed == metadata
|
||||
? _value.metadata
|
||||
: metadata // ignore: cast_nullable_to_non_nullable
|
||||
as Map<String, dynamic>?,
|
||||
game: freezed == game
|
||||
? _value.game
|
||||
: game // ignore: cast_nullable_to_non_nullable
|
||||
as GameDto?,
|
||||
createdAt: freezed == createdAt
|
||||
? _value.createdAt
|
||||
: createdAt // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
updatedAt: freezed == updatedAt
|
||||
? _value.updatedAt
|
||||
: updatedAt // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
)
|
||||
as $Val,
|
||||
);
|
||||
}
|
||||
|
||||
/// Create a copy of GamePrizeDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$GameDtoCopyWith<$Res>? get game {
|
||||
if (_value.game == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $GameDtoCopyWith<$Res>(_value.game!, (value) {
|
||||
return _then(_value.copyWith(game: value) as $Val);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$GamePrizeDtoImplCopyWith<$Res>
|
||||
implements $GamePrizeDtoCopyWith<$Res> {
|
||||
factory _$$GamePrizeDtoImplCopyWith(
|
||||
_$GamePrizeDtoImpl value,
|
||||
$Res Function(_$GamePrizeDtoImpl) then,
|
||||
) = __$$GamePrizeDtoImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({
|
||||
@JsonKey(name: 'id') String? id,
|
||||
@JsonKey(name: 'game_id') String? gameId,
|
||||
@JsonKey(name: 'name') String? name,
|
||||
@JsonKey(name: 'weight') int? weight,
|
||||
@JsonKey(name: 'stock') int? stock,
|
||||
@JsonKey(name: 'max_stock') int? maxStock,
|
||||
@JsonKey(name: 'threshold') int? threshold,
|
||||
@JsonKey(name: 'metadata') Map<String, dynamic>? metadata,
|
||||
@JsonKey(name: 'game') GameDto? game,
|
||||
@JsonKey(name: 'created_at') String? createdAt,
|
||||
@JsonKey(name: 'updated_at') String? updatedAt,
|
||||
});
|
||||
|
||||
@override
|
||||
$GameDtoCopyWith<$Res>? get game;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$GamePrizeDtoImplCopyWithImpl<$Res>
|
||||
extends _$GamePrizeDtoCopyWithImpl<$Res, _$GamePrizeDtoImpl>
|
||||
implements _$$GamePrizeDtoImplCopyWith<$Res> {
|
||||
__$$GamePrizeDtoImplCopyWithImpl(
|
||||
_$GamePrizeDtoImpl _value,
|
||||
$Res Function(_$GamePrizeDtoImpl) _then,
|
||||
) : super(_value, _then);
|
||||
|
||||
/// Create a copy of GamePrizeDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? id = freezed,
|
||||
Object? gameId = freezed,
|
||||
Object? name = freezed,
|
||||
Object? weight = freezed,
|
||||
Object? stock = freezed,
|
||||
Object? maxStock = freezed,
|
||||
Object? threshold = freezed,
|
||||
Object? metadata = freezed,
|
||||
Object? game = freezed,
|
||||
Object? createdAt = freezed,
|
||||
Object? updatedAt = freezed,
|
||||
}) {
|
||||
return _then(
|
||||
_$GamePrizeDtoImpl(
|
||||
id: freezed == id
|
||||
? _value.id
|
||||
: id // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
gameId: freezed == gameId
|
||||
? _value.gameId
|
||||
: gameId // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
name: freezed == name
|
||||
? _value.name
|
||||
: name // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
weight: freezed == weight
|
||||
? _value.weight
|
||||
: weight // ignore: cast_nullable_to_non_nullable
|
||||
as int?,
|
||||
stock: freezed == stock
|
||||
? _value.stock
|
||||
: stock // ignore: cast_nullable_to_non_nullable
|
||||
as int?,
|
||||
maxStock: freezed == maxStock
|
||||
? _value.maxStock
|
||||
: maxStock // ignore: cast_nullable_to_non_nullable
|
||||
as int?,
|
||||
threshold: freezed == threshold
|
||||
? _value.threshold
|
||||
: threshold // ignore: cast_nullable_to_non_nullable
|
||||
as int?,
|
||||
metadata: freezed == metadata
|
||||
? _value._metadata
|
||||
: metadata // ignore: cast_nullable_to_non_nullable
|
||||
as Map<String, dynamic>?,
|
||||
game: freezed == game
|
||||
? _value.game
|
||||
: game // ignore: cast_nullable_to_non_nullable
|
||||
as GameDto?,
|
||||
createdAt: freezed == createdAt
|
||||
? _value.createdAt
|
||||
: createdAt // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
updatedAt: freezed == updatedAt
|
||||
? _value.updatedAt
|
||||
: updatedAt // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
class _$GamePrizeDtoImpl extends _GamePrizeDto {
|
||||
const _$GamePrizeDtoImpl({
|
||||
@JsonKey(name: 'id') this.id,
|
||||
@JsonKey(name: 'game_id') this.gameId,
|
||||
@JsonKey(name: 'name') this.name,
|
||||
@JsonKey(name: 'weight') this.weight,
|
||||
@JsonKey(name: 'stock') this.stock,
|
||||
@JsonKey(name: 'max_stock') this.maxStock,
|
||||
@JsonKey(name: 'threshold') this.threshold,
|
||||
@JsonKey(name: 'metadata') final Map<String, dynamic>? metadata,
|
||||
@JsonKey(name: 'game') this.game,
|
||||
@JsonKey(name: 'created_at') this.createdAt,
|
||||
@JsonKey(name: 'updated_at') this.updatedAt,
|
||||
}) : _metadata = metadata,
|
||||
super._();
|
||||
|
||||
factory _$GamePrizeDtoImpl.fromJson(Map<String, dynamic> json) =>
|
||||
_$$GamePrizeDtoImplFromJson(json);
|
||||
|
||||
@override
|
||||
@JsonKey(name: 'id')
|
||||
final String? id;
|
||||
@override
|
||||
@JsonKey(name: 'game_id')
|
||||
final String? gameId;
|
||||
@override
|
||||
@JsonKey(name: 'name')
|
||||
final String? name;
|
||||
@override
|
||||
@JsonKey(name: 'weight')
|
||||
final int? weight;
|
||||
@override
|
||||
@JsonKey(name: 'stock')
|
||||
final int? stock;
|
||||
@override
|
||||
@JsonKey(name: 'max_stock')
|
||||
final int? maxStock;
|
||||
@override
|
||||
@JsonKey(name: 'threshold')
|
||||
final int? threshold;
|
||||
final Map<String, dynamic>? _metadata;
|
||||
@override
|
||||
@JsonKey(name: 'metadata')
|
||||
Map<String, dynamic>? get metadata {
|
||||
final value = _metadata;
|
||||
if (value == null) return null;
|
||||
if (_metadata is EqualUnmodifiableMapView) return _metadata;
|
||||
// ignore: implicit_dynamic_type
|
||||
return EqualUnmodifiableMapView(value);
|
||||
}
|
||||
|
||||
@override
|
||||
@JsonKey(name: 'game')
|
||||
final GameDto? game;
|
||||
@override
|
||||
@JsonKey(name: 'created_at')
|
||||
final String? createdAt;
|
||||
@override
|
||||
@JsonKey(name: 'updated_at')
|
||||
final String? updatedAt;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'GamePrizeDto(id: $id, gameId: $gameId, name: $name, weight: $weight, stock: $stock, maxStock: $maxStock, threshold: $threshold, metadata: $metadata, game: $game, createdAt: $createdAt, updatedAt: $updatedAt)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$GamePrizeDtoImpl &&
|
||||
(identical(other.id, id) || other.id == id) &&
|
||||
(identical(other.gameId, gameId) || other.gameId == gameId) &&
|
||||
(identical(other.name, name) || other.name == name) &&
|
||||
(identical(other.weight, weight) || other.weight == weight) &&
|
||||
(identical(other.stock, stock) || other.stock == stock) &&
|
||||
(identical(other.maxStock, maxStock) ||
|
||||
other.maxStock == maxStock) &&
|
||||
(identical(other.threshold, threshold) ||
|
||||
other.threshold == threshold) &&
|
||||
const DeepCollectionEquality().equals(other._metadata, _metadata) &&
|
||||
(identical(other.game, game) || other.game == game) &&
|
||||
(identical(other.createdAt, createdAt) ||
|
||||
other.createdAt == createdAt) &&
|
||||
(identical(other.updatedAt, updatedAt) ||
|
||||
other.updatedAt == updatedAt));
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
int get hashCode => Object.hash(
|
||||
runtimeType,
|
||||
id,
|
||||
gameId,
|
||||
name,
|
||||
weight,
|
||||
stock,
|
||||
maxStock,
|
||||
threshold,
|
||||
const DeepCollectionEquality().hash(_metadata),
|
||||
game,
|
||||
createdAt,
|
||||
updatedAt,
|
||||
);
|
||||
|
||||
/// Create a copy of GamePrizeDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$GamePrizeDtoImplCopyWith<_$GamePrizeDtoImpl> get copyWith =>
|
||||
__$$GamePrizeDtoImplCopyWithImpl<_$GamePrizeDtoImpl>(this, _$identity);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$$GamePrizeDtoImplToJson(this);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _GamePrizeDto extends GamePrizeDto {
|
||||
const factory _GamePrizeDto({
|
||||
@JsonKey(name: 'id') final String? id,
|
||||
@JsonKey(name: 'game_id') final String? gameId,
|
||||
@JsonKey(name: 'name') final String? name,
|
||||
@JsonKey(name: 'weight') final int? weight,
|
||||
@JsonKey(name: 'stock') final int? stock,
|
||||
@JsonKey(name: 'max_stock') final int? maxStock,
|
||||
@JsonKey(name: 'threshold') final int? threshold,
|
||||
@JsonKey(name: 'metadata') final Map<String, dynamic>? metadata,
|
||||
@JsonKey(name: 'game') final GameDto? game,
|
||||
@JsonKey(name: 'created_at') final String? createdAt,
|
||||
@JsonKey(name: 'updated_at') final String? updatedAt,
|
||||
}) = _$GamePrizeDtoImpl;
|
||||
const _GamePrizeDto._() : super._();
|
||||
|
||||
factory _GamePrizeDto.fromJson(Map<String, dynamic> json) =
|
||||
_$GamePrizeDtoImpl.fromJson;
|
||||
|
||||
@override
|
||||
@JsonKey(name: 'id')
|
||||
String? get id;
|
||||
@override
|
||||
@JsonKey(name: 'game_id')
|
||||
String? get gameId;
|
||||
@override
|
||||
@JsonKey(name: 'name')
|
||||
String? get name;
|
||||
@override
|
||||
@JsonKey(name: 'weight')
|
||||
int? get weight;
|
||||
@override
|
||||
@JsonKey(name: 'stock')
|
||||
int? get stock;
|
||||
@override
|
||||
@JsonKey(name: 'max_stock')
|
||||
int? get maxStock;
|
||||
@override
|
||||
@JsonKey(name: 'threshold')
|
||||
int? get threshold;
|
||||
@override
|
||||
@JsonKey(name: 'metadata')
|
||||
Map<String, dynamic>? get metadata;
|
||||
@override
|
||||
@JsonKey(name: 'game')
|
||||
GameDto? get game;
|
||||
@override
|
||||
@JsonKey(name: 'created_at')
|
||||
String? get createdAt;
|
||||
@override
|
||||
@JsonKey(name: 'updated_at')
|
||||
String? get updatedAt;
|
||||
|
||||
/// Create a copy of GamePrizeDto
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
_$$GamePrizeDtoImplCopyWith<_$GamePrizeDtoImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'game_dtos.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
_$GameDtoImpl _$$GameDtoImplFromJson(Map<String, dynamic> json) =>
|
||||
_$GameDtoImpl(
|
||||
id: json['id'] as String?,
|
||||
name: json['name'] as String?,
|
||||
type: json['type'] as String?,
|
||||
isActive: json['is_active'] as bool?,
|
||||
metadata: json['metadata'] as Map<String, dynamic>?,
|
||||
createdAt: json['created_at'] as String?,
|
||||
updatedAt: json['updated_at'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$GameDtoImplToJson(_$GameDtoImpl instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'name': instance.name,
|
||||
'type': instance.type,
|
||||
'is_active': instance.isActive,
|
||||
'metadata': instance.metadata,
|
||||
'created_at': instance.createdAt,
|
||||
'updated_at': instance.updatedAt,
|
||||
};
|
||||
|
||||
_$GamePrizeDtoImpl _$$GamePrizeDtoImplFromJson(Map<String, dynamic> json) =>
|
||||
_$GamePrizeDtoImpl(
|
||||
id: json['id'] as String?,
|
||||
gameId: json['game_id'] as String?,
|
||||
name: json['name'] as String?,
|
||||
weight: (json['weight'] as num?)?.toInt(),
|
||||
stock: (json['stock'] as num?)?.toInt(),
|
||||
maxStock: (json['max_stock'] as num?)?.toInt(),
|
||||
threshold: (json['threshold'] as num?)?.toInt(),
|
||||
metadata: json['metadata'] as Map<String, dynamic>?,
|
||||
game: json['game'] == null
|
||||
? null
|
||||
: GameDto.fromJson(json['game'] as Map<String, dynamic>),
|
||||
createdAt: json['created_at'] as String?,
|
||||
updatedAt: json['updated_at'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$GamePrizeDtoImplToJson(_$GamePrizeDtoImpl instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'game_id': instance.gameId,
|
||||
'name': instance.name,
|
||||
'weight': instance.weight,
|
||||
'stock': instance.stock,
|
||||
'max_stock': instance.maxStock,
|
||||
'threshold': instance.threshold,
|
||||
'metadata': instance.metadata,
|
||||
'game': instance.game,
|
||||
'created_at': instance.createdAt,
|
||||
'updated_at': instance.updatedAt,
|
||||
};
|
||||
@@ -0,0 +1,36 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
|
||||
import '../../../domain/game/game.dart';
|
||||
import '../datasources/remote_data_provider.dart';
|
||||
|
||||
@Injectable(as: IGameRepository)
|
||||
class GameRepository implements IGameRepository {
|
||||
final GameRemoteDataProvider _remoteDataProvider;
|
||||
|
||||
final String _logName = 'GameRepository';
|
||||
|
||||
GameRepository(this._remoteDataProvider);
|
||||
|
||||
@override
|
||||
Future<Either<GameFailure, List<GamePrize>>> gamePrizeByGameId({
|
||||
required String id,
|
||||
}) async {
|
||||
try {
|
||||
final result = await _remoteDataProvider.gamePrizeByGameId(id: id);
|
||||
|
||||
if (result.hasError) {
|
||||
return left(result.error!);
|
||||
}
|
||||
|
||||
final data = result.data!.map((e) => e.toDomain()).toList();
|
||||
|
||||
return right(data);
|
||||
} catch (e, s) {
|
||||
log('gamePrizeByGameId', name: _logName, error: e, stackTrace: s);
|
||||
return left(const GameFailure.unexpectedError());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user