mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
no need for models and blocs for now
This commit is contained in:
@ -1,37 +0,0 @@
|
|||||||
import 'package:bloc/bloc.dart';
|
|
||||||
import 'package:equatable/equatable.dart';
|
|
||||||
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
|
||||||
|
|
||||||
import '../../data/models/community_model.dart';
|
|
||||||
import '../../data/sources/space_managment_remote_source.dart';
|
|
||||||
|
|
||||||
part 'communities_event.dart';
|
|
||||||
part 'communities_state.dart';
|
|
||||||
|
|
||||||
class CommunitiesBloc extends Bloc<CommunitiesEvent, CommunitiesState> {
|
|
||||||
SpaceManagementRemoteSource spaceManagementRemoteSource =
|
|
||||||
SpaceManagementRemoteSource();
|
|
||||||
CommunitiesBloc() : super(CommunitiesInitial()) {
|
|
||||||
on<CommunitiesEvent>((event, emit) {
|
|
||||||
if (event is FetchCommunitiesEvent) {
|
|
||||||
_fetchCommunities(emit);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _fetchCommunities(Emitter<CommunitiesState> emit) async {
|
|
||||||
String? projectUuid = await ProjectManager.getProjectUUID();
|
|
||||||
if (projectUuid == null) {
|
|
||||||
emit(const CommunitiesError("Project UUID is null"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
emit(CommunitiesLoading());
|
|
||||||
try {
|
|
||||||
final communities =
|
|
||||||
await spaceManagementRemoteSource.fetchCommunities(projectUuid);
|
|
||||||
emit(CommunitiesLoaded(communities));
|
|
||||||
} catch (e) {
|
|
||||||
emit(CommunitiesError(e.toString()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
part of 'communities_bloc.dart';
|
|
||||||
|
|
||||||
sealed class CommunitiesEvent extends Equatable {
|
|
||||||
const CommunitiesEvent();
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [];
|
|
||||||
}
|
|
||||||
|
|
||||||
class FetchCommunitiesEvent extends CommunitiesEvent {}
|
|
@ -1,30 +0,0 @@
|
|||||||
part of 'communities_bloc.dart';
|
|
||||||
|
|
||||||
sealed class CommunitiesState extends Equatable {
|
|
||||||
const CommunitiesState();
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [];
|
|
||||||
}
|
|
||||||
|
|
||||||
final class CommunitiesInitial extends CommunitiesState {}
|
|
||||||
|
|
||||||
final class CommunitiesLoading extends CommunitiesState {}
|
|
||||||
|
|
||||||
final class CommunitiesLoaded extends CommunitiesState {
|
|
||||||
final List<CommunityModel> communities;
|
|
||||||
|
|
||||||
const CommunitiesLoaded(this.communities);
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [communities];
|
|
||||||
}
|
|
||||||
|
|
||||||
final class CommunitiesError extends CommunitiesState {
|
|
||||||
final String message;
|
|
||||||
|
|
||||||
const CommunitiesError(this.message);
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [message];
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
import 'package:syncrow_web/pages/spaces_management/refactor/data/models/space_model.dart';
|
|
||||||
|
|
||||||
class CommunityModel {
|
|
||||||
String id, name;
|
|
||||||
List<SpaceModel>? spaces;
|
|
||||||
CommunityModel({
|
|
||||||
required this.id,
|
|
||||||
required this.name,
|
|
||||||
this.spaces,
|
|
||||||
});
|
|
||||||
|
|
||||||
factory CommunityModel.fromJson(Map<String, dynamic> json) => CommunityModel(
|
|
||||||
id: json['id'],
|
|
||||||
name: json['name'],
|
|
||||||
spaces: SpaceModel.fromJsonList(json['spaces']),
|
|
||||||
);
|
|
||||||
|
|
||||||
static List<CommunityModel> fromJsonList(List<dynamic> jsonList) {
|
|
||||||
return jsonList.map((json) => CommunityModel.fromJson(json)).toList();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
class DeviceModel {
|
|
||||||
String id, name, tag;
|
|
||||||
String location;
|
|
||||||
DeviceModel({
|
|
||||||
required this.id,
|
|
||||||
required this.name,
|
|
||||||
required this.tag,
|
|
||||||
required this.location,
|
|
||||||
});
|
|
||||||
factory DeviceModel.fromJson(Map<String, dynamic> json) => DeviceModel(
|
|
||||||
id: json['id'],
|
|
||||||
name: json['name'],
|
|
||||||
tag: json['tag'],
|
|
||||||
location: json['location'],
|
|
||||||
);
|
|
||||||
|
|
||||||
static List<DeviceModel> fromJsonList(List<dynamic> jsonList) {
|
|
||||||
return jsonList.map((json) => DeviceModel.fromJson(json)).toList();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
import 'device_model.dart';
|
|
||||||
|
|
||||||
class SpaceModel {
|
|
||||||
String id, parentId, name;
|
|
||||||
List<SpaceModel>? spaces;
|
|
||||||
List<DeviceModel>? devices;
|
|
||||||
|
|
||||||
SpaceModel({
|
|
||||||
required this.id,
|
|
||||||
required this.parentId,
|
|
||||||
required this.name,
|
|
||||||
this.spaces,
|
|
||||||
this.devices,
|
|
||||||
});
|
|
||||||
|
|
||||||
factory SpaceModel.fromJson(Map<String, dynamic> json) => SpaceModel(
|
|
||||||
id: json['id'],
|
|
||||||
parentId: json['parentId'],
|
|
||||||
name: json['name'],
|
|
||||||
spaces: SpaceModel.fromJsonList(json['spaces']),
|
|
||||||
devices: DeviceModel.fromJsonList(json['devices']),
|
|
||||||
);
|
|
||||||
|
|
||||||
static List<SpaceModel> fromJsonList(List<dynamic> jsonList) {
|
|
||||||
return jsonList.map((json) => SpaceModel.fromJson(json)).toList();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
import 'device_model.dart';
|
|
||||||
|
|
||||||
class SubSpaceModel {
|
|
||||||
String id, name;
|
|
||||||
List<DeviceModel>? devices;
|
|
||||||
SubSpaceModel({
|
|
||||||
required this.id,
|
|
||||||
required this.name,
|
|
||||||
this.devices,
|
|
||||||
});
|
|
||||||
factory SubSpaceModel.fromJson(Map<String, dynamic> json) => SubSpaceModel(
|
|
||||||
id: json['id'],
|
|
||||||
name: json['name'],
|
|
||||||
devices: DeviceModel.fromJsonList(json['devices']),
|
|
||||||
);
|
|
||||||
static List<SubSpaceModel> fromJsonList(List<dynamic> jsonList) {
|
|
||||||
return jsonList.map((json) => SubSpaceModel.fromJson(json)).toList();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
import 'package:syncrow_web/core/network/end_points.dart';
|
|
||||||
import 'package:syncrow_web/core/network/enums.dart';
|
|
||||||
import 'package:syncrow_web/core/network/request.dart';
|
|
||||||
|
|
||||||
import '../models/community_model.dart';
|
|
||||||
|
|
||||||
class SpaceManagementRemoteSource {
|
|
||||||
Future<List<CommunityModel>> fetchCommunities(String projectUuid) async {
|
|
||||||
Request request = Request(
|
|
||||||
EndPoints.fetchCommunities.replaceFirst('{projectUuid}', projectUuid),
|
|
||||||
method: RequestType.get,
|
|
||||||
autherized: true,
|
|
||||||
);
|
|
||||||
final response = await request.sendRequest();
|
|
||||||
return CommunityModel.fromJsonList((response['data']));
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user