update database
This commit is contained in:
69
lib/features/showrooms/data/models/showroom_model.dart
Normal file
69
lib/features/showrooms/data/models/showroom_model.dart
Normal file
@@ -0,0 +1,69 @@
|
||||
import 'dart:convert';
|
||||
import 'package:hive_ce/hive.dart';
|
||||
import 'package:worker/core/constants/storage_constants.dart';
|
||||
|
||||
part 'showroom_model.g.dart';
|
||||
|
||||
@HiveType(typeId: HiveTypeIds.showroomModel)
|
||||
class ShowroomModel extends HiveObject {
|
||||
ShowroomModel({required this.showroomId, required this.title, required this.description, this.coverImage, this.link360, required this.area, required this.style, required this.location, this.galleryImages, required this.viewCount, required this.isFeatured, required this.isActive, this.publishedAt, this.createdBy});
|
||||
|
||||
@HiveField(0) final String showroomId;
|
||||
@HiveField(1) final String title;
|
||||
@HiveField(2) final String description;
|
||||
@HiveField(3) final String? coverImage;
|
||||
@HiveField(4) final String? link360;
|
||||
@HiveField(5) final double area;
|
||||
@HiveField(6) final String style;
|
||||
@HiveField(7) final String location;
|
||||
@HiveField(8) final String? galleryImages;
|
||||
@HiveField(9) final int viewCount;
|
||||
@HiveField(10) final bool isFeatured;
|
||||
@HiveField(11) final bool isActive;
|
||||
@HiveField(12) final DateTime? publishedAt;
|
||||
@HiveField(13) final String? createdBy;
|
||||
|
||||
factory ShowroomModel.fromJson(Map<String, dynamic> json) => ShowroomModel(
|
||||
showroomId: json['showroom_id'] as String,
|
||||
title: json['title'] as String,
|
||||
description: json['description'] as String,
|
||||
coverImage: json['cover_image'] as String?,
|
||||
link360: json['link_360'] as String?,
|
||||
area: (json['area'] as num).toDouble(),
|
||||
style: json['style'] as String,
|
||||
location: json['location'] as String,
|
||||
galleryImages: json['gallery_images'] != null ? jsonEncode(json['gallery_images']) : null,
|
||||
viewCount: json['view_count'] as int? ?? 0,
|
||||
isFeatured: json['is_featured'] as bool? ?? false,
|
||||
isActive: json['is_active'] as bool? ?? true,
|
||||
publishedAt: json['published_at'] != null ? DateTime.parse(json['published_at']?.toString() ?? '') : null,
|
||||
createdBy: json['created_by'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'showroom_id': showroomId,
|
||||
'title': title,
|
||||
'description': description,
|
||||
'cover_image': coverImage,
|
||||
'link_360': link360,
|
||||
'area': area,
|
||||
'style': style,
|
||||
'location': location,
|
||||
'gallery_images': galleryImages != null ? jsonDecode(galleryImages!) : null,
|
||||
'view_count': viewCount,
|
||||
'is_featured': isFeatured,
|
||||
'is_active': isActive,
|
||||
'published_at': publishedAt?.toIso8601String(),
|
||||
'created_by': createdBy,
|
||||
};
|
||||
|
||||
List<String>? get galleryImagesList {
|
||||
if (galleryImages == null) return null;
|
||||
try {
|
||||
final decoded = jsonDecode(galleryImages!) as List;
|
||||
return decoded.map((e) => e.toString()).toList();
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
80
lib/features/showrooms/data/models/showroom_model.g.dart
Normal file
80
lib/features/showrooms/data/models/showroom_model.g.dart
Normal file
@@ -0,0 +1,80 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'showroom_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// TypeAdapterGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class ShowroomModelAdapter extends TypeAdapter<ShowroomModel> {
|
||||
@override
|
||||
final typeId = 21;
|
||||
|
||||
@override
|
||||
ShowroomModel read(BinaryReader reader) {
|
||||
final numOfFields = reader.readByte();
|
||||
final fields = <int, dynamic>{
|
||||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||
};
|
||||
return ShowroomModel(
|
||||
showroomId: fields[0] as String,
|
||||
title: fields[1] as String,
|
||||
description: fields[2] as String,
|
||||
coverImage: fields[3] as String?,
|
||||
link360: fields[4] as String?,
|
||||
area: (fields[5] as num).toDouble(),
|
||||
style: fields[6] as String,
|
||||
location: fields[7] as String,
|
||||
galleryImages: fields[8] as String?,
|
||||
viewCount: (fields[9] as num).toInt(),
|
||||
isFeatured: fields[10] as bool,
|
||||
isActive: fields[11] as bool,
|
||||
publishedAt: fields[12] as DateTime?,
|
||||
createdBy: fields[13] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, ShowroomModel obj) {
|
||||
writer
|
||||
..writeByte(14)
|
||||
..writeByte(0)
|
||||
..write(obj.showroomId)
|
||||
..writeByte(1)
|
||||
..write(obj.title)
|
||||
..writeByte(2)
|
||||
..write(obj.description)
|
||||
..writeByte(3)
|
||||
..write(obj.coverImage)
|
||||
..writeByte(4)
|
||||
..write(obj.link360)
|
||||
..writeByte(5)
|
||||
..write(obj.area)
|
||||
..writeByte(6)
|
||||
..write(obj.style)
|
||||
..writeByte(7)
|
||||
..write(obj.location)
|
||||
..writeByte(8)
|
||||
..write(obj.galleryImages)
|
||||
..writeByte(9)
|
||||
..write(obj.viewCount)
|
||||
..writeByte(10)
|
||||
..write(obj.isFeatured)
|
||||
..writeByte(11)
|
||||
..write(obj.isActive)
|
||||
..writeByte(12)
|
||||
..write(obj.publishedAt)
|
||||
..writeByte(13)
|
||||
..write(obj.createdBy);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => typeId.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is ShowroomModelAdapter &&
|
||||
runtimeType == other.runtimeType &&
|
||||
typeId == other.typeId;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import 'package:hive_ce/hive.dart';
|
||||
import 'package:worker/core/constants/storage_constants.dart';
|
||||
|
||||
part 'showroom_product_model.g.dart';
|
||||
|
||||
@HiveType(typeId: HiveTypeIds.showroomProductModel)
|
||||
class ShowroomProductModel extends HiveObject {
|
||||
ShowroomProductModel({required this.showroomId, required this.productId, required this.quantityUsed});
|
||||
|
||||
@HiveField(0) final String showroomId;
|
||||
@HiveField(1) final String productId;
|
||||
@HiveField(2) final double quantityUsed;
|
||||
|
||||
factory ShowroomProductModel.fromJson(Map<String, dynamic> json) => ShowroomProductModel(
|
||||
showroomId: json['showroom_id'] as String,
|
||||
productId: json['product_id'] as String,
|
||||
quantityUsed: (json['quantity_used'] as num).toDouble(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
'showroom_id': showroomId,
|
||||
'product_id': productId,
|
||||
'quantity_used': quantityUsed,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'showroom_product_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// TypeAdapterGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class ShowroomProductModelAdapter extends TypeAdapter<ShowroomProductModel> {
|
||||
@override
|
||||
final typeId = 22;
|
||||
|
||||
@override
|
||||
ShowroomProductModel read(BinaryReader reader) {
|
||||
final numOfFields = reader.readByte();
|
||||
final fields = <int, dynamic>{
|
||||
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||
};
|
||||
return ShowroomProductModel(
|
||||
showroomId: fields[0] as String,
|
||||
productId: fields[1] as String,
|
||||
quantityUsed: (fields[2] as num).toDouble(),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, ShowroomProductModel obj) {
|
||||
writer
|
||||
..writeByte(3)
|
||||
..writeByte(0)
|
||||
..write(obj.showroomId)
|
||||
..writeByte(1)
|
||||
..write(obj.productId)
|
||||
..writeByte(2)
|
||||
..write(obj.quantityUsed);
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => typeId.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is ShowroomProductModelAdapter &&
|
||||
runtimeType == other.runtimeType &&
|
||||
typeId == other.typeId;
|
||||
}
|
||||
163
lib/features/showrooms/domain/entities/showroom.dart
Normal file
163
lib/features/showrooms/domain/entities/showroom.dart
Normal file
@@ -0,0 +1,163 @@
|
||||
/// Domain Entity: Showroom
|
||||
///
|
||||
/// Represents a virtual showroom display.
|
||||
library;
|
||||
|
||||
/// Showroom Entity
|
||||
///
|
||||
/// Contains information about a showroom:
|
||||
/// - Showroom details and description
|
||||
/// - Media (images, 360 view)
|
||||
/// - Metadata (style, location, area)
|
||||
/// - Visibility settings
|
||||
class Showroom {
|
||||
/// Unique showroom identifier
|
||||
final String showroomId;
|
||||
|
||||
/// Showroom title
|
||||
final String title;
|
||||
|
||||
/// Showroom description
|
||||
final String? description;
|
||||
|
||||
/// Cover image URL
|
||||
final String? coverImage;
|
||||
|
||||
/// 360-degree view link
|
||||
final String? link360;
|
||||
|
||||
/// Showroom area (square meters)
|
||||
final double? area;
|
||||
|
||||
/// Design style
|
||||
final String? style;
|
||||
|
||||
/// Location/address
|
||||
final String? location;
|
||||
|
||||
/// Gallery image URLs
|
||||
final List<String> galleryImages;
|
||||
|
||||
/// View count
|
||||
final int viewCount;
|
||||
|
||||
/// Showroom is featured
|
||||
final bool isFeatured;
|
||||
|
||||
/// Showroom is active and visible
|
||||
final bool isActive;
|
||||
|
||||
/// Publication timestamp
|
||||
final DateTime? publishedAt;
|
||||
|
||||
/// User ID who created the showroom
|
||||
final String? createdBy;
|
||||
|
||||
const Showroom({
|
||||
required this.showroomId,
|
||||
required this.title,
|
||||
this.description,
|
||||
this.coverImage,
|
||||
this.link360,
|
||||
this.area,
|
||||
this.style,
|
||||
this.location,
|
||||
required this.galleryImages,
|
||||
required this.viewCount,
|
||||
required this.isFeatured,
|
||||
required this.isActive,
|
||||
this.publishedAt,
|
||||
this.createdBy,
|
||||
});
|
||||
|
||||
/// Check if showroom is published
|
||||
bool get isPublished =>
|
||||
publishedAt != null && DateTime.now().isAfter(publishedAt!);
|
||||
|
||||
/// Check if showroom has 360 view
|
||||
bool get has360View => link360 != null && link360!.isNotEmpty;
|
||||
|
||||
/// Check if showroom has gallery
|
||||
bool get hasGallery => galleryImages.isNotEmpty;
|
||||
|
||||
/// Get gallery size
|
||||
int get gallerySize => galleryImages.length;
|
||||
|
||||
/// Check if showroom has cover image
|
||||
bool get hasCoverImage => coverImage != null && coverImage!.isNotEmpty;
|
||||
|
||||
/// Get display image (cover or first gallery image)
|
||||
String? get displayImage {
|
||||
if (hasCoverImage) return coverImage;
|
||||
if (hasGallery) return galleryImages.first;
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Check if showroom can be viewed
|
||||
bool get canBeViewed => isActive && isPublished;
|
||||
|
||||
/// Copy with method for immutability
|
||||
Showroom copyWith({
|
||||
String? showroomId,
|
||||
String? title,
|
||||
String? description,
|
||||
String? coverImage,
|
||||
String? link360,
|
||||
double? area,
|
||||
String? style,
|
||||
String? location,
|
||||
List<String>? galleryImages,
|
||||
int? viewCount,
|
||||
bool? isFeatured,
|
||||
bool? isActive,
|
||||
DateTime? publishedAt,
|
||||
String? createdBy,
|
||||
}) {
|
||||
return Showroom(
|
||||
showroomId: showroomId ?? this.showroomId,
|
||||
title: title ?? this.title,
|
||||
description: description ?? this.description,
|
||||
coverImage: coverImage ?? this.coverImage,
|
||||
link360: link360 ?? this.link360,
|
||||
area: area ?? this.area,
|
||||
style: style ?? this.style,
|
||||
location: location ?? this.location,
|
||||
galleryImages: galleryImages ?? this.galleryImages,
|
||||
viewCount: viewCount ?? this.viewCount,
|
||||
isFeatured: isFeatured ?? this.isFeatured,
|
||||
isActive: isActive ?? this.isActive,
|
||||
publishedAt: publishedAt ?? this.publishedAt,
|
||||
createdBy: createdBy ?? this.createdBy,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return other is Showroom &&
|
||||
other.showroomId == showroomId &&
|
||||
other.title == title &&
|
||||
other.style == style &&
|
||||
other.isFeatured == isFeatured &&
|
||||
other.isActive == isActive;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hash(
|
||||
showroomId,
|
||||
title,
|
||||
style,
|
||||
isFeatured,
|
||||
isActive,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Showroom(showroomId: $showroomId, title: $title, style: $style, '
|
||||
'area: $area, viewCount: $viewCount, isFeatured: $isFeatured, '
|
||||
'isActive: $isActive)';
|
||||
}
|
||||
}
|
||||
65
lib/features/showrooms/domain/entities/showroom_product.dart
Normal file
65
lib/features/showrooms/domain/entities/showroom_product.dart
Normal file
@@ -0,0 +1,65 @@
|
||||
/// Domain Entity: Showroom Product
|
||||
///
|
||||
/// Represents a product used in a showroom display.
|
||||
library;
|
||||
|
||||
/// Showroom Product Entity
|
||||
///
|
||||
/// Contains information about a product featured in a showroom:
|
||||
/// - Product reference
|
||||
/// - Quantity used
|
||||
/// - Showroom context
|
||||
class ShowroomProduct {
|
||||
/// Showroom ID
|
||||
final String showroomId;
|
||||
|
||||
/// Product ID
|
||||
final String productId;
|
||||
|
||||
/// Quantity of product used in the showroom
|
||||
final double quantityUsed;
|
||||
|
||||
const ShowroomProduct({
|
||||
required this.showroomId,
|
||||
required this.productId,
|
||||
required this.quantityUsed,
|
||||
});
|
||||
|
||||
/// Copy with method for immutability
|
||||
ShowroomProduct copyWith({
|
||||
String? showroomId,
|
||||
String? productId,
|
||||
double? quantityUsed,
|
||||
}) {
|
||||
return ShowroomProduct(
|
||||
showroomId: showroomId ?? this.showroomId,
|
||||
productId: productId ?? this.productId,
|
||||
quantityUsed: quantityUsed ?? this.quantityUsed,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return other is ShowroomProduct &&
|
||||
other.showroomId == showroomId &&
|
||||
other.productId == productId &&
|
||||
other.quantityUsed == quantityUsed;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hash(
|
||||
showroomId,
|
||||
productId,
|
||||
quantityUsed,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ShowroomProduct(showroomId: $showroomId, productId: $productId, '
|
||||
'quantityUsed: $quantityUsed)';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user