-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
[ Add, Edit ] adapted the localization process method to the SSE from…
… the server, aligned eerything for the mvp, exposed version 0.9.0
Showing
9 changed files
with
259 additions
and
110 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,100 @@ | ||
// ignore_for_file: public_member_api_docs, sort_constructors_first | ||
import 'dart:convert'; | ||
|
||
import 'package:equatable/equatable.dart'; | ||
|
||
typedef JsonContentMap = Map<String, dynamic>; | ||
|
||
class LocalizationOutput extends Equatable { | ||
enum LangSyncServerSSEType { info, warn, error, result } | ||
|
||
class LangSyncServerSSE extends Equatable { | ||
final String message; | ||
final LangSyncServerSSEType type; | ||
final int statusCode; | ||
final DateTime date; | ||
|
||
const LangSyncServerSSE({ | ||
required this.message, | ||
required this.type, | ||
required this.statusCode, | ||
required this.date, | ||
}); | ||
@override | ||
List<Object?> get props => [ | ||
message, | ||
type, | ||
statusCode, | ||
date, | ||
]; | ||
|
||
factory LangSyncServerSSE.fromJson(Map<String, dynamic> res) { | ||
final type = LangSyncServerSSEType.values.firstWhere( | ||
(element) => element.name == res['type'] as String, | ||
); | ||
|
||
if (type == LangSyncServerSSEType.result) { | ||
return LangSyncServerResultSSE.fromJson(res); | ||
} else { | ||
return LangSyncServerSSE( | ||
message: res['message'] as String, | ||
type: type, | ||
statusCode: res['statusCode'] as int, | ||
date: DateTime.parse(res['date'] as String), | ||
); | ||
} | ||
} | ||
} | ||
|
||
class LangSyncServerResultSSE extends LangSyncServerSSE { | ||
final String outputPartitionId; | ||
|
||
const LocalizationOutput({ | ||
const LangSyncServerResultSSE({ | ||
required this.outputPartitionId, | ||
required super.message, | ||
required super.type, | ||
required super.statusCode, | ||
required super.date, | ||
}); | ||
|
||
factory LocalizationOutput.fromJson(Map<String, dynamic> res) { | ||
return LocalizationOutput( | ||
outputPartitionId: res['partitionId'] as String, | ||
factory LangSyncServerResultSSE.fromJson(Map<String, dynamic> res) { | ||
final message = res['message'] as String; | ||
final decoded = jsonDecode(message) as Map<String, dynamic>; | ||
|
||
return LangSyncServerResultSSE( | ||
outputPartitionId: decoded['partitionId'] as String, | ||
message: message, | ||
statusCode: res['statusCode'] as int, | ||
type: // this is hardcoded, butsince we are sure that it is correct. | ||
LangSyncServerSSEType.result, | ||
date: DateTime.parse( | ||
res['date'] as String, | ||
), | ||
); | ||
} | ||
|
||
@override | ||
List<Object?> get props => [outputPartitionId]; | ||
List<Object?> get props => [ | ||
outputPartitionId, | ||
super.message, | ||
super.type, | ||
super.statusCode, | ||
super.date, | ||
]; | ||
} | ||
|
||
class LangSyncServerLoggerSSE extends LangSyncServerSSE { | ||
const LangSyncServerLoggerSSE({ | ||
required super.date, | ||
required super.message, | ||
required super.statusCode, | ||
required super.type, | ||
}); | ||
|
||
@override | ||
List<Object?> get props => [ | ||
super.date, | ||
super.message, | ||
super.statusCode, | ||
super.type, | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.