diff --git a/lib/pages/space_management_v2/modules/communities/presentation/bloc/communities_bloc.dart b/lib/pages/space_management_v2/modules/communities/presentation/bloc/communities_bloc.dart index 83b71c1c..0d85b22f 100644 --- a/lib/pages/space_management_v2/modules/communities/presentation/bloc/communities_bloc.dart +++ b/lib/pages/space_management_v2/modules/communities/presentation/bloc/communities_bloc.dart @@ -13,12 +13,12 @@ class CommunitiesBloc extends Bloc { required CommunitiesService communitiesService, }) : _communitiesService = communitiesService, super(const CommunitiesState()) { - on(_onGetCommunity); + on(_onLoadCommunities); } final CommunitiesService _communitiesService; - Future _onGetCommunity( + Future _onLoadCommunities( LoadCommunities event, Emitter emit, ) async { diff --git a/lib/pages/space_management_v2/modules/products/data/services/remote_products_service.dart b/lib/pages/space_management_v2/modules/products/data/services/remote_products_service.dart index 47b8f6aa..6e501b44 100644 --- a/lib/pages/space_management_v2/modules/products/data/services/remote_products_service.dart +++ b/lib/pages/space_management_v2/modules/products/data/services/remote_products_service.dart @@ -1,5 +1,5 @@ import 'package:dio/dio.dart'; -import 'package:syncrow_web/pages/space_management_v2/modules/products/domain/models/product_model.dart'; +import 'package:syncrow_web/pages/space_management_v2/modules/products/domain/models/product.dart'; import 'package:syncrow_web/pages/space_management_v2/modules/products/domain/params/load_products_param.dart'; import 'package:syncrow_web/pages/space_management_v2/modules/products/domain/services/products_service.dart'; import 'package:syncrow_web/services/api/api_exception.dart'; @@ -13,7 +13,7 @@ class RemoteProductsService implements ProductsService { static const _defaultErrorMessage = 'Failed to load devices'; @override - Future> getProducts(LoadProductsParam param) async { + Future> getProducts(LoadProductsParam param) async { try { final response = await _httpService.get( path: 'devices', @@ -24,7 +24,7 @@ class RemoteProductsService implements ProductsService { }, expectedResponseModel: (data) { return (data as List) - .map((e) => ProductModel.fromJson(e as Map)) + .map((e) => Product.fromJson(e as Map)) .toList(); }, ); diff --git a/lib/pages/space_management_v2/modules/products/domain/models/product_model.dart b/lib/pages/space_management_v2/modules/products/domain/models/product.dart similarity index 55% rename from lib/pages/space_management_v2/modules/products/domain/models/product_model.dart rename to lib/pages/space_management_v2/modules/products/domain/models/product.dart index 03a7995c..cd837121 100644 --- a/lib/pages/space_management_v2/modules/products/domain/models/product_model.dart +++ b/lib/pages/space_management_v2/modules/products/domain/models/product.dart @@ -1,21 +1,28 @@ import 'package:equatable/equatable.dart'; -class ProductModel extends Equatable { +class Product extends Equatable { final String uuid; final String name; - const ProductModel({ + const Product({ required this.uuid, required this.name, }); - factory ProductModel.fromJson(Map json) { - return ProductModel( + factory Product.fromJson(Map json) { + return Product( uuid: json['uuid'] as String, name: json['name'] as String, ); } + Map toJson() { + return { + 'uuid': uuid, + 'name': name, + }; + } + @override List get props => [uuid, name]; } diff --git a/lib/pages/space_management_v2/modules/products/domain/services/products_service.dart b/lib/pages/space_management_v2/modules/products/domain/services/products_service.dart index fe9b2850..18554382 100644 --- a/lib/pages/space_management_v2/modules/products/domain/services/products_service.dart +++ b/lib/pages/space_management_v2/modules/products/domain/services/products_service.dart @@ -1,6 +1,6 @@ -import 'package:syncrow_web/pages/space_management_v2/modules/products/domain/models/product_model.dart'; +import 'package:syncrow_web/pages/space_management_v2/modules/products/domain/models/product.dart'; import 'package:syncrow_web/pages/space_management_v2/modules/products/domain/params/load_products_param.dart'; abstract class ProductsService { - Future> getProducts(LoadProductsParam param); + Future> getProducts(LoadProductsParam param); } diff --git a/lib/pages/space_management_v2/modules/products/presentation/bloc/products_bloc.dart b/lib/pages/space_management_v2/modules/products/presentation/bloc/products_bloc.dart index a0f227c1..1ce6ae89 100644 --- a/lib/pages/space_management_v2/modules/products/presentation/bloc/products_bloc.dart +++ b/lib/pages/space_management_v2/modules/products/presentation/bloc/products_bloc.dart @@ -1,6 +1,6 @@ import 'package:bloc/bloc.dart'; import 'package:equatable/equatable.dart'; -import 'package:syncrow_web/pages/space_management_v2/modules/products/domain/models/product_model.dart'; +import 'package:syncrow_web/pages/space_management_v2/modules/products/domain/models/product.dart'; import 'package:syncrow_web/pages/space_management_v2/modules/products/domain/params/load_products_param.dart'; import 'package:syncrow_web/pages/space_management_v2/modules/products/domain/services/products_service.dart'; import 'package:syncrow_web/services/api/api_exception.dart'; @@ -12,10 +12,10 @@ class ProductsBloc extends Bloc { final ProductsService _deviceService; ProductsBloc(this._deviceService) : super(ProductsInitial()) { - on(_onLoadDevices); + on(_onLoadProducts); } - Future _onLoadDevices( + Future _onLoadProducts( LoadProducts event, Emitter emit, ) async { diff --git a/lib/pages/space_management_v2/modules/products/presentation/bloc/products_state.dart b/lib/pages/space_management_v2/modules/products/presentation/bloc/products_state.dart index 68942282..d5622cd3 100644 --- a/lib/pages/space_management_v2/modules/products/presentation/bloc/products_state.dart +++ b/lib/pages/space_management_v2/modules/products/presentation/bloc/products_state.dart @@ -12,12 +12,12 @@ final class ProductsInitial extends ProductsState {} final class ProductsLoading extends ProductsState {} final class ProductsLoaded extends ProductsState { - final List devices; + final List products; - const ProductsLoaded(this.devices); + const ProductsLoaded(this.products); @override - List get props => [devices]; + List get props => [products]; } final class ProductsFailure extends ProductsState { diff --git a/lib/pages/space_management_v2/modules/space_details/domain/models/space_details_model.dart b/lib/pages/space_management_v2/modules/space_details/domain/models/space_details_model.dart index 0d2ea80d..891e7eb2 100644 --- a/lib/pages/space_management_v2/modules/space_details/domain/models/space_details_model.dart +++ b/lib/pages/space_management_v2/modules/space_details/domain/models/space_details_model.dart @@ -1,4 +1,6 @@ import 'package:equatable/equatable.dart'; +import 'package:syncrow_web/pages/space_management_v2/modules/products/domain/models/product.dart'; +import 'package:syncrow_web/pages/space_management_v2/modules/tags/domain/models/tag.dart'; class SpaceDetailsModel extends Equatable { final String uuid; @@ -46,10 +48,12 @@ class SpaceDetailsModel extends Equatable { class ProductAllocation extends Equatable { final Product product; final Tag tag; + final String? location; const ProductAllocation({ required this.product, required this.tag, + this.location, }); factory ProductAllocation.fromJson(Map json) { @@ -70,68 +74,6 @@ class ProductAllocation extends Equatable { List get props => [product, tag]; } -class Product extends Equatable { - final String uuid; - final String name; - - const Product({ - required this.uuid, - required this.name, - }); - - factory Product.fromJson(Map json) { - return Product( - uuid: json['uuid'] as String, - name: json['name'] as String, - ); - } - - Map toJson() { - return { - 'uuid': uuid, - 'name': name, - }; - } - - @override - List get props => [uuid, name]; -} - -class Tag extends Equatable { - final String uuid; - final String name; - final String createdAt; - final String updatedAt; - - const Tag({ - required this.uuid, - required this.name, - required this.createdAt, - required this.updatedAt, - }); - - factory Tag.fromJson(Map json) { - return Tag( - uuid: json['uuid'] as String, - name: json['name'] as String, - createdAt: json['createdAt'] as String, - updatedAt: json['updatedAt'] as String, - ); - } - - Map toJson() { - return { - 'uuid': uuid, - 'name': name, - 'createdAt': createdAt, - 'updatedAt': updatedAt, - }; - } - - @override - List get props => [uuid, name, createdAt, updatedAt]; -} - class Subspace extends Equatable { final String uuid; final String name; diff --git a/lib/pages/space_management_v2/modules/tags/data/services/remote_tags_service.dart b/lib/pages/space_management_v2/modules/tags/data/services/remote_tags_service.dart index b97077f5..b5545bd3 100644 --- a/lib/pages/space_management_v2/modules/tags/data/services/remote_tags_service.dart +++ b/lib/pages/space_management_v2/modules/tags/data/services/remote_tags_service.dart @@ -1,5 +1,5 @@ import 'package:dio/dio.dart'; -import 'package:syncrow_web/pages/space_management_v2/modules/tags/domain/models/tag_model.dart'; +import 'package:syncrow_web/pages/space_management_v2/modules/tags/domain/models/tag.dart'; import 'package:syncrow_web/pages/space_management_v2/modules/tags/domain/params/load_tags_param.dart'; import 'package:syncrow_web/pages/space_management_v2/modules/tags/domain/services/tags_service.dart'; import 'package:syncrow_web/services/api/api_exception.dart'; @@ -14,7 +14,7 @@ final class RemoteTagsService implements TagsService { static const _defaultErrorMessage = 'Failed to load tags'; @override - Future> loadTags(LoadTagsParam param) async { + Future> loadTags(LoadTagsParam param) async { if (param.projectUuid == null) { throw Exception('Project UUID is required'); } @@ -28,9 +28,7 @@ final class RemoteTagsService implements TagsService { expectedResponseModel: (json) { final result = json as Map; final data = result['data'] as List; - return data - .map((e) => TagModel.fromJson(e as Map)) - .toList(); + return data.map((e) => Tag.fromJson(e as Map)).toList(); }, ); return response; diff --git a/lib/pages/space_management_v2/modules/tags/domain/models/tag.dart b/lib/pages/space_management_v2/modules/tags/domain/models/tag.dart new file mode 100644 index 00000000..1044d888 --- /dev/null +++ b/lib/pages/space_management_v2/modules/tags/domain/models/tag.dart @@ -0,0 +1,36 @@ +import 'package:equatable/equatable.dart'; + +class Tag extends Equatable { + final String uuid; + final String name; + final String createdAt; + final String updatedAt; + + const Tag({ + required this.uuid, + required this.name, + required this.createdAt, + required this.updatedAt, + }); + + factory Tag.fromJson(Map json) { + return Tag( + uuid: json['uuid'] as String, + name: json['name'] as String, + createdAt: json['createdAt'] as String, + updatedAt: json['updatedAt'] as String, + ); + } + + Map toJson() { + return { + 'uuid': uuid, + 'name': name, + 'createdAt': createdAt, + 'updatedAt': updatedAt, + }; + } + + @override + List get props => [uuid, name, createdAt, updatedAt]; +} diff --git a/lib/pages/space_management_v2/modules/tags/domain/models/tag_model.dart b/lib/pages/space_management_v2/modules/tags/domain/models/tag_model.dart deleted file mode 100644 index 108aa6b2..00000000 --- a/lib/pages/space_management_v2/modules/tags/domain/models/tag_model.dart +++ /dev/null @@ -1,53 +0,0 @@ -import 'package:equatable/equatable.dart'; -import 'package:uuid/uuid.dart'; - -class TagModel extends Equatable { - const TagModel({ - required this.uuid, - required this.tag, - required this.internalId, - required this.location, - }); - - final String? uuid; - final String? tag; - final String? internalId; - final String? location; - - factory TagModel.fromJson(Map json) { - final internalId = json['internalId'] as String? ?? const Uuid().v4(); - final tag = json['tag'] as Map?; - final name = json['name'] as String?; - - return TagModel( - uuid: name != null ? json['uuid'] as String? : tag?['uuid'] as String?, - internalId: internalId, - tag: name ?? tag?['name'] as String?, - location: json['location'] as String?, - ); - } - - TagModel copyWith({ - String? uuid, - String? tag, - String? location, - String? internalId, - }) { - return TagModel( - uuid: uuid ?? this.uuid, - tag: tag ?? this.tag, - location: location ?? this.location, - internalId: internalId ?? this.internalId, - ); - } - - Map toJson() { - return { - if (uuid != null) 'uuid': uuid, - 'name': tag, - }; - } - - @override - List get props => [uuid, tag, internalId, location]; -} diff --git a/lib/pages/space_management_v2/modules/tags/domain/services/tags_service.dart b/lib/pages/space_management_v2/modules/tags/domain/services/tags_service.dart index a143743d..ae097020 100644 --- a/lib/pages/space_management_v2/modules/tags/domain/services/tags_service.dart +++ b/lib/pages/space_management_v2/modules/tags/domain/services/tags_service.dart @@ -1,6 +1,6 @@ -import 'package:syncrow_web/pages/space_management_v2/modules/tags/domain/models/tag_model.dart'; +import 'package:syncrow_web/pages/space_management_v2/modules/tags/domain/models/tag.dart'; import 'package:syncrow_web/pages/space_management_v2/modules/tags/domain/params/load_tags_param.dart'; abstract interface class TagsService { - Future> loadTags(LoadTagsParam param); + Future> loadTags(LoadTagsParam param); } diff --git a/lib/pages/space_management_v2/modules/tags/presentation/bloc/tags_bloc.dart b/lib/pages/space_management_v2/modules/tags/presentation/bloc/tags_bloc.dart index b4091478..e51884cb 100644 --- a/lib/pages/space_management_v2/modules/tags/presentation/bloc/tags_bloc.dart +++ b/lib/pages/space_management_v2/modules/tags/presentation/bloc/tags_bloc.dart @@ -1,6 +1,6 @@ import 'package:bloc/bloc.dart'; import 'package:equatable/equatable.dart'; -import 'package:syncrow_web/pages/space_management_v2/modules/tags/domain/models/tag_model.dart'; +import 'package:syncrow_web/pages/space_management_v2/modules/tags/domain/models/tag.dart'; import 'package:syncrow_web/pages/space_management_v2/modules/tags/domain/params/load_tags_param.dart'; import 'package:syncrow_web/pages/space_management_v2/modules/tags/domain/services/tags_service.dart'; import 'package:syncrow_web/services/api/api_exception.dart'; diff --git a/lib/pages/space_management_v2/modules/tags/presentation/bloc/tags_state.dart b/lib/pages/space_management_v2/modules/tags/presentation/bloc/tags_state.dart index d6a13c6d..7afe55c9 100644 --- a/lib/pages/space_management_v2/modules/tags/presentation/bloc/tags_state.dart +++ b/lib/pages/space_management_v2/modules/tags/presentation/bloc/tags_state.dart @@ -12,7 +12,7 @@ class TagsInitial extends TagsState {} class TagsLoading extends TagsState {} class TagsLoaded extends TagsState { - final List tags; + final List tags; const TagsLoaded(this.tags);