Skip to content

Commit

Permalink
[ Edit ] added more comment docs for models
Browse files Browse the repository at this point in the history
  • Loading branch information
anasfik committed Dec 6, 2023
1 parent d429cd4 commit 0d7644d
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 33 deletions.
1 change: 0 additions & 1 deletion lib/src/commands/debug_info/debug_info.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// ignore_for_file: public_member_api_docs, sort_constructors_first
import 'dart:async';

import 'package:args/command_runner.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/src/commands/start_command/start_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class StartCommand extends Command<int> {

final outputList =
await NetClient.instance.retrieveJsonPartitionWithOutput(
outputoperationId: result.outputoperationId,
outputOperationId: result.outputOperationId,
apiKey: apiKey,
);

Expand Down
1 change: 1 addition & 0 deletions lib/src/etc/enums.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enum LangSyncServerSSEType { info, warn, error, result }
12 changes: 12 additions & 0 deletions lib/src/etc/models/Localization_doc.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import 'package:equatable/equatable.dart';

/// {@template localization_doc}
/// A Localization Doc model, it holds the created at date, the operation id, the json parts length and the output langs.
/// {@endtemplate}
class LocalizationDoc extends Equatable {
/// {@macro localization_doc}
const LocalizationDoc({
required this.createdAt,
required this.operationId,
required this.jsonPartsLength,
this.outputLangs,
});

/// Creates a [LocalizationDoc] from a [Map].
factory LocalizationDoc.fromJson(Map<String, dynamic> json) {
return LocalizationDoc(
createdAt: DateTime.parse(json['createdAt'] as String),
Expand All @@ -23,9 +28,16 @@ class LocalizationDoc extends Equatable {
);
}

/// The created at date.
final DateTime createdAt;

/// The operation id.
final String operationId;

/// The json parts length.
final int jsonPartsLength;

/// The output langs.
final List<String>? outputLangs;

@override
Expand Down
10 changes: 9 additions & 1 deletion lib/src/etc/models/lang_output.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
// ignore_for_file: public_member_api_docs, sort_constructors_first
import 'package:equatable/equatable.dart';

/// {@template lang_output}
/// A Language Output model, it holds the language name, the localized at date and the json formatted response.
/// {@endtemplate}
class LangOutput extends Equatable {
/// The language name.
final String lang;

/// The localized at date.
final DateTime localizedAt;

/// The json formatted response.
final Map<String, dynamic> jsonFormattedResponse;

/// {@macro lang_output}
const LangOutput({
required this.lang,
required this.localizedAt,
required this.jsonFormattedResponse,
});

/// Creates a [LangOutput] from a [Map].
factory LangOutput.fromJson(Map<String, dynamic> json) {
return LangOutput(
lang: json['lang'] as String,
Expand Down
15 changes: 10 additions & 5 deletions lib/src/etc/models/operation.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
// ignore_for_file: public_member_api_docs, sort_constructors_first
import 'package:equatable/equatable.dart';

class PartitionResponse extends Equatable {
/// {@template operation}
/// An Operation model, it holds the operation id and the operation type.
/// {@endtemplate}
class SaveFileOperation extends Equatable {
/// The operation id.
final String operationId;

const PartitionResponse({
/// {@macro operation}
const SaveFileOperation({
required this.operationId,
});

factory PartitionResponse.fromJson(Map<String, dynamic> json) {
return PartitionResponse(
/// Creates a [SaveFileOperation] from a [Map].
factory SaveFileOperation.fromJson(Map<String, dynamic> json) {
return SaveFileOperation(
operationId: json['operationId'] as String,
);
}
Expand Down
62 changes: 41 additions & 21 deletions lib/src/etc/models/result_locale.dart
Original file line number Diff line number Diff line change
@@ -1,32 +1,22 @@
// ignore_for_file: public_member_api_docs, sort_constructors_first
import 'dart:convert';

import 'package:equatable/equatable.dart';

typedef JsonContentMap = Map<String, dynamic>;

enum LangSyncServerSSEType { info, warn, error, result }
import 'package:langsync/src/etc/enums.dart';

/// {@template lang_sync_server_sse}
/// A LangSync Server SSE model, it holds the message, the type, the status code and the date.
/// {@endtemplate}
class LangSyncServerSSE extends Equatable {
final String message;
final LangSyncServerSSEType type;
final int statusCode;
final DateTime date;

/// {@macro lang_sync_server_sse}
const LangSyncServerSSE({
required this.message,
required this.type,
required this.statusCode,
required this.date,
});
@override
List<Object?> get props => [
message,
type,
statusCode,
date,
];

/// Creates a [LangSyncServerSSE] from a [Map].
factory LangSyncServerSSE.fromJson(Map<String, dynamic> res) {
final type = LangSyncServerSSEType.values.firstWhere(
(element) => element.name == res['type'] as String,
Expand All @@ -43,25 +33,48 @@ class LangSyncServerSSE extends Equatable {
);
}
}

/// The message of the SSE.
final String message;

/// The type of the SSE.
final LangSyncServerSSEType type;

/// The status code of the SSE.
final int statusCode;

/// The date of the SSE.
final DateTime date;

@override
List<Object?> get props => [
message,
type,
statusCode,
date,
];
}

/// {@template lang_sync_server_result_sse}
/// A LangSync Server Result SSE model, it holds the message, the type, the status code, the date and the output operation id.
/// {@endtemplate}
class LangSyncServerResultSSE extends LangSyncServerSSE {
final String outputoperationId;

/// {@macro lang_sync_server_result_sse}
const LangSyncServerResultSSE({
required this.outputoperationId,
required this.outputOperationId,
required super.message,
required super.type,
required super.statusCode,
required super.date,
});

/// Creates a [LangSyncServerResultSSE] from a [Map].
factory LangSyncServerResultSSE.fromJson(Map<String, dynamic> res) {
final message = res['message'] as String;
final decoded = jsonDecode(message) as Map<String, dynamic>;

return LangSyncServerResultSSE(
outputoperationId: decoded['operationId'] as String,
outputOperationId: decoded['operationId'] as String,
message: message,
statusCode: res['statusCode'] as int,
type: // this is hardcoded, butsince we are sure that it is correct.
Expand All @@ -72,17 +85,24 @@ class LangSyncServerResultSSE extends LangSyncServerSSE {
);
}

/// The output operation id.
final String outputOperationId;

@override
List<Object?> get props => [
outputoperationId,
outputOperationId,
super.message,
super.type,
super.statusCode,
super.date,
];
}

/// {@template lang_sync_server_logger_sse}
/// A LangSync Server Logger SSE model, it holds the message, the type, the status code and the date.
/// {@endtemplate}
class LangSyncServerLoggerSSE extends LangSyncServerSSE {
/// {@macro lang_sync_server_logger_sse}
const LangSyncServerLoggerSSE({
required super.date,
required super.message,
Expand Down
1 change: 1 addition & 0 deletions lib/src/etc/models/user_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:equatable/equatable.dart';
import 'package:langsync/src/etc/extensions.dart';
import 'package:langsync/src/etc/models/localization_doc.dart';

//! Schedule for removal.
class UserInfo extends Equatable {
const UserInfo({
required this.userId,
Expand Down
8 changes: 4 additions & 4 deletions lib/src/etc/networking/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class NetClient extends NetClientBoilerPlate {
);
}

Future<PartitionResponse> saveFile({
Future<SaveFileOperation> saveFile({
required String apiKey,
required File sourceFile,
}) {
Expand All @@ -58,12 +58,12 @@ class NetClient extends NetClientBoilerPlate {
'post',
{'Authorization': 'Bearer $apiKey'},
{'sourceFile': sourceFile},
PartitionResponse.fromJson,
SaveFileOperation.fromJson,
);
}

Future<List<LangOutput>> retrieveJsonPartitionWithOutput({
required String outputoperationId,
required String outputOperationId,
required String apiKey,
}) {
return makeRes(
Expand All @@ -73,7 +73,7 @@ class NetClient extends NetClientBoilerPlate {
'Authorization': 'Bearer $apiKey',
},
{
'operationId': outputoperationId,
'operationId': outputOperationId,
},
(res) {
final output = (res['output'] as List)
Expand Down
1 change: 1 addition & 0 deletions lib/src/etc/typedefs.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
typedef JsonContentMap = Map<String, dynamic>;

0 comments on commit 0d7644d

Please sign in to comment.