create submission
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
/// Project Progress Model
|
||||
///
|
||||
/// Data model for project progress from API responses with Hive caching.
|
||||
/// Based on API response from frappe.client.get_list with doctype "Progress of construction"
|
||||
library;
|
||||
|
||||
import 'package:hive_ce/hive.dart';
|
||||
import 'package:worker/core/constants/storage_constants.dart';
|
||||
import 'package:worker/features/projects/domain/entities/project_progress.dart';
|
||||
|
||||
part 'project_progress_model.g.dart';
|
||||
|
||||
/// Project Progress Model - Type ID: 64
|
||||
@HiveType(typeId: HiveTypeIds.projectProgressModel)
|
||||
class ProjectProgressModel extends HiveObject {
|
||||
/// Unique identifier (API: name)
|
||||
@HiveField(0)
|
||||
final String id;
|
||||
|
||||
/// Progress status label in Vietnamese (API: status)
|
||||
@HiveField(1)
|
||||
final String status;
|
||||
|
||||
ProjectProgressModel({
|
||||
required this.id,
|
||||
required this.status,
|
||||
});
|
||||
|
||||
/// Create from JSON (API response)
|
||||
factory ProjectProgressModel.fromJson(Map<String, dynamic> json) {
|
||||
return ProjectProgressModel(
|
||||
id: json['name'] as String,
|
||||
status: json['status'] as String,
|
||||
);
|
||||
}
|
||||
|
||||
/// Convert to JSON
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'name': id,
|
||||
'status': status,
|
||||
};
|
||||
}
|
||||
|
||||
/// Convert to entity
|
||||
ProjectProgress toEntity() {
|
||||
return ProjectProgress(
|
||||
id: id,
|
||||
status: status,
|
||||
);
|
||||
}
|
||||
|
||||
/// Create from entity
|
||||
factory ProjectProgressModel.fromEntity(ProjectProgress entity) {
|
||||
return ProjectProgressModel(
|
||||
id: entity.id,
|
||||
status: entity.status,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'project_progress_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// TypeAdapterGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class ProjectProgressModelAdapter extends TypeAdapter<ProjectProgressModel> {
|
||||
@override
|
||||
final typeId = 64;
|
||||
|
||||
@override
|
||||
ProjectProgressModel read(BinaryReader reader) {
|
||||
final numOfFields = reader.readByte();
|
||||
final fields = <int, dynamic>{
|
||||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||
};
|
||||
return ProjectProgressModel(
|
||||
id: fields[0] as String,
|
||||
status: fields[1] as String,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, ProjectProgressModel obj) {
|
||||
writer
|
||||
..writeByte(2)
|
||||
..writeByte(0)
|
||||
..write(obj.id)
|
||||
..writeByte(1)
|
||||
..write(obj.status);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => typeId.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is ProjectProgressModelAdapter &&
|
||||
runtimeType == other.runtimeType &&
|
||||
typeId == other.typeId;
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
/// Project Submission Request Model
|
||||
///
|
||||
/// Request model for creating/updating project submissions via API.
|
||||
/// Based on API: building_material.building_material.api.project.save
|
||||
library;
|
||||
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
/// Project Submission Request
|
||||
///
|
||||
/// Used to create or update project submissions.
|
||||
class ProjectSubmissionRequest {
|
||||
/// Project ID (optional for new, required for update)
|
||||
final String? name;
|
||||
|
||||
/// Project name/title (API: designed_area)
|
||||
final String designedArea;
|
||||
|
||||
/// Project address (API: address_of_project)
|
||||
final String addressOfProject;
|
||||
|
||||
/// Project owner name (API: project_owner)
|
||||
final String projectOwner;
|
||||
|
||||
/// Design firm name (API: design_firm)
|
||||
final String? designFirm;
|
||||
|
||||
/// Construction contractor name (API: contruction_contractor)
|
||||
final String? contractionContractor;
|
||||
|
||||
/// Design area in m² (API: design_area)
|
||||
final double designArea;
|
||||
|
||||
/// Products included in the design (API: products_included_in_the_design)
|
||||
final String productsIncludedInTheDesign;
|
||||
|
||||
/// Project progress ID from ProjectProgress.id (API: project_progress)
|
||||
final String projectProgress;
|
||||
|
||||
/// Expected commencement date (API: expected_commencement_date)
|
||||
final DateTime? expectedCommencementDate;
|
||||
|
||||
/// Project description (API: description)
|
||||
final String? description;
|
||||
|
||||
/// Request date (API: request_date)
|
||||
final DateTime? requestDate;
|
||||
|
||||
const ProjectSubmissionRequest({
|
||||
this.name,
|
||||
required this.designedArea,
|
||||
required this.addressOfProject,
|
||||
required this.projectOwner,
|
||||
this.designFirm,
|
||||
this.contractionContractor,
|
||||
required this.designArea,
|
||||
required this.productsIncludedInTheDesign,
|
||||
required this.projectProgress,
|
||||
this.expectedCommencementDate,
|
||||
this.description,
|
||||
this.requestDate,
|
||||
});
|
||||
|
||||
/// Convert to JSON for API request
|
||||
Map<String, dynamic> toJson() {
|
||||
final dateFormat = DateFormat('yyyy-MM-dd');
|
||||
final dateTimeFormat = DateFormat('yyyy-MM-dd HH:mm:ss');
|
||||
|
||||
return {
|
||||
if (name != null) 'name': name,
|
||||
'designed_area': designedArea,
|
||||
'address_of_project': addressOfProject,
|
||||
'project_owner': projectOwner,
|
||||
if (designFirm != null) 'design_firm': designFirm,
|
||||
if (contractionContractor != null)
|
||||
'contruction_contractor': contractionContractor,
|
||||
'design_area': designArea,
|
||||
'products_included_in_the_design': productsIncludedInTheDesign,
|
||||
'project_progress': projectProgress,
|
||||
if (expectedCommencementDate != null)
|
||||
'expected_commencement_date': dateFormat.format(expectedCommencementDate!),
|
||||
if (description != null) 'description': description,
|
||||
'request_date': dateTimeFormat.format(requestDate ?? DateTime.now()),
|
||||
};
|
||||
}
|
||||
|
||||
/// Create a copy with updated fields
|
||||
ProjectSubmissionRequest copyWith({
|
||||
String? name,
|
||||
String? designedArea,
|
||||
String? addressOfProject,
|
||||
String? projectOwner,
|
||||
String? designFirm,
|
||||
String? contractionContractor,
|
||||
double? designArea,
|
||||
String? productsIncludedInTheDesign,
|
||||
String? projectProgress,
|
||||
DateTime? expectedCommencementDate,
|
||||
String? description,
|
||||
DateTime? requestDate,
|
||||
}) {
|
||||
return ProjectSubmissionRequest(
|
||||
name: name ?? this.name,
|
||||
designedArea: designedArea ?? this.designedArea,
|
||||
addressOfProject: addressOfProject ?? this.addressOfProject,
|
||||
projectOwner: projectOwner ?? this.projectOwner,
|
||||
designFirm: designFirm ?? this.designFirm,
|
||||
contractionContractor: contractionContractor ?? this.contractionContractor,
|
||||
designArea: designArea ?? this.designArea,
|
||||
productsIncludedInTheDesign:
|
||||
productsIncludedInTheDesign ?? this.productsIncludedInTheDesign,
|
||||
projectProgress: projectProgress ?? this.projectProgress,
|
||||
expectedCommencementDate:
|
||||
expectedCommencementDate ?? this.expectedCommencementDate,
|
||||
description: description ?? this.description,
|
||||
requestDate: requestDate ?? this.requestDate,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user