request detail
This commit is contained in:
103
lib/features/showrooms/data/models/design_request_model.dart
Normal file
103
lib/features/showrooms/data/models/design_request_model.dart
Normal file
@@ -0,0 +1,103 @@
|
||||
/// Data Model: Design Request Model
|
||||
///
|
||||
/// JSON serialization model for design request API responses.
|
||||
library;
|
||||
|
||||
import 'package:worker/features/showrooms/data/models/sample_project_model.dart';
|
||||
import 'package:worker/features/showrooms/domain/entities/design_request.dart';
|
||||
|
||||
/// Design Request Model
|
||||
///
|
||||
/// Handles JSON serialization/deserialization for API communication.
|
||||
class DesignRequestModel {
|
||||
/// Unique request identifier (API: name)
|
||||
final String name;
|
||||
|
||||
/// Request subject/title (API: subject)
|
||||
final String subject;
|
||||
|
||||
/// Request description - may contain HTML (API: description)
|
||||
final String? description;
|
||||
|
||||
/// Deadline date string (API: dateline)
|
||||
final String? dateline;
|
||||
|
||||
/// Status display text (API: status)
|
||||
final String status;
|
||||
|
||||
/// Status color code (API: status_color)
|
||||
final String statusColor;
|
||||
|
||||
/// List of attached files (API: files_list) - available in detail
|
||||
final List<ProjectFileModel> filesList;
|
||||
|
||||
const DesignRequestModel({
|
||||
required this.name,
|
||||
required this.subject,
|
||||
this.description,
|
||||
this.dateline,
|
||||
required this.status,
|
||||
required this.statusColor,
|
||||
this.filesList = const [],
|
||||
});
|
||||
|
||||
/// Create model from JSON map
|
||||
factory DesignRequestModel.fromJson(Map<String, dynamic> json) {
|
||||
final filesListJson = json['files_list'] as List<dynamic>?;
|
||||
|
||||
return DesignRequestModel(
|
||||
name: json['name'] as String? ?? '',
|
||||
subject: json['subject'] as String? ?? '',
|
||||
description: json['description'] as String?,
|
||||
dateline: json['dateline'] as String?,
|
||||
status: json['status'] as String? ?? '',
|
||||
statusColor: json['status_color'] as String? ?? '',
|
||||
filesList: filesListJson != null
|
||||
? filesListJson
|
||||
.map((f) => ProjectFileModel.fromJson(f as Map<String, dynamic>))
|
||||
.toList()
|
||||
: [],
|
||||
);
|
||||
}
|
||||
|
||||
/// Convert model to JSON map
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'name': name,
|
||||
'subject': subject,
|
||||
'description': description,
|
||||
'dateline': dateline,
|
||||
'status': status,
|
||||
'status_color': statusColor,
|
||||
'files_list': filesList.map((f) => f.toJson()).toList(),
|
||||
};
|
||||
}
|
||||
|
||||
/// Convert to domain entity
|
||||
DesignRequest toEntity() {
|
||||
return DesignRequest(
|
||||
id: name,
|
||||
subject: subject,
|
||||
description: description,
|
||||
dateline: dateline,
|
||||
statusText: status,
|
||||
statusColor: statusColor,
|
||||
filesList: filesList.map((f) => f.toEntity()).toList(),
|
||||
);
|
||||
}
|
||||
|
||||
/// Create model from domain entity
|
||||
factory DesignRequestModel.fromEntity(DesignRequest entity) {
|
||||
return DesignRequestModel(
|
||||
name: entity.id,
|
||||
subject: entity.subject,
|
||||
description: entity.description,
|
||||
dateline: entity.dateline,
|
||||
status: entity.statusText,
|
||||
statusColor: entity.statusColor,
|
||||
filesList: entity.filesList
|
||||
.map((f) => ProjectFileModel(name: f.id, fileUrl: f.fileUrl))
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -5,24 +5,26 @@ library;
|
||||
|
||||
import 'package:worker/features/showrooms/domain/entities/sample_project.dart';
|
||||
|
||||
/// Sample Project File Model
|
||||
/// Project File Model
|
||||
///
|
||||
/// Handles JSON serialization for file attachments.
|
||||
class SampleProjectFileModel {
|
||||
/// Shared model for file attachments used by:
|
||||
/// - SampleProjectModel (model houses)
|
||||
/// - DesignRequestModel (design requests)
|
||||
class ProjectFileModel {
|
||||
/// Unique file identifier (API: name)
|
||||
final String name;
|
||||
|
||||
/// Full URL to the file (API: file_url)
|
||||
final String fileUrl;
|
||||
|
||||
const SampleProjectFileModel({
|
||||
const ProjectFileModel({
|
||||
required this.name,
|
||||
required this.fileUrl,
|
||||
});
|
||||
|
||||
/// Create model from JSON map
|
||||
factory SampleProjectFileModel.fromJson(Map<String, dynamic> json) {
|
||||
return SampleProjectFileModel(
|
||||
factory ProjectFileModel.fromJson(Map<String, dynamic> json) {
|
||||
return ProjectFileModel(
|
||||
name: json['name'] as String? ?? '',
|
||||
fileUrl: json['file_url'] as String? ?? '',
|
||||
);
|
||||
@@ -37,8 +39,8 @@ class SampleProjectFileModel {
|
||||
}
|
||||
|
||||
/// Convert to domain entity
|
||||
SampleProjectFile toEntity() {
|
||||
return SampleProjectFile(
|
||||
ProjectFile toEntity() {
|
||||
return ProjectFile(
|
||||
id: name,
|
||||
fileUrl: fileUrl,
|
||||
);
|
||||
@@ -65,7 +67,7 @@ class SampleProjectModel {
|
||||
final String? thumbnail;
|
||||
|
||||
/// List of attached files/images (API: files_list) - available in detail
|
||||
final List<SampleProjectFileModel> filesList;
|
||||
final List<ProjectFileModel> filesList;
|
||||
|
||||
const SampleProjectModel({
|
||||
required this.name,
|
||||
@@ -88,7 +90,7 @@ class SampleProjectModel {
|
||||
thumbnail: json['thumbnail'] as String?,
|
||||
filesList: filesListJson != null
|
||||
? filesListJson
|
||||
.map((f) => SampleProjectFileModel.fromJson(f as Map<String, dynamic>))
|
||||
.map((f) => ProjectFileModel.fromJson(f as Map<String, dynamic>))
|
||||
.toList()
|
||||
: [],
|
||||
);
|
||||
@@ -127,7 +129,7 @@ class SampleProjectModel {
|
||||
link: entity.viewUrl,
|
||||
thumbnail: entity.thumbnailUrl,
|
||||
filesList: entity.filesList
|
||||
.map((f) => SampleProjectFileModel(name: f.id, fileUrl: f.fileUrl))
|
||||
.map((f) => ProjectFileModel(name: f.id, fileUrl: f.fileUrl))
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user