refactor: Projektstruktur in app/ und backend/ aufgeteilt
This commit is contained in:
85
app/lib/models/acknowledgment_message.dart
Normal file
85
app/lib/models/acknowledgment_message.dart
Normal file
@@ -0,0 +1,85 @@
|
||||
/// Acknowledgment message sent by client to confirm message receipt
|
||||
class AcknowledgmentMessage {
|
||||
/// ID of the message being acknowledged
|
||||
final String messageId;
|
||||
|
||||
/// Status of the acknowledgment
|
||||
final AcknowledgmentStatus status;
|
||||
|
||||
/// Timestamp when the acknowledgment was created
|
||||
final DateTime timestamp;
|
||||
|
||||
/// Optional error message if status is FAILED
|
||||
final String? errorMessage;
|
||||
|
||||
AcknowledgmentMessage({
|
||||
required this.messageId,
|
||||
required this.status,
|
||||
required this.timestamp,
|
||||
this.errorMessage,
|
||||
});
|
||||
|
||||
/// Create AcknowledgmentMessage from JSON
|
||||
factory AcknowledgmentMessage.fromJson(Map<String, dynamic> json) {
|
||||
return AcknowledgmentMessage(
|
||||
messageId: json['messageId'] as String,
|
||||
status: AcknowledgmentStatus.fromString(json['status'] as String),
|
||||
timestamp: DateTime.parse(json['timestamp'] as String),
|
||||
errorMessage: json['errorMessage'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
/// Convert AcknowledgmentMessage to JSON
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'messageId': messageId,
|
||||
'status': status.toString(),
|
||||
'timestamp': timestamp.toIso8601String(),
|
||||
if (errorMessage != null) 'errorMessage': errorMessage,
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'AcknowledgmentMessage(messageId: $messageId, status: $status)';
|
||||
}
|
||||
}
|
||||
|
||||
/// Status of an acknowledgment
|
||||
enum AcknowledgmentStatus {
|
||||
/// Message was received by the client
|
||||
received,
|
||||
|
||||
/// Message was processed successfully
|
||||
processed,
|
||||
|
||||
/// Message processing failed
|
||||
failed;
|
||||
|
||||
/// Convert string to AcknowledgmentStatus
|
||||
static AcknowledgmentStatus fromString(String value) {
|
||||
switch (value.toUpperCase()) {
|
||||
case 'RECEIVED':
|
||||
return AcknowledgmentStatus.received;
|
||||
case 'PROCESSED':
|
||||
return AcknowledgmentStatus.processed;
|
||||
case 'FAILED':
|
||||
return AcknowledgmentStatus.failed;
|
||||
default:
|
||||
return AcknowledgmentStatus.received;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
switch (this) {
|
||||
case AcknowledgmentStatus.received:
|
||||
return 'RECEIVED';
|
||||
case AcknowledgmentStatus.processed:
|
||||
return 'PROCESSED';
|
||||
case AcknowledgmentStatus.failed:
|
||||
return 'FAILED';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user