sample project
This commit is contained in:
134
lib/features/showrooms/data/models/sample_project_model.dart
Normal file
134
lib/features/showrooms/data/models/sample_project_model.dart
Normal file
@@ -0,0 +1,134 @@
|
||||
/// Data Model: Sample Project Model
|
||||
///
|
||||
/// JSON serialization model for sample project API responses.
|
||||
library;
|
||||
|
||||
import 'package:worker/features/showrooms/domain/entities/sample_project.dart';
|
||||
|
||||
/// Sample Project File Model
|
||||
///
|
||||
/// Handles JSON serialization for file attachments.
|
||||
class SampleProjectFileModel {
|
||||
/// Unique file identifier (API: name)
|
||||
final String name;
|
||||
|
||||
/// Full URL to the file (API: file_url)
|
||||
final String fileUrl;
|
||||
|
||||
const SampleProjectFileModel({
|
||||
required this.name,
|
||||
required this.fileUrl,
|
||||
});
|
||||
|
||||
/// Create model from JSON map
|
||||
factory SampleProjectFileModel.fromJson(Map<String, dynamic> json) {
|
||||
return SampleProjectFileModel(
|
||||
name: json['name'] as String? ?? '',
|
||||
fileUrl: json['file_url'] as String? ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
/// Convert model to JSON map
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'name': name,
|
||||
'file_url': fileUrl,
|
||||
};
|
||||
}
|
||||
|
||||
/// Convert to domain entity
|
||||
SampleProjectFile toEntity() {
|
||||
return SampleProjectFile(
|
||||
id: name,
|
||||
fileUrl: fileUrl,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Sample Project Model
|
||||
///
|
||||
/// Handles JSON serialization/deserialization for API communication.
|
||||
class SampleProjectModel {
|
||||
/// Unique project identifier (API: name)
|
||||
final String name;
|
||||
|
||||
/// Project display name (API: project_name)
|
||||
final String projectName;
|
||||
|
||||
/// Project description/notes - may contain HTML (API: notes)
|
||||
final String? notes;
|
||||
|
||||
/// URL to 360° view (API: link)
|
||||
final String? link;
|
||||
|
||||
/// Thumbnail image URL (API: thumbnail)
|
||||
final String? thumbnail;
|
||||
|
||||
/// List of attached files/images (API: files_list) - available in detail
|
||||
final List<SampleProjectFileModel> filesList;
|
||||
|
||||
const SampleProjectModel({
|
||||
required this.name,
|
||||
required this.projectName,
|
||||
this.notes,
|
||||
this.link,
|
||||
this.thumbnail,
|
||||
this.filesList = const [],
|
||||
});
|
||||
|
||||
/// Create model from JSON map
|
||||
factory SampleProjectModel.fromJson(Map<String, dynamic> json) {
|
||||
final filesListJson = json['files_list'] as List<dynamic>?;
|
||||
|
||||
return SampleProjectModel(
|
||||
name: json['name'] as String? ?? '',
|
||||
projectName: json['project_name'] as String? ?? '',
|
||||
notes: json['notes'] as String?,
|
||||
link: json['link'] as String?,
|
||||
thumbnail: json['thumbnail'] as String?,
|
||||
filesList: filesListJson != null
|
||||
? filesListJson
|
||||
.map((f) => SampleProjectFileModel.fromJson(f as Map<String, dynamic>))
|
||||
.toList()
|
||||
: [],
|
||||
);
|
||||
}
|
||||
|
||||
/// Convert model to JSON map
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'name': name,
|
||||
'project_name': projectName,
|
||||
'notes': notes,
|
||||
'link': link,
|
||||
'thumbnail': thumbnail,
|
||||
'files_list': filesList.map((f) => f.toJson()).toList(),
|
||||
};
|
||||
}
|
||||
|
||||
/// Convert to domain entity
|
||||
SampleProject toEntity() {
|
||||
return SampleProject(
|
||||
id: name,
|
||||
projectName: projectName,
|
||||
description: notes,
|
||||
viewUrl: link,
|
||||
thumbnailUrl: thumbnail,
|
||||
filesList: filesList.map((f) => f.toEntity()).toList(),
|
||||
);
|
||||
}
|
||||
|
||||
/// Create model from domain entity
|
||||
factory SampleProjectModel.fromEntity(SampleProject entity) {
|
||||
return SampleProjectModel(
|
||||
name: entity.id,
|
||||
projectName: entity.projectName,
|
||||
notes: entity.description,
|
||||
link: entity.viewUrl,
|
||||
thumbnail: entity.thumbnailUrl,
|
||||
filesList: entity.filesList
|
||||
.map((f) => SampleProjectFileModel(name: f.id, fileUrl: f.fileUrl))
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user