Game Prize and Logout

This commit is contained in:
efrilm
2025-09-18 10:39:54 +07:00
parent 006486bc2a
commit 3c596461c6
31 changed files with 4189 additions and 677 deletions
+29
View File
@@ -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 ?? '',
);
}