mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
Dev (#265)
<!-- Thanks for contributing! Provide a description of your changes below and a general summary in the title Please look at the following checklist to ensure that your PR can be accepted quickly: --> ## Description <!--- Describe your changes in detail --> ## Type of Change <!--- Put an `x` in all the boxes that apply: --> - [x] ✨ New feature (non-breaking change which adds functionality) - [ ] 🛠️ Bug fix (non-breaking change which fixes an issue) - [ ] ❌ Breaking change (fix or feature that would cause existing functionality to change) - [ ] 🧹 Code refactor - [ ] ✅ Build configuration change - [ ] 📝 Documentation - [ ] 🗑️ Chore
This commit is contained in:
@ -7,7 +7,6 @@ import 'package:go_router/go_router.dart';
|
|||||||
import 'package:syncrow_web/firebase_options_prod.dart';
|
import 'package:syncrow_web/firebase_options_prod.dart';
|
||||||
import 'package:syncrow_web/pages/auth/bloc/auth_bloc.dart';
|
import 'package:syncrow_web/pages/auth/bloc/auth_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/home/bloc/home_bloc.dart';
|
import 'package:syncrow_web/pages/home/bloc/home_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/home/bloc/home_event.dart';
|
|
||||||
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_bloc.dart';
|
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
||||||
@ -21,8 +20,10 @@ import 'package:syncrow_web/utils/theme/theme.dart';
|
|||||||
|
|
||||||
Future<void> main() async {
|
Future<void> main() async {
|
||||||
try {
|
try {
|
||||||
const environment =
|
const environment = String.fromEnvironment(
|
||||||
String.fromEnvironment('FLAVOR', defaultValue: 'production');
|
'FLAVOR',
|
||||||
|
defaultValue: 'production',
|
||||||
|
);
|
||||||
await dotenv.load(fileName: '.env.$environment');
|
await dotenv.load(fileName: '.env.$environment');
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
await Firebase.initializeApp(
|
await Firebase.initializeApp(
|
||||||
@ -40,7 +41,7 @@ class MyApp extends StatelessWidget {
|
|||||||
initialLocation: RoutesConst.auth,
|
initialLocation: RoutesConst.auth,
|
||||||
routes: AppRoutes.getRoutes(),
|
routes: AppRoutes.getRoutes(),
|
||||||
redirect: (context, state) async {
|
redirect: (context, state) async {
|
||||||
String checkToken = await AuthBloc.getTokenAndValidate();
|
final checkToken = await AuthBloc.getTokenAndValidate();
|
||||||
final loggedIn = checkToken == 'Success';
|
final loggedIn = checkToken == 'Success';
|
||||||
final goingToLogin = state.uri.toString() == RoutesConst.auth;
|
final goingToLogin = state.uri.toString() == RoutesConst.auth;
|
||||||
|
|
||||||
@ -58,8 +59,7 @@ class MyApp extends StatelessWidget {
|
|||||||
BlocProvider<CreateRoutineBloc>(
|
BlocProvider<CreateRoutineBloc>(
|
||||||
create: (context) => CreateRoutineBloc(),
|
create: (context) => CreateRoutineBloc(),
|
||||||
),
|
),
|
||||||
BlocProvider(
|
BlocProvider(create: (context) => HomeBloc()),
|
||||||
create: (context) => HomeBloc()..add(const FetchUserInfo())),
|
|
||||||
BlocProvider<VisitorPasswordBloc>(
|
BlocProvider<VisitorPasswordBloc>(
|
||||||
create: (context) => VisitorPasswordBloc(),
|
create: (context) => VisitorPasswordBloc(),
|
||||||
),
|
),
|
||||||
|
@ -7,7 +7,6 @@ import 'package:go_router/go_router.dart';
|
|||||||
import 'package:syncrow_web/firebase_options_dev.dart';
|
import 'package:syncrow_web/firebase_options_dev.dart';
|
||||||
import 'package:syncrow_web/pages/auth/bloc/auth_bloc.dart';
|
import 'package:syncrow_web/pages/auth/bloc/auth_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/home/bloc/home_bloc.dart';
|
import 'package:syncrow_web/pages/home/bloc/home_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/home/bloc/home_event.dart';
|
|
||||||
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_bloc.dart';
|
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
||||||
@ -21,7 +20,10 @@ import 'package:syncrow_web/utils/theme/theme.dart';
|
|||||||
|
|
||||||
Future<void> main() async {
|
Future<void> main() async {
|
||||||
try {
|
try {
|
||||||
const environment = String.fromEnvironment('FLAVOR', defaultValue: 'development');
|
const environment = String.fromEnvironment(
|
||||||
|
'FLAVOR',
|
||||||
|
defaultValue: 'development',
|
||||||
|
);
|
||||||
await dotenv.load(fileName: '.env.$environment');
|
await dotenv.load(fileName: '.env.$environment');
|
||||||
WidgetsFlutterBinding.ensureInitialized();
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
await Firebase.initializeApp(
|
await Firebase.initializeApp(
|
||||||
@ -39,7 +41,7 @@ class MyApp extends StatelessWidget {
|
|||||||
initialLocation: RoutesConst.auth,
|
initialLocation: RoutesConst.auth,
|
||||||
routes: AppRoutes.getRoutes(),
|
routes: AppRoutes.getRoutes(),
|
||||||
redirect: (context, state) async {
|
redirect: (context, state) async {
|
||||||
String checkToken = await AuthBloc.getTokenAndValidate();
|
final checkToken = await AuthBloc.getTokenAndValidate();
|
||||||
final loggedIn = checkToken == 'Success';
|
final loggedIn = checkToken == 'Success';
|
||||||
final goingToLogin = state.uri.toString() == RoutesConst.auth;
|
final goingToLogin = state.uri.toString() == RoutesConst.auth;
|
||||||
|
|
||||||
@ -57,7 +59,7 @@ class MyApp extends StatelessWidget {
|
|||||||
BlocProvider<CreateRoutineBloc>(
|
BlocProvider<CreateRoutineBloc>(
|
||||||
create: (context) => CreateRoutineBloc(),
|
create: (context) => CreateRoutineBloc(),
|
||||||
),
|
),
|
||||||
BlocProvider(create: (context) => HomeBloc()..add(const FetchUserInfo())),
|
BlocProvider(create: (context) => HomeBloc()),
|
||||||
BlocProvider<VisitorPasswordBloc>(
|
BlocProvider<VisitorPasswordBloc>(
|
||||||
create: (context) => VisitorPasswordBloc(),
|
create: (context) => VisitorPasswordBloc(),
|
||||||
),
|
),
|
||||||
|
@ -7,7 +7,6 @@ import 'package:go_router/go_router.dart';
|
|||||||
import 'package:syncrow_web/firebase_options_prod.dart';
|
import 'package:syncrow_web/firebase_options_prod.dart';
|
||||||
import 'package:syncrow_web/pages/auth/bloc/auth_bloc.dart';
|
import 'package:syncrow_web/pages/auth/bloc/auth_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/home/bloc/home_bloc.dart';
|
import 'package:syncrow_web/pages/home/bloc/home_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/home/bloc/home_event.dart';
|
|
||||||
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_bloc.dart';
|
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
||||||
@ -39,7 +38,7 @@ class MyApp extends StatelessWidget {
|
|||||||
initialLocation: RoutesConst.auth,
|
initialLocation: RoutesConst.auth,
|
||||||
routes: AppRoutes.getRoutes(),
|
routes: AppRoutes.getRoutes(),
|
||||||
redirect: (context, state) async {
|
redirect: (context, state) async {
|
||||||
String checkToken = await AuthBloc.getTokenAndValidate();
|
final checkToken = await AuthBloc.getTokenAndValidate();
|
||||||
final loggedIn = checkToken == 'Success';
|
final loggedIn = checkToken == 'Success';
|
||||||
final goingToLogin = state.uri.toString() == RoutesConst.auth;
|
final goingToLogin = state.uri.toString() == RoutesConst.auth;
|
||||||
|
|
||||||
@ -57,7 +56,7 @@ class MyApp extends StatelessWidget {
|
|||||||
BlocProvider<CreateRoutineBloc>(
|
BlocProvider<CreateRoutineBloc>(
|
||||||
create: (context) => CreateRoutineBloc(),
|
create: (context) => CreateRoutineBloc(),
|
||||||
),
|
),
|
||||||
BlocProvider(create: (context) => HomeBloc()..add(const FetchUserInfo())),
|
BlocProvider(create: (context) => HomeBloc()),
|
||||||
BlocProvider<VisitorPasswordBloc>(
|
BlocProvider<VisitorPasswordBloc>(
|
||||||
create: (context) => VisitorPasswordBloc(),
|
create: (context) => VisitorPasswordBloc(),
|
||||||
),
|
),
|
||||||
|
@ -13,29 +13,32 @@ import 'package:syncrow_web/pages/space_tree/bloc/space_tree_event.dart';
|
|||||||
import 'package:syncrow_web/services/home_api.dart';
|
import 'package:syncrow_web/services/home_api.dart';
|
||||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
import 'package:syncrow_web/utils/constants/routes_const.dart';
|
import 'package:syncrow_web/utils/constants/routes_const.dart';
|
||||||
import 'package:syncrow_web/utils/navigation_service.dart';
|
|
||||||
|
|
||||||
class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
||||||
UserModel? user;
|
UserModel? user;
|
||||||
String terms = '';
|
String terms = '';
|
||||||
String policy = '';
|
String policy = '';
|
||||||
|
|
||||||
HomeBloc() : super((HomeInitial())) {
|
HomeBloc() : super(HomeInitial()) {
|
||||||
on<FetchUserInfo>(_fetchUserInfo);
|
on<FetchUserInfo>(_fetchUserInfo);
|
||||||
on<FetchTermEvent>(_fetchTerms);
|
on<FetchTermEvent>(_fetchTerms);
|
||||||
on<FetchPolicyEvent>(_fetchPolicy);
|
on<FetchPolicyEvent>(_fetchPolicy);
|
||||||
on<ConfirmUserAgreementEvent>(_confirmUserAgreement);
|
on<ConfirmUserAgreementEvent>(_confirmUserAgreement);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future _fetchUserInfo(FetchUserInfo event, Emitter<HomeState> emit) async {
|
Future<void> _fetchUserInfo(
|
||||||
|
FetchUserInfo event,
|
||||||
|
Emitter<HomeState> emit,
|
||||||
|
) async {
|
||||||
try {
|
try {
|
||||||
var uuid =
|
final uuid =
|
||||||
await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
|
await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
|
||||||
user = await HomeApi().fetchUserInfo(uuid);
|
if (uuid != null) {
|
||||||
|
user = await HomeApi().fetchUserInfo(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
if (user != null && user!.project != null) {
|
if (user != null && user?.project != null) {
|
||||||
await ProjectManager.setProjectUUID(user!.project!.uuid);
|
await ProjectManager.setProjectUUID(user!.project!.uuid);
|
||||||
|
|
||||||
}
|
}
|
||||||
add(FetchTermEvent());
|
add(FetchTermEvent());
|
||||||
add(FetchPolicyEvent());
|
add(FetchPolicyEvent());
|
||||||
@ -46,7 +49,7 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future _fetchTerms(FetchTermEvent event, Emitter<HomeState> emit) async {
|
Future<void> _fetchTerms(FetchTermEvent event, Emitter<HomeState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingHome());
|
emit(LoadingHome());
|
||||||
terms = await HomeApi().fetchTerms();
|
terms = await HomeApi().fetchTerms();
|
||||||
@ -56,22 +59,22 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future _fetchPolicy(FetchPolicyEvent event, Emitter<HomeState> emit) async {
|
Future<void> _fetchPolicy(FetchPolicyEvent event, Emitter<HomeState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingHome());
|
emit(LoadingHome());
|
||||||
policy = await HomeApi().fetchPolicy();
|
policy = await HomeApi().fetchPolicy();
|
||||||
emit(HomeInitial());
|
emit(HomeInitial());
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugPrint("Error fetching policy: $e");
|
debugPrint('Error fetching policy: $e');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future _confirmUserAgreement(
|
Future<void> _confirmUserAgreement(
|
||||||
ConfirmUserAgreementEvent event, Emitter<HomeState> emit) async {
|
ConfirmUserAgreementEvent event, Emitter<HomeState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(LoadingHome());
|
emit(LoadingHome());
|
||||||
var uuid =
|
final uuid =
|
||||||
await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
|
await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
|
||||||
policy = await HomeApi().confirmUserAgreements(uuid);
|
policy = await HomeApi().confirmUserAgreements(uuid);
|
||||||
emit(PolicyAgreement());
|
emit(PolicyAgreement());
|
||||||
@ -80,7 +83,7 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<HomeItemModel> homeItems = [
|
final List<HomeItemModel> homeItems = [
|
||||||
HomeItemModel(
|
HomeItemModel(
|
||||||
title: 'Access Management',
|
title: 'Access Management',
|
||||||
icon: Assets.accessIcon,
|
icon: Assets.accessIcon,
|
||||||
|
@ -1,11 +1,25 @@
|
|||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/home/bloc/home_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/home/bloc/home_event.dart';
|
||||||
import 'package:syncrow_web/pages/home/view/home_page_mobile.dart';
|
import 'package:syncrow_web/pages/home/view/home_page_mobile.dart';
|
||||||
import 'package:syncrow_web/pages/home/view/home_page_web.dart';
|
import 'package:syncrow_web/pages/home/view/home_page_web.dart';
|
||||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||||
|
|
||||||
class HomePage extends StatelessWidget with HelperResponsiveLayout {
|
class HomePage extends StatefulWidget {
|
||||||
const HomePage({super.key});
|
const HomePage({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<HomePage> createState() => _HomePageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _HomePageState extends State<HomePage> with HelperResponsiveLayout{
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
context.read<HomeBloc>().add(const FetchUserInfo());
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final isSmallScreen = isSmallScreenSize(context);
|
final isSmallScreen = isSmallScreenSize(context);
|
||||||
|
@ -1419,15 +1419,17 @@ Future<void> _onLoadScenes(
|
|||||||
event.automationId, event.automationStatusUpdate, projectId);
|
event.automationId, event.automationStatusUpdate, projectId);
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
final updatedAutomations = await SceneApi.getAutomationByUnitId(
|
// await SceneApi.getAutomationByUnitId(
|
||||||
event.automationStatusUpdate.spaceUuid,
|
// event.automationStatusUpdate.spaceUuid,
|
||||||
event.communityId,
|
// event.communityId,
|
||||||
projectId);
|
// projectId);
|
||||||
|
|
||||||
// Remove from loading set safely
|
// Remove from loading set safely
|
||||||
|
|
||||||
final updatedLoadingIds = {...state.loadingAutomationIds!}
|
final updatedLoadingIds = {...state.loadingAutomationIds!}
|
||||||
..remove(event.automationId);
|
..remove(event.automationId);
|
||||||
|
final updatedAutomations = changeItemStateOnToggelingSceen(
|
||||||
|
state.automations, event.automationId);
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
automations: updatedAutomations,
|
automations: updatedAutomations,
|
||||||
loadingAutomationIds: updatedLoadingIds,
|
loadingAutomationIds: updatedLoadingIds,
|
||||||
@ -1449,4 +1451,24 @@ Future<void> _onLoadScenes(
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<ScenesModel> changeItemStateOnToggelingSceen(
|
||||||
|
List<ScenesModel> oldSceen, String automationId) {
|
||||||
|
return oldSceen.map((scene) {
|
||||||
|
if (scene.id == automationId) {
|
||||||
|
return ScenesModel(
|
||||||
|
id: scene.id,
|
||||||
|
sceneTuyaId: scene.sceneTuyaId,
|
||||||
|
name: scene.name,
|
||||||
|
status: scene.status == 'enable' ? 'disable' : 'enable',
|
||||||
|
type: scene.type,
|
||||||
|
spaceName: scene.spaceName,
|
||||||
|
spaceId: scene.spaceId,
|
||||||
|
communityId: scene.communityId,
|
||||||
|
icon: scene.icon,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return scene;
|
||||||
|
}).toList();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/models/community_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/params/load_communities_param.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/services/communities_service.dart';
|
||||||
|
import 'package:syncrow_web/services/api/api_exception.dart';
|
||||||
|
import 'package:syncrow_web/services/api/http_service.dart';
|
||||||
|
|
||||||
|
class RemoteCommunitiesService implements CommunitiesService {
|
||||||
|
const RemoteCommunitiesService(this._httpService);
|
||||||
|
|
||||||
|
final HTTPService _httpService;
|
||||||
|
|
||||||
|
static const _defaultErrorMessage = 'Failed to load communities';
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<List<CommunityModel>> getCommunity(LoadCommunitiesParam param) async {
|
||||||
|
try {
|
||||||
|
return _httpService.get(
|
||||||
|
path: '/api/communities/',
|
||||||
|
expectedResponseModel: (json) => (json as List<dynamic>)
|
||||||
|
.map((e) => CommunityModel.fromJson(e as Map<String, dynamic>))
|
||||||
|
.toList(),
|
||||||
|
);
|
||||||
|
} on DioException catch (e) {
|
||||||
|
final message = e.response?.data as Map<String, dynamic>?;
|
||||||
|
final error = message?['error'] as Map<String, dynamic>?;
|
||||||
|
final errorMessage = error?['error'] as String? ?? '';
|
||||||
|
throw APIException(errorMessage);
|
||||||
|
} catch (e) {
|
||||||
|
final formattedErrorMessage = [_defaultErrorMessage, '$e'].join(': ');
|
||||||
|
throw APIException(formattedErrorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/models/space_model.dart';
|
||||||
|
|
||||||
|
class CommunityModel extends Equatable {
|
||||||
|
final String uuid;
|
||||||
|
final String name;
|
||||||
|
final List<SpaceModel> spaces;
|
||||||
|
|
||||||
|
const CommunityModel({
|
||||||
|
required this.uuid,
|
||||||
|
required this.name,
|
||||||
|
required this.spaces,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory CommunityModel.fromJson(Map<String, dynamic> json) {
|
||||||
|
return CommunityModel(
|
||||||
|
uuid: json['uuid'] as String,
|
||||||
|
name: json['name'] as String,
|
||||||
|
spaces: (json['spaces'] as List<dynamic>)
|
||||||
|
.map((e) => SpaceModel.fromJson(e as Map<String, dynamic>))
|
||||||
|
.toList(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [uuid, name, spaces];
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
import 'package:equatable/equatable.dart';
|
||||||
|
|
||||||
|
class SpaceModel extends Equatable {
|
||||||
|
final String uuid;
|
||||||
|
final String spaceName;
|
||||||
|
final String icon;
|
||||||
|
final List<SpaceModel> children;
|
||||||
|
|
||||||
|
const SpaceModel({
|
||||||
|
required this.uuid,
|
||||||
|
required this.spaceName,
|
||||||
|
required this.icon,
|
||||||
|
required this.children,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory SpaceModel.fromJson(Map<String, dynamic> json) {
|
||||||
|
return SpaceModel(
|
||||||
|
uuid: json['uuid'] as String,
|
||||||
|
spaceName: json['spaceName'] as String,
|
||||||
|
icon: json['icon'] as String,
|
||||||
|
children: (json['children'] as List<dynamic>?)
|
||||||
|
?.map((e) => SpaceModel.fromJson(e as Map<String, dynamic>))
|
||||||
|
.toList() ??
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [uuid, spaceName, icon, children];
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
class LoadCommunitiesParam {
|
||||||
|
const LoadCommunitiesParam();
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/models/community_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/params/load_communities_param.dart';
|
||||||
|
|
||||||
|
abstract class CommunitiesService {
|
||||||
|
Future<List<CommunityModel>> getCommunity(LoadCommunitiesParam param);
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/models/community_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/params/load_communities_param.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/services/communities_service.dart';
|
||||||
|
import 'package:syncrow_web/services/api/api_exception.dart';
|
||||||
|
|
||||||
|
part 'communities_event.dart';
|
||||||
|
part 'communities_state.dart';
|
||||||
|
|
||||||
|
class CommunitiesBloc extends Bloc<CommunitiesEvent, CommunitiesState> {
|
||||||
|
CommunitiesBloc({
|
||||||
|
required CommunitiesService communitiesService,
|
||||||
|
}) : _communitiesService = communitiesService,
|
||||||
|
super(const CommunitiesState()) {
|
||||||
|
on<LoadCommunities>(_onLoadCommunities);
|
||||||
|
}
|
||||||
|
|
||||||
|
final CommunitiesService _communitiesService;
|
||||||
|
|
||||||
|
Future<void> _onLoadCommunities(
|
||||||
|
LoadCommunities event,
|
||||||
|
Emitter<CommunitiesState> emit,
|
||||||
|
) async {
|
||||||
|
try {
|
||||||
|
emit(const CommunitiesState(status: CommunitiesStatus.loading));
|
||||||
|
final communities = await _communitiesService.getCommunity(event.param);
|
||||||
|
emit(
|
||||||
|
CommunitiesState(
|
||||||
|
status: CommunitiesStatus.success,
|
||||||
|
communities: communities,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} on APIException catch (e) {
|
||||||
|
emit(
|
||||||
|
CommunitiesState(
|
||||||
|
status: CommunitiesStatus.failure,
|
||||||
|
errorMessage: e.message,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
emit(
|
||||||
|
CommunitiesState(
|
||||||
|
status: CommunitiesStatus.failure,
|
||||||
|
errorMessage: e.toString(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
part of 'communities_bloc.dart';
|
||||||
|
|
||||||
|
sealed class CommunitiesEvent extends Equatable {
|
||||||
|
const CommunitiesEvent();
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [];
|
||||||
|
}
|
||||||
|
|
||||||
|
class LoadCommunities extends CommunitiesEvent {
|
||||||
|
const LoadCommunities(this.param);
|
||||||
|
|
||||||
|
final LoadCommunitiesParam param;
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [param];
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
part of 'communities_bloc.dart';
|
||||||
|
|
||||||
|
enum CommunitiesStatus { initial, loading, success, failure }
|
||||||
|
|
||||||
|
final class CommunitiesState extends Equatable {
|
||||||
|
const CommunitiesState({
|
||||||
|
this.status = CommunitiesStatus.initial,
|
||||||
|
this.communities = const [],
|
||||||
|
this.errorMessage,
|
||||||
|
});
|
||||||
|
|
||||||
|
final CommunitiesStatus status;
|
||||||
|
final List<CommunityModel> communities;
|
||||||
|
final String? errorMessage;
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [status, communities, errorMessage];
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/models/community_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/create_community/domain/param/create_community_param.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/create_community/domain/services/create_community_service.dart';
|
||||||
|
import 'package:syncrow_web/services/api/api_exception.dart';
|
||||||
|
import 'package:syncrow_web/services/api/http_service.dart';
|
||||||
|
|
||||||
|
class RemoteCreateCommunityService implements CreateCommunityService {
|
||||||
|
const RemoteCreateCommunityService(this._httpService);
|
||||||
|
|
||||||
|
final HTTPService _httpService;
|
||||||
|
|
||||||
|
static const _defaultErrorMessage = 'Failed to create community';
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<CommunityModel> createCommunity(CreateCommunityParam param) async {
|
||||||
|
try {
|
||||||
|
final response = await _httpService.post(
|
||||||
|
path: 'endpoint',
|
||||||
|
expectedResponseModel: (data) => CommunityModel.fromJson(
|
||||||
|
data as Map<String, dynamic>,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return response;
|
||||||
|
} on DioException catch (e) {
|
||||||
|
final message = e.response?.data as Map<String, dynamic>?;
|
||||||
|
final error = message?['error'] as Map<String, dynamic>?;
|
||||||
|
final errorMessage = error?['error'] as String? ?? '';
|
||||||
|
final formattedErrorMessage = [
|
||||||
|
_defaultErrorMessage,
|
||||||
|
errorMessage,
|
||||||
|
].join(': ');
|
||||||
|
throw APIException(formattedErrorMessage);
|
||||||
|
} catch (e) {
|
||||||
|
final formattedErrorMessage = [_defaultErrorMessage, '$e'].join(': ');
|
||||||
|
throw APIException(formattedErrorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
import 'package:equatable/equatable.dart';
|
||||||
|
|
||||||
|
class CreateCommunityParam extends Equatable {
|
||||||
|
const CreateCommunityParam({required this.name});
|
||||||
|
|
||||||
|
final String name;
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [name];
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/models/community_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/create_community/domain/param/create_community_param.dart';
|
||||||
|
|
||||||
|
abstract class CreateCommunityService {
|
||||||
|
Future<CommunityModel> createCommunity(CreateCommunityParam param);
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
import 'package:bloc/bloc.dart';
|
||||||
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/models/community_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/create_community/domain/param/create_community_param.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/create_community/domain/services/create_community_service.dart';
|
||||||
|
import 'package:syncrow_web/services/api/api_exception.dart';
|
||||||
|
|
||||||
|
part 'create_community_event.dart';
|
||||||
|
part 'create_community_state.dart';
|
||||||
|
|
||||||
|
class CreateCommunityBloc extends Bloc<CreateCommunityEvent, CreateCommunityState> {
|
||||||
|
final CreateCommunityService _createCommunityService;
|
||||||
|
|
||||||
|
CreateCommunityBloc(
|
||||||
|
this._createCommunityService,
|
||||||
|
) : super(CreateCommunityInitial()) {
|
||||||
|
on<CreateCommunity>(_onCreateCommunity);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _onCreateCommunity(
|
||||||
|
CreateCommunity event,
|
||||||
|
Emitter<CreateCommunityState> emit,
|
||||||
|
) async {
|
||||||
|
emit(CreateCommunityLoading());
|
||||||
|
try {
|
||||||
|
final createdCommunity = await _createCommunityService.createCommunity(
|
||||||
|
event.param,
|
||||||
|
);
|
||||||
|
emit(CreateCommunitySuccess(createdCommunity));
|
||||||
|
} on APIException catch (e) {
|
||||||
|
emit(CreateCommunityFailure(e.message));
|
||||||
|
} catch (e) {
|
||||||
|
emit(CreateCommunityFailure(e.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
part of 'create_community_bloc.dart';
|
||||||
|
|
||||||
|
sealed class CreateCommunityEvent extends Equatable {
|
||||||
|
const CreateCommunityEvent();
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [];
|
||||||
|
}
|
||||||
|
|
||||||
|
final class CreateCommunity extends CreateCommunityEvent {
|
||||||
|
const CreateCommunity(this.param);
|
||||||
|
|
||||||
|
final CreateCommunityParam param;
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [param];
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
part of 'create_community_bloc.dart';
|
||||||
|
|
||||||
|
sealed class CreateCommunityState extends Equatable {
|
||||||
|
const CreateCommunityState();
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [];
|
||||||
|
}
|
||||||
|
|
||||||
|
final class CreateCommunityInitial extends CreateCommunityState {}
|
||||||
|
|
||||||
|
final class CreateCommunityLoading extends CreateCommunityState {}
|
||||||
|
|
||||||
|
final class CreateCommunitySuccess extends CreateCommunityState {
|
||||||
|
const CreateCommunitySuccess(this.community);
|
||||||
|
|
||||||
|
final CommunityModel community;
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [community];
|
||||||
|
}
|
||||||
|
|
||||||
|
final class CreateCommunityFailure extends CreateCommunityState {
|
||||||
|
final String message;
|
||||||
|
|
||||||
|
const CreateCommunityFailure(this.message);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [message];
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
import 'package:dio/dio.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';
|
||||||
|
import 'package:syncrow_web/services/api/http_service.dart';
|
||||||
|
|
||||||
|
class RemoteProductsService implements ProductsService {
|
||||||
|
const RemoteProductsService(this._httpService);
|
||||||
|
|
||||||
|
final HTTPService _httpService;
|
||||||
|
|
||||||
|
static const _defaultErrorMessage = 'Failed to load devices';
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<List<Product>> getProducts(LoadProductsParam param) async {
|
||||||
|
try {
|
||||||
|
final response = await _httpService.get(
|
||||||
|
path: 'devices',
|
||||||
|
queryParameters: {
|
||||||
|
'spaceUuid': param.spaceUuid,
|
||||||
|
if (param.type != null) 'type': param.type,
|
||||||
|
if (param.status != null) 'status': param.status,
|
||||||
|
},
|
||||||
|
expectedResponseModel: (data) {
|
||||||
|
return (data as List)
|
||||||
|
.map((e) => Product.fromJson(e as Map<String, dynamic>))
|
||||||
|
.toList();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return response;
|
||||||
|
} on DioException catch (e) {
|
||||||
|
final message = e.response?.data as Map<String, dynamic>?;
|
||||||
|
final error = message?['error'] as Map<String, dynamic>?;
|
||||||
|
final errorMessage = error?['error'] as String? ?? '';
|
||||||
|
final formattedErrorMessage = [
|
||||||
|
_defaultErrorMessage,
|
||||||
|
errorMessage,
|
||||||
|
].join(': ');
|
||||||
|
throw APIException(formattedErrorMessage);
|
||||||
|
} catch (e) {
|
||||||
|
final formattedErrorMessage = [_defaultErrorMessage, '$e'].join(': ');
|
||||||
|
throw APIException(formattedErrorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
import 'package:equatable/equatable.dart';
|
||||||
|
|
||||||
|
class Product extends Equatable {
|
||||||
|
final String uuid;
|
||||||
|
final String name;
|
||||||
|
|
||||||
|
const Product({
|
||||||
|
required this.uuid,
|
||||||
|
required this.name,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory Product.fromJson(Map<String, dynamic> json) {
|
||||||
|
return Product(
|
||||||
|
uuid: json['uuid'] as String,
|
||||||
|
name: json['name'] as String,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
return {
|
||||||
|
'uuid': uuid,
|
||||||
|
'name': name,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [uuid, name];
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
class LoadProductsParam {
|
||||||
|
final String spaceUuid;
|
||||||
|
final String? type;
|
||||||
|
final String? status;
|
||||||
|
|
||||||
|
const LoadProductsParam({
|
||||||
|
required this.spaceUuid,
|
||||||
|
this.type,
|
||||||
|
this.status,
|
||||||
|
});
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
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<List<Product>> getProducts(LoadProductsParam param);
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
import 'package:bloc/bloc.dart';
|
||||||
|
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/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';
|
||||||
|
|
||||||
|
part 'products_event.dart';
|
||||||
|
part 'products_state.dart';
|
||||||
|
|
||||||
|
class ProductsBloc extends Bloc<ProductsEvent, ProductsState> {
|
||||||
|
final ProductsService _deviceService;
|
||||||
|
|
||||||
|
ProductsBloc(this._deviceService) : super(ProductsInitial()) {
|
||||||
|
on<LoadProducts>(_onLoadProducts);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _onLoadProducts(
|
||||||
|
LoadProducts event,
|
||||||
|
Emitter<ProductsState> emit,
|
||||||
|
) async {
|
||||||
|
emit(ProductsLoading());
|
||||||
|
try {
|
||||||
|
final devices = await _deviceService.getProducts(event.param);
|
||||||
|
emit(ProductsLoaded(devices));
|
||||||
|
} on APIException catch (e) {
|
||||||
|
emit(ProductsFailure(e.message));
|
||||||
|
} catch (e) {
|
||||||
|
emit(ProductsFailure(e.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
part of 'products_bloc.dart';
|
||||||
|
|
||||||
|
sealed class ProductsEvent extends Equatable {
|
||||||
|
const ProductsEvent();
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [];
|
||||||
|
}
|
||||||
|
|
||||||
|
final class LoadProducts extends ProductsEvent {
|
||||||
|
const LoadProducts(this.param);
|
||||||
|
|
||||||
|
final LoadProductsParam param;
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [param];
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
part of 'products_bloc.dart';
|
||||||
|
|
||||||
|
sealed class ProductsState extends Equatable {
|
||||||
|
const ProductsState();
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [];
|
||||||
|
}
|
||||||
|
|
||||||
|
final class ProductsInitial extends ProductsState {}
|
||||||
|
|
||||||
|
final class ProductsLoading extends ProductsState {}
|
||||||
|
|
||||||
|
final class ProductsLoaded extends ProductsState {
|
||||||
|
final List<Product> products;
|
||||||
|
|
||||||
|
const ProductsLoaded(this.products);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [products];
|
||||||
|
}
|
||||||
|
|
||||||
|
final class ProductsFailure extends ProductsState {
|
||||||
|
final String message;
|
||||||
|
|
||||||
|
const ProductsFailure(this.message);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [message];
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/domain/models/space_details_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/domain/params/load_spaces_param.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/domain/services/space_details_service.dart';
|
||||||
|
import 'package:syncrow_web/services/api/api_exception.dart';
|
||||||
|
import 'package:syncrow_web/services/api/http_service.dart';
|
||||||
|
|
||||||
|
class RemoteSpaceDetailsService implements SpaceDetailsService {
|
||||||
|
final HTTPService _httpService;
|
||||||
|
|
||||||
|
RemoteSpaceDetailsService({
|
||||||
|
required HTTPService httpService,
|
||||||
|
}) : _httpService = httpService;
|
||||||
|
|
||||||
|
static const _defaultErrorMessage = 'Failed to load space details';
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<SpaceDetailsModel> getSpaceDetails(LoadSpacesParam param) async {
|
||||||
|
try {
|
||||||
|
final response = await _httpService.get(
|
||||||
|
path: 'endpoint',
|
||||||
|
expectedResponseModel: (data) {
|
||||||
|
return SpaceDetailsModel.fromJson(data as Map<String, dynamic>);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return response;
|
||||||
|
} on DioException catch (e) {
|
||||||
|
final message = e.response?.data as Map<String, dynamic>?;
|
||||||
|
final error = message?['error'] as Map<String, dynamic>?;
|
||||||
|
final errorMessage = error?['error'] as String? ?? '';
|
||||||
|
final formattedErrorMessage = [_defaultErrorMessage, errorMessage].join(
|
||||||
|
': ',
|
||||||
|
);
|
||||||
|
throw APIException(formattedErrorMessage);
|
||||||
|
} catch (e) {
|
||||||
|
final formattedErrorMessage = [_defaultErrorMessage, '$e'].join(': ');
|
||||||
|
throw APIException(formattedErrorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,108 @@
|
|||||||
|
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;
|
||||||
|
final String spaceName;
|
||||||
|
final String icon;
|
||||||
|
final List<ProductAllocation> productAllocations;
|
||||||
|
final List<Subspace> subspaces;
|
||||||
|
|
||||||
|
const SpaceDetailsModel({
|
||||||
|
required this.uuid,
|
||||||
|
required this.spaceName,
|
||||||
|
required this.icon,
|
||||||
|
required this.productAllocations,
|
||||||
|
required this.subspaces,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory SpaceDetailsModel.fromJson(Map<String, dynamic> json) {
|
||||||
|
return SpaceDetailsModel(
|
||||||
|
uuid: json['uuid'] as String,
|
||||||
|
spaceName: json['spaceName'] as String,
|
||||||
|
icon: json['icon'] as String,
|
||||||
|
productAllocations: (json['productAllocations'] as List)
|
||||||
|
.map((e) => ProductAllocation.fromJson(e as Map<String, dynamic>))
|
||||||
|
.toList(),
|
||||||
|
subspaces: (json['subspaces'] as List)
|
||||||
|
.map((e) => Subspace.fromJson(e as Map<String, dynamic>))
|
||||||
|
.toList(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
return {
|
||||||
|
'uuid': uuid,
|
||||||
|
'spaceName': spaceName,
|
||||||
|
'icon': icon,
|
||||||
|
'productAllocations': productAllocations.map((e) => e.toJson()).toList(),
|
||||||
|
'subspaces': subspaces.map((e) => e.toJson()).toList(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [uuid, spaceName, icon, productAllocations, subspaces];
|
||||||
|
}
|
||||||
|
|
||||||
|
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<String, dynamic> json) {
|
||||||
|
return ProductAllocation(
|
||||||
|
product: Product.fromJson(json['product'] as Map<String, dynamic>),
|
||||||
|
tag: Tag.fromJson(json['tag'] as Map<String, dynamic>),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
return {
|
||||||
|
'product': product.toJson(),
|
||||||
|
'tag': tag.toJson(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [product, tag];
|
||||||
|
}
|
||||||
|
|
||||||
|
class Subspace extends Equatable {
|
||||||
|
final String uuid;
|
||||||
|
final String name;
|
||||||
|
final List<ProductAllocation> productAllocations;
|
||||||
|
|
||||||
|
const Subspace({
|
||||||
|
required this.uuid,
|
||||||
|
required this.name,
|
||||||
|
required this.productAllocations,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory Subspace.fromJson(Map<String, dynamic> json) {
|
||||||
|
return Subspace(
|
||||||
|
uuid: json['uuid'] as String,
|
||||||
|
name: json['name'] as String,
|
||||||
|
productAllocations: (json['productAllocations'] as List)
|
||||||
|
.map((e) => ProductAllocation.fromJson(e as Map<String, dynamic>))
|
||||||
|
.toList(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
return {
|
||||||
|
'uuid': uuid,
|
||||||
|
'name': name,
|
||||||
|
'productAllocations': productAllocations.map((e) => e.toJson()).toList(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [uuid, name, productAllocations];
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
class LoadSpacesParam {
|
||||||
|
const LoadSpacesParam();
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/domain/models/space_details_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/domain/params/load_spaces_param.dart';
|
||||||
|
|
||||||
|
abstract class SpaceDetailsService {
|
||||||
|
Future<SpaceDetailsModel> getSpaceDetails(LoadSpacesParam param);
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
import 'package:bloc/bloc.dart';
|
||||||
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/domain/models/space_details_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/domain/params/load_spaces_param.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/domain/services/space_details_service.dart';
|
||||||
|
import 'package:syncrow_web/services/api/api_exception.dart';
|
||||||
|
|
||||||
|
part 'space_details_event.dart';
|
||||||
|
part 'space_details_state.dart';
|
||||||
|
|
||||||
|
class SpaceDetailsBloc extends Bloc<SpaceDetailsEvent, SpaceDetailsState> {
|
||||||
|
final SpaceDetailsService _spaceDetailsService;
|
||||||
|
|
||||||
|
SpaceDetailsBloc(this._spaceDetailsService) : super(SpaceDetailsInitial()) {
|
||||||
|
on<LoadSpaceDetails>(_onLoadSpaceDetails);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _onLoadSpaceDetails(
|
||||||
|
LoadSpaceDetails event,
|
||||||
|
Emitter<SpaceDetailsState> emit,
|
||||||
|
) async {
|
||||||
|
emit(SpaceDetailsLoading());
|
||||||
|
try {
|
||||||
|
final spaceDetails = await _spaceDetailsService.getSpaceDetails(
|
||||||
|
event.param,
|
||||||
|
);
|
||||||
|
emit(SpaceDetailsLoaded(spaceDetails));
|
||||||
|
} on APIException catch (e) {
|
||||||
|
emit(SpaceDetailsFailure(e.message));
|
||||||
|
} catch (e) {
|
||||||
|
emit(SpaceDetailsFailure(e.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
part of 'space_details_bloc.dart';
|
||||||
|
|
||||||
|
sealed class SpaceDetailsEvent extends Equatable {
|
||||||
|
const SpaceDetailsEvent();
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [];
|
||||||
|
}
|
||||||
|
|
||||||
|
class LoadSpaceDetails extends SpaceDetailsEvent {
|
||||||
|
const LoadSpaceDetails(this.param);
|
||||||
|
|
||||||
|
final LoadSpacesParam param;
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [param];
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
part of 'space_details_bloc.dart';
|
||||||
|
|
||||||
|
sealed class SpaceDetailsState extends Equatable {
|
||||||
|
const SpaceDetailsState();
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [];
|
||||||
|
}
|
||||||
|
|
||||||
|
final class SpaceDetailsInitial extends SpaceDetailsState {}
|
||||||
|
|
||||||
|
final class SpaceDetailsLoading extends SpaceDetailsState {}
|
||||||
|
|
||||||
|
final class SpaceDetailsLoaded extends SpaceDetailsState {
|
||||||
|
final SpaceDetailsModel spaceDetails;
|
||||||
|
|
||||||
|
const SpaceDetailsLoaded(this.spaceDetails);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [spaceDetails];
|
||||||
|
}
|
||||||
|
|
||||||
|
final class SpaceDetailsFailure extends SpaceDetailsState {
|
||||||
|
final String message;
|
||||||
|
|
||||||
|
const SpaceDetailsFailure(this.message);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [message];
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
import 'package:dio/dio.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';
|
||||||
|
import 'package:syncrow_web/services/api/http_service.dart';
|
||||||
|
import 'package:syncrow_web/utils/constants/api_const.dart';
|
||||||
|
|
||||||
|
final class RemoteTagsService implements TagsService {
|
||||||
|
const RemoteTagsService(this._httpService);
|
||||||
|
|
||||||
|
final HTTPService _httpService;
|
||||||
|
|
||||||
|
static const _defaultErrorMessage = 'Failed to load tags';
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<List<Tag>> loadTags(LoadTagsParam param) async {
|
||||||
|
if (param.projectUuid == null) {
|
||||||
|
throw Exception('Project UUID is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
final response = await _httpService.get(
|
||||||
|
path: ApiEndpoints.listTags.replaceAll(
|
||||||
|
'{projectUuid}',
|
||||||
|
param.projectUuid!,
|
||||||
|
),
|
||||||
|
expectedResponseModel: (json) {
|
||||||
|
final result = json as Map<String, dynamic>;
|
||||||
|
final data = result['data'] as List<dynamic>;
|
||||||
|
return data.map((e) => Tag.fromJson(e as Map<String, dynamic>)).toList();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return response;
|
||||||
|
} on DioException catch (e) {
|
||||||
|
final message = e.response?.data as Map<String, dynamic>?;
|
||||||
|
final error = message?['error'] as Map<String, dynamic>?;
|
||||||
|
final errorMessage = error?['error'] as String? ?? '';
|
||||||
|
final formattedErrorMessage = [
|
||||||
|
_defaultErrorMessage,
|
||||||
|
errorMessage,
|
||||||
|
].join(': ');
|
||||||
|
throw APIException(formattedErrorMessage);
|
||||||
|
} catch (e) {
|
||||||
|
final formattedErrorMessage = [_defaultErrorMessage, '$e'].join(': ');
|
||||||
|
throw APIException(formattedErrorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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<String, dynamic> json) {
|
||||||
|
return Tag(
|
||||||
|
uuid: json['uuid'] as String,
|
||||||
|
name: json['name'] as String,
|
||||||
|
createdAt: json['createdAt'] as String,
|
||||||
|
updatedAt: json['updatedAt'] as String,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
return {
|
||||||
|
'uuid': uuid,
|
||||||
|
'name': name,
|
||||||
|
'createdAt': createdAt,
|
||||||
|
'updatedAt': updatedAt,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [uuid, name, createdAt, updatedAt];
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
class LoadTagsParam {
|
||||||
|
final String? projectUuid;
|
||||||
|
|
||||||
|
const LoadTagsParam({this.projectUuid});
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
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<List<Tag>> loadTags(LoadTagsParam param);
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
import 'package:bloc/bloc.dart';
|
||||||
|
import 'package:equatable/equatable.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';
|
||||||
|
|
||||||
|
part 'tags_event.dart';
|
||||||
|
part 'tags_state.dart';
|
||||||
|
|
||||||
|
class TagsBloc extends Bloc<TagsEvent, TagsState> {
|
||||||
|
final TagsService _tagsService;
|
||||||
|
|
||||||
|
TagsBloc(this._tagsService) : super(TagsInitial()) {
|
||||||
|
on<LoadTags>(_onLoadTags);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _onLoadTags(
|
||||||
|
LoadTags event,
|
||||||
|
Emitter<TagsState> emit,
|
||||||
|
) async {
|
||||||
|
emit(TagsLoading());
|
||||||
|
try {
|
||||||
|
final tags = await _tagsService.loadTags(event.param);
|
||||||
|
emit(TagsLoaded(tags));
|
||||||
|
} on APIException catch (e) {
|
||||||
|
emit(TagsFailure(e.message));
|
||||||
|
} catch (e) {
|
||||||
|
emit(TagsFailure(e.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
part of 'tags_bloc.dart';
|
||||||
|
|
||||||
|
abstract class TagsEvent extends Equatable {
|
||||||
|
const TagsEvent();
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [];
|
||||||
|
}
|
||||||
|
|
||||||
|
class LoadTags extends TagsEvent {
|
||||||
|
final LoadTagsParam param;
|
||||||
|
|
||||||
|
const LoadTags(this.param);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [param];
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
part of 'tags_bloc.dart';
|
||||||
|
|
||||||
|
abstract class TagsState extends Equatable {
|
||||||
|
const TagsState();
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [];
|
||||||
|
}
|
||||||
|
|
||||||
|
class TagsInitial extends TagsState {}
|
||||||
|
|
||||||
|
class TagsLoading extends TagsState {}
|
||||||
|
|
||||||
|
class TagsLoaded extends TagsState {
|
||||||
|
final List<Tag> tags;
|
||||||
|
|
||||||
|
const TagsLoaded(this.tags);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [tags];
|
||||||
|
}
|
||||||
|
|
||||||
|
class TagsFailure extends TagsState {
|
||||||
|
final String message;
|
||||||
|
|
||||||
|
const TagsFailure(this.message);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [message];
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/models/community_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/update_community/domain/params/update_community_param.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/update_community/domain/services/update_community_service.dart';
|
||||||
|
import 'package:syncrow_web/services/api/api_exception.dart';
|
||||||
|
import 'package:syncrow_web/services/api/http_service.dart';
|
||||||
|
|
||||||
|
class RemoteUpdateCommunityService implements UpdateCommunityService {
|
||||||
|
const RemoteUpdateCommunityService(this._httpService);
|
||||||
|
|
||||||
|
final HTTPService _httpService;
|
||||||
|
|
||||||
|
static const _defaultErrorMessage = 'Failed to update community';
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<CommunityModel> updateCommunity(UpdateCommunityParam param) async {
|
||||||
|
try {
|
||||||
|
final response = await _httpService.put(
|
||||||
|
path: 'endpoint',
|
||||||
|
expectedResponseModel: (data) => CommunityModel.fromJson(
|
||||||
|
data as Map<String, dynamic>,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return response;
|
||||||
|
} on DioException catch (e) {
|
||||||
|
final message = e.response?.data as Map<String, dynamic>?;
|
||||||
|
final error = message?['error'] as Map<String, dynamic>?;
|
||||||
|
final errorMessage = error?['error'] as String? ?? '';
|
||||||
|
final formattedErrorMessage = [
|
||||||
|
_defaultErrorMessage,
|
||||||
|
errorMessage,
|
||||||
|
].join(': ');
|
||||||
|
throw APIException(formattedErrorMessage);
|
||||||
|
} catch (e) {
|
||||||
|
final formattedErrorMessage = [_defaultErrorMessage, '$e'].join(': ');
|
||||||
|
throw APIException(formattedErrorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
import 'package:equatable/equatable.dart';
|
||||||
|
|
||||||
|
class UpdateCommunityParam extends Equatable {
|
||||||
|
const UpdateCommunityParam({required this.name});
|
||||||
|
|
||||||
|
final String name;
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [name];
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/models/community_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/update_community/domain/params/update_community_param.dart';
|
||||||
|
|
||||||
|
abstract class UpdateCommunityService {
|
||||||
|
Future<CommunityModel> updateCommunity(UpdateCommunityParam param);
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
import 'package:bloc/bloc.dart';
|
||||||
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/communities/domain/models/community_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/update_community/domain/params/update_community_param.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/update_community/domain/services/update_community_service.dart';
|
||||||
|
import 'package:syncrow_web/services/api/api_exception.dart';
|
||||||
|
|
||||||
|
part 'update_community_event.dart';
|
||||||
|
part 'update_community_state.dart';
|
||||||
|
|
||||||
|
class UpdateCommunityBloc extends Bloc<UpdateCommunityEvent, UpdateCommunityState> {
|
||||||
|
final UpdateCommunityService _updateCommunityService;
|
||||||
|
|
||||||
|
UpdateCommunityBloc(
|
||||||
|
this._updateCommunityService,
|
||||||
|
) : super(UpdateCommunityInitial()) {
|
||||||
|
on<UpdateCommunity>(_onUpdateCommunity);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _onUpdateCommunity(
|
||||||
|
UpdateCommunity event,
|
||||||
|
Emitter<UpdateCommunityState> emit,
|
||||||
|
) async {
|
||||||
|
emit(UpdateCommunityLoading());
|
||||||
|
try {
|
||||||
|
final updatedCommunity = await _updateCommunityService.updateCommunity(
|
||||||
|
event.param,
|
||||||
|
);
|
||||||
|
emit(UpdateCommunitySuccess(updatedCommunity));
|
||||||
|
} on APIException catch (e) {
|
||||||
|
emit(UpdateCommunityFailure(e.message));
|
||||||
|
} catch (e) {
|
||||||
|
emit(UpdateCommunityFailure(e.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
part of 'update_community_bloc.dart';
|
||||||
|
|
||||||
|
sealed class UpdateCommunityEvent extends Equatable {
|
||||||
|
const UpdateCommunityEvent();
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [];
|
||||||
|
}
|
||||||
|
|
||||||
|
final class UpdateCommunity extends UpdateCommunityEvent {
|
||||||
|
const UpdateCommunity(this.param);
|
||||||
|
|
||||||
|
final UpdateCommunityParam param;
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [param];
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
part of 'update_community_bloc.dart';
|
||||||
|
|
||||||
|
sealed class UpdateCommunityState extends Equatable {
|
||||||
|
const UpdateCommunityState();
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [];
|
||||||
|
}
|
||||||
|
|
||||||
|
final class UpdateCommunityInitial extends UpdateCommunityState {}
|
||||||
|
|
||||||
|
final class UpdateCommunityLoading extends UpdateCommunityState {}
|
||||||
|
|
||||||
|
final class UpdateCommunitySuccess extends UpdateCommunityState {
|
||||||
|
final CommunityModel community;
|
||||||
|
|
||||||
|
const UpdateCommunitySuccess(this.community);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [community];
|
||||||
|
}
|
||||||
|
|
||||||
|
final class UpdateCommunityFailure extends UpdateCommunityState {
|
||||||
|
final String message;
|
||||||
|
|
||||||
|
const UpdateCommunityFailure(this.message);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [message];
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/domain/models/space_details_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/update_space/domain/services/update_space_service.dart';
|
||||||
|
import 'package:syncrow_web/services/api/api_exception.dart';
|
||||||
|
import 'package:syncrow_web/services/api/http_service.dart';
|
||||||
|
|
||||||
|
class RemoteUpdateSpaceService implements UpdateSpaceService {
|
||||||
|
const RemoteUpdateSpaceService(this._httpService);
|
||||||
|
|
||||||
|
final HTTPService _httpService;
|
||||||
|
|
||||||
|
static const _defaultErrorMessage = 'Failed to update space';
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<SpaceDetailsModel> updateSpace(SpaceDetailsModel space) async {
|
||||||
|
try {
|
||||||
|
final response = await _httpService.put(
|
||||||
|
path: 'endpoint',
|
||||||
|
body: space.toJson(),
|
||||||
|
expectedResponseModel: (data) => SpaceDetailsModel.fromJson(
|
||||||
|
data as Map<String, dynamic>,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
return response;
|
||||||
|
} on DioException catch (e) {
|
||||||
|
final message = e.response?.data as Map<String, dynamic>?;
|
||||||
|
final error = message?['error'] as Map<String, dynamic>?;
|
||||||
|
final errorMessage = error?['error'] as String? ?? '';
|
||||||
|
final formattedErrorMessage = [
|
||||||
|
_defaultErrorMessage,
|
||||||
|
errorMessage,
|
||||||
|
].join(': ');
|
||||||
|
throw APIException(formattedErrorMessage);
|
||||||
|
} catch (e) {
|
||||||
|
final formattedErrorMessage = [_defaultErrorMessage, '$e'].join(': ');
|
||||||
|
throw APIException(formattedErrorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/domain/models/space_details_model.dart';
|
||||||
|
|
||||||
|
abstract class UpdateSpaceService {
|
||||||
|
Future<SpaceDetailsModel> updateSpace(SpaceDetailsModel space);
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
import 'package:bloc/bloc.dart';
|
||||||
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/space_details/domain/models/space_details_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_management_v2/modules/update_space/domain/services/update_space_service.dart';
|
||||||
|
import 'package:syncrow_web/services/api/api_exception.dart';
|
||||||
|
|
||||||
|
part 'update_space_event.dart';
|
||||||
|
part 'update_space_state.dart';
|
||||||
|
|
||||||
|
class UpdateSpaceBloc extends Bloc<UpdateSpaceEvent, UpdateSpaceState> {
|
||||||
|
final UpdateSpaceService _updateSpaceService;
|
||||||
|
|
||||||
|
UpdateSpaceBloc(this._updateSpaceService) : super(UpdateSpaceInitial()) {
|
||||||
|
on<UpdateSpace>(_onUpdateSpace);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _onUpdateSpace(
|
||||||
|
UpdateSpace event,
|
||||||
|
Emitter<UpdateSpaceState> emit,
|
||||||
|
) async {
|
||||||
|
emit(UpdateSpaceLoading());
|
||||||
|
try {
|
||||||
|
final updatedSpace = await _updateSpaceService.updateSpace(event.space);
|
||||||
|
emit(UpdateSpaceSuccess(updatedSpace));
|
||||||
|
} on APIException catch (e) {
|
||||||
|
emit(UpdateSpaceFailure(e.message));
|
||||||
|
} catch (e) {
|
||||||
|
emit(UpdateSpaceFailure(e.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
part of 'update_space_bloc.dart';
|
||||||
|
|
||||||
|
sealed class UpdateSpaceEvent extends Equatable {
|
||||||
|
const UpdateSpaceEvent();
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [];
|
||||||
|
}
|
||||||
|
|
||||||
|
final class UpdateSpace extends UpdateSpaceEvent {
|
||||||
|
const UpdateSpace(this.space);
|
||||||
|
|
||||||
|
final SpaceDetailsModel space;
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [space];
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
part of 'update_space_bloc.dart';
|
||||||
|
|
||||||
|
sealed class UpdateSpaceState extends Equatable {
|
||||||
|
const UpdateSpaceState();
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [];
|
||||||
|
}
|
||||||
|
|
||||||
|
final class UpdateSpaceInitial extends UpdateSpaceState {}
|
||||||
|
|
||||||
|
final class UpdateSpaceLoading extends UpdateSpaceState {}
|
||||||
|
|
||||||
|
final class UpdateSpaceSuccess extends UpdateSpaceState {
|
||||||
|
final SpaceDetailsModel space;
|
||||||
|
|
||||||
|
const UpdateSpaceSuccess(this.space);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [space];
|
||||||
|
}
|
||||||
|
|
||||||
|
final class UpdateSpaceFailure extends UpdateSpaceState {
|
||||||
|
final String message;
|
||||||
|
|
||||||
|
const UpdateSpaceFailure(this.message);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [message];
|
||||||
|
}
|
@ -3,14 +3,20 @@ import 'package:syncrow_web/services/api/http_service.dart';
|
|||||||
import 'package:syncrow_web/utils/constants/api_const.dart';
|
import 'package:syncrow_web/utils/constants/api_const.dart';
|
||||||
|
|
||||||
class HomeApi {
|
class HomeApi {
|
||||||
Future fetchUserInfo(userId) async {
|
Future<UserModel?> fetchUserInfo(String userId) async {
|
||||||
final response = await HTTPService().get(
|
try {
|
||||||
path: ApiEndpoints.getUser.replaceAll('{userUuid}', userId!),
|
final response = await HTTPService().get(
|
||||||
|
path: ApiEndpoints.getUser.replaceAll('{userUuid}', userId),
|
||||||
showServerMessage: true,
|
showServerMessage: true,
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
return UserModel.fromJson(json);
|
final user = UserModel.fromJson(json as Map<String, dynamic>);
|
||||||
});
|
return user;
|
||||||
return response;
|
},
|
||||||
|
);
|
||||||
|
return response;
|
||||||
|
} catch (e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future fetchTerms() async {
|
Future fetchTerms() async {
|
||||||
|
Reference in New Issue
Block a user