build_app
This commit is contained in:
parent
c206eb19d1
commit
483778e2a6
4
testrel01-dbtdt-d/authsec_mysql/mysql/wf_table/wf_table.sql
Executable file
4
testrel01-dbtdt-d/authsec_mysql/mysql/wf_table/wf_table.sql
Executable file
@ -0,0 +1,4 @@
|
||||
CREATE TABLE dbtdt.Ad6(id BIGINT NOT NULL AUTO_INCREMENT, onetoone VARCHAR(400), onetomanyextension VARCHAR(400), fileupload_fields VARCHAR(400), description VARCHAR(400), value_list_field VARCHAR(400), name VARCHAR(400), PRIMARY KEY (id));
|
||||
|
||||
CREATE TABLE dbtdt.Child(id BIGINT NOT NULL AUTO_INCREMENT, description VARCHAR(400), name VARCHAR(400), PRIMARY KEY (id));
|
||||
|
||||
@ -0,0 +1,92 @@
|
||||
import 'dart:typed_data';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
import '../../../../resources/api_constants.dart';
|
||||
import '../../../../data/network/base_network_service.dart';
|
||||
import '../../../../data/network/network_api_service.dart';
|
||||
|
||||
class Ad6ApiService {
|
||||
final String baseUrl = ApiConstants.baseUrl;
|
||||
|
||||
final BaseNetworkService _helper = NetworkApiService();
|
||||
|
||||
|
||||
|
||||
Future<List<Map<String, dynamic>>> getEntities() async {
|
||||
|
||||
try {
|
||||
final response = await _helper.getGetApiResponse('$baseUrl/Ad6/Ad6');
|
||||
final entities = (response as List).cast<Map<String, dynamic>>();
|
||||
return entities;
|
||||
} catch (e) {
|
||||
throw Exception('Failed to get all entities: $e');
|
||||
}
|
||||
}
|
||||
Future<List<Map<String, dynamic>>> getAllWithPagination(
|
||||
int page, int size) async {
|
||||
try {
|
||||
final response =
|
||||
await _helper.getGetApiResponse('$baseUrl/Ad6/Ad6/getall/page?page=$page&size=$size');
|
||||
final entities =
|
||||
(response['content'] as List).cast<Map<String, dynamic>>();
|
||||
return entities;
|
||||
} catch (e) {
|
||||
throw Exception('Failed to get all without pagination: $e');
|
||||
}
|
||||
}
|
||||
Future<Map<String, dynamic>> createEntity(
|
||||
Map<String, dynamic> entity) async {
|
||||
try {
|
||||
print("in post api$entity");
|
||||
final response =
|
||||
await _helper.getPostApiResponse('$baseUrl/Ad6/Ad6', entity);
|
||||
|
||||
print(entity);
|
||||
|
||||
// Assuming the response is a Map<String, dynamic>
|
||||
Map<String, dynamic> responseData = response;
|
||||
|
||||
return responseData;
|
||||
} catch (e) {
|
||||
throw Exception('Failed to create entity: $e');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Future<void> updateEntity( int entityId, Map<String, dynamic> entity) async {
|
||||
try {
|
||||
await _helper.getPutApiResponse('$baseUrl/Ad6/Ad6/$entityId',
|
||||
entity); print(entity);
|
||||
|
||||
} catch (e) {
|
||||
throw Exception('Failed to update entity: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteEntity( int entityId) async {
|
||||
try {
|
||||
await _helper.getDeleteApiResponse('$baseUrl/Ad6/Ad6/$entityId');
|
||||
} catch (e) {
|
||||
throw Exception('Failed to delete entity: $e');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,86 @@
|
||||
// ignore_for_file: use_build_context_synchronously
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../Ad6_viewModel/Ad6_view_model_screen.dart';
|
||||
import 'Ad6_fields.dart';import 'package:base_project/BuilderField/shared/ui/entity_screens.dart';
|
||||
import '../../../../utils/image_constant.dart';
|
||||
import '../../../../utils/size_utils.dart';
|
||||
import '../../../../theme/app_style.dart';
|
||||
import '../../../../widgets/app_bar/appbar_image.dart';
|
||||
import '../../../../widgets/app_bar/appbar_title.dart';
|
||||
import '../../../../widgets/app_bar/custom_app_bar.dart';
|
||||
import '../../../../widgets/custom_button.dart';
|
||||
import '../../../../widgets/custom_text_form_field.dart';
|
||||
import '../../../../widgets/custom_dropdown_field.dart';
|
||||
import 'dart:math';
|
||||
import 'package:qr_flutter/qr_flutter.dart';
|
||||
import 'package:barcode_widget/barcode_widget.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import 'package:autocomplete_textfield/autocomplete_textfield.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
import '../../../../Reuseable/reusable_date_picker_field.dart';
|
||||
import '../../../../Reuseable/reusable_date_time_picker_field.dart'
|
||||
;import 'package:multi_select_flutter/multi_select_flutter.dart';
|
||||
import 'package:just_audio/just_audio.dart';
|
||||
import 'package:video_player/video_player.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:lottie/lottie.dart';
|
||||
import '../../../../utils/toast_messages/toast_message_util.dart';
|
||||
import 'dart:io';
|
||||
import '../../../../Reuseable/reusable_text_field.dart';
|
||||
import '../../../../Reuseable/reusable_dropdown_field.dart';
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class Ad6CreateEntityScreen extends StatefulWidget {
|
||||
const Ad6CreateEntityScreen({super.key});
|
||||
|
||||
@override
|
||||
_Ad6CreateEntityScreenState createState() => _Ad6CreateEntityScreenState();
|
||||
}
|
||||
|
||||
class _Ad6CreateEntityScreenState extends State<Ad6CreateEntityScreen> {
|
||||
|
||||
final Map<String, dynamic> formData = {};
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer<Ad6ViewModelScreen>(
|
||||
builder: (context, viewModel, child) {
|
||||
return EntityCreateScreen(
|
||||
fields: Ad6Fields.getFields(context),
|
||||
onSubmit: (data) => _handleSubmit(data),
|
||||
title: 'Ad6',
|
||||
isLoading: viewModel.isLoading,
|
||||
errorMessage:
|
||||
viewModel.errorMessage.isNotEmpty ? viewModel.errorMessage : null,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _handleSubmit(Map<String, dynamic> formData) async {
|
||||
final provider =
|
||||
Provider.of<Ad6ViewModelScreen>(context, listen: false);
|
||||
final success = await provider.createEntity(formData);
|
||||
|
||||
if (success && mounted) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,94 @@
|
||||
// ignore_for_file: use_build_context_synchronously
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../../../BuilderField/shared/ui/entity_details.dart';
|
||||
import '../Ad6_viewModel/Ad6_view_model_screen.dart';
|
||||
import 'Ad6_update_entity_screen.dart';
|
||||
|
||||
class Ad6DetailsScreen extends StatefulWidget {
|
||||
final Map<String, dynamic> entity;
|
||||
|
||||
const Ad6DetailsScreen({
|
||||
super.key,
|
||||
required this.entity,
|
||||
});
|
||||
|
||||
@override
|
||||
State<Ad6DetailsScreen> createState() => _Ad6DetailsScreenState();
|
||||
}
|
||||
|
||||
class _Ad6DetailsScreenState extends State<Ad6DetailsScreen> {
|
||||
void _navigateToUpdateScreen(Map<String, dynamic> entity) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ChangeNotifierProvider(
|
||||
create: (context) => Ad6ViewModelScreen(),
|
||||
child: Ad6UpdateEntityScreen(entity: entity),
|
||||
),
|
||||
),
|
||||
).then((_) {
|
||||
// Refresh the details screen with updated data
|
||||
setState(() {});
|
||||
});
|
||||
}
|
||||
|
||||
void _showDeleteDialog(Map<String, dynamic> entity) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('Confirm Deletion'),
|
||||
content: const Text('Are you sure you want to delete this Ad6?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: const Text('Cancel'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
TextButton(
|
||||
child: const Text('Delete'),
|
||||
onPressed: () async {
|
||||
Navigator.of(context).pop();
|
||||
final vm =
|
||||
Provider.of<Ad6ViewModelScreen>(context, listen: false);
|
||||
final success = await vm.deleteEntity(entity['id']);
|
||||
if (success && mounted) {
|
||||
Navigator.pop(context); // Go back to list
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer<Ad6ViewModelScreen>(
|
||||
builder: (context, viewModel, child) {
|
||||
return EntityDetails(
|
||||
entity: widget.entity,
|
||||
onEdit: (entity) => _navigateToUpdateScreen(entity),
|
||||
onDelete: (entity) => _showDeleteDialog(entity),
|
||||
title: 'Ad6',
|
||||
displayFields: [
|
||||
{'key': 'name', 'label': 'Name', 'type': 'text'},
|
||||
|
||||
{'key': 'description', 'label': 'description', 'type': 'text'},
|
||||
|
||||
|
||||
|
||||
{'key': 'value_list_field', 'label': 'Value List Field', 'type': 'value_list'},
|
||||
|
||||
|
||||
|
||||
],
|
||||
isLoading: viewModel.isLoading,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,165 @@
|
||||
// ignore_for_file: use_build_context_synchronously
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:base_project/BuilderField/shared/ui/entity_list.dart';
|
||||
import 'Ad6_create_entity_screen.dart';
|
||||
import 'Ad6_update_entity_screen.dart';
|
||||
import '../Ad6_viewModel/Ad6_view_model_screen.dart';
|
||||
import 'Ad6_details_screen.dart';import 'package:flutter/services.dart';
|
||||
import 'package:speech_to_text/speech_to_text.dart' as stt;
|
||||
import '../../../../theme/app_style.dart';
|
||||
import '../../../../utils/size_utils.dart';
|
||||
import '../../../../widgets/custom_icon_button.dart';
|
||||
import '../../../../utils/image_constant.dart';
|
||||
import '../../../../widgets/app_bar/appbar_image.dart';
|
||||
import '../../../../widgets/app_bar/appbar_title.dart';
|
||||
import '../../../../widgets/app_bar/custom_app_bar.dart';
|
||||
import '../../../../theme/app_decoration.dart';
|
||||
import 'package:multi_select_flutter/multi_select_flutter.dart';
|
||||
import '../../../../Reuseable/reusable_text_field.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../../../utils/toast_messages/toast_message_util.dart';
|
||||
import '../../../../BuilderField/shared/fields/realted_entity_insert_field.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
|
||||
class Ad6_entity_list_screen extends StatefulWidget {
|
||||
static const String routeName = '/entity-list';
|
||||
|
||||
@override
|
||||
_Ad6_entity_list_screenState createState() => _Ad6_entity_list_screenState();
|
||||
}
|
||||
|
||||
class _Ad6_entity_list_screenState extends State<Ad6_entity_list_screen> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadData();
|
||||
}
|
||||
|
||||
void _loadData() {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) {
|
||||
final vm = Provider.of<Ad6ViewModelScreen>(context, listen: false);
|
||||
vm.getAllWithPagination(refresh: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _navigateToCreateScreen() {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ChangeNotifierProvider(
|
||||
create: (context) => Ad6ViewModelScreen(),
|
||||
child: const Ad6CreateEntityScreen(),
|
||||
),
|
||||
),
|
||||
).then((_) {
|
||||
final vm = Provider.of<Ad6ViewModelScreen>(context, listen: false);
|
||||
vm.refreshData();
|
||||
});
|
||||
}
|
||||
|
||||
void _navigateToUpdateScreen(Map<String, dynamic> entity) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ChangeNotifierProvider(
|
||||
create: (context) => Ad6ViewModelScreen(),
|
||||
child: Ad6UpdateEntityScreen(entity: entity),
|
||||
),
|
||||
),
|
||||
).then((_) {
|
||||
final vm = Provider.of<Ad6ViewModelScreen>(context, listen: false);
|
||||
vm.refreshData();
|
||||
});
|
||||
}
|
||||
|
||||
void _navigateToDetailsScreen(Map<String, dynamic> entity) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ChangeNotifierProvider(
|
||||
create: (context) => Ad6ViewModelScreen(),
|
||||
child: Ad6DetailsScreen(entity: entity),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showDeleteDialog(Map<String, dynamic> entity) {
|
||||
final parentContext = context;
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('Confirm Deletion'),
|
||||
content: const Text('Are you sure you want to delete this Ad6?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: const Text('Cancel'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
TextButton(
|
||||
child: const Text('Delete'),
|
||||
onPressed: () async {
|
||||
Navigator.of(context).pop();
|
||||
final vm =
|
||||
Provider.of<Ad6ViewModelScreen>(parentContext, listen: false);
|
||||
await vm.deleteEntity(entity['id']);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer<Ad6ViewModelScreen>(
|
||||
builder: (context, viewModel, child) {
|
||||
return EntityList(
|
||||
entities: viewModel.filteredList,
|
||||
isLoading: viewModel.isLoading,
|
||||
errorMessage:
|
||||
viewModel.errorMessage.isNotEmpty ? viewModel.errorMessage : null,
|
||||
hasMoreData: viewModel.hasMoreData,
|
||||
searchQuery: viewModel.searchQuery,
|
||||
onSearchChanged: (query) => viewModel.searchad6(query),
|
||||
onEdit: (entity) => _navigateToUpdateScreen(entity),
|
||||
onDelete: (entity) => _showDeleteDialog(entity),
|
||||
onTap: (entity) => _navigateToDetailsScreen(entity),
|
||||
onRefresh: () => viewModel.refreshData(),
|
||||
onLoadMore: () => viewModel.getAllWithPagination(),
|
||||
title: 'Ad6',
|
||||
onAddNew: _navigateToCreateScreen,
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
displayFields: [
|
||||
{'key': 'name', 'label': 'Name', 'type': 'text'},
|
||||
|
||||
{'key': 'description', 'label': 'description', 'type': 'text'},
|
||||
|
||||
|
||||
|
||||
{'key': 'value_list_field', 'label': 'Value List Field', 'type': 'value_list'},
|
||||
|
||||
|
||||
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,145 @@
|
||||
import 'package:base_project/BuilderField/shared/fields/number_field.dart';
|
||||
import 'package:base_project/BuilderField/shared/fields/password_field.dart';
|
||||
import 'package:base_project/BuilderField/shared/fields/phone_field.dart';
|
||||
import 'package:base_project/BuilderField/shared/fields/custom_text_field.dart';
|
||||
|
||||
import '../../../../BuilderField/shared/fields/base_field.dart';
|
||||
|
||||
import '../../../../BuilderField/shared/fields/date_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/datetime_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/email_field.dart';
|
||||
import 'package:base_project/BuilderField/shared/fields/url_field.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../../../BuilderField/shared/fields/custom_text_field.dart' as shared_text;
|
||||
import '../../../../BuilderField/shared/fields/one_to_one_relation_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/calculated_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/one_to_many_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/value_list_picker_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/captcha_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/switch_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/url_field.dart';
|
||||
|
||||
import '../../../../BuilderField/shared/fields/audio_upload_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/checkbox_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/file_upload_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/image_upload_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/radio_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/video_upload_field.dart';
|
||||
|
||||
import '../../../../BuilderField/shared/fields/autocomplete_dropdown_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/autocomplete_multiselect_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/one_to_one_relation_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/data_grid_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/dropdown_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/dynamic_dropdown_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/dynamic_multiselect_dropdown_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/static_multiselect_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/currency_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/field_group_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/qr_code_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/barcode_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/dependent_dropdown_field.dart';
|
||||
import '../Ad6_viewModel/Ad6_view_model_screen.dart';/// Field definitions for Ad6 entity
|
||||
/// This defines the structure and validation for Ad6 forms
|
||||
class Ad6Fields {
|
||||
/// Get field definitions for Ad6 entity
|
||||
static List<BaseField> getFields(BuildContext context) {
|
||||
final viewModel =
|
||||
Provider.of<Ad6ViewModelScreen>(context, listen: false);
|
||||
return [
|
||||
// Basic Information
|
||||
CustomTextField(
|
||||
fieldKey: 'name',
|
||||
label: 'Name',
|
||||
hint: 'Enter Name',
|
||||
isRequired: true,
|
||||
maxLength: 50,
|
||||
),
|
||||
|
||||
CustomTextField(
|
||||
fieldKey: 'description',
|
||||
label: 'description',
|
||||
hint: 'Enter description',
|
||||
isRequired: true,
|
||||
maxLength: 50,
|
||||
),
|
||||
|
||||
OneToOneRelationField(
|
||||
fieldKey: 'child',
|
||||
label: 'child',
|
||||
hint: 'child details',
|
||||
relationSchema: {
|
||||
'title': 'child',
|
||||
'box': true,
|
||||
'fields': [
|
||||
|
||||
|
||||
{
|
||||
'type': 'text',
|
||||
'label': 'Active',
|
||||
'hint': 'Enter Active',
|
||||
'path': 'child.active',
|
||||
},
|
||||
|
||||
|
||||
|
||||
|
||||
{
|
||||
'type': 'text',
|
||||
'label': 'Description',
|
||||
'hint': 'Enter Description',
|
||||
'path': 'child.description',
|
||||
},
|
||||
|
||||
|
||||
|
||||
|
||||
{
|
||||
'type': 'text',
|
||||
'label': 'Name',
|
||||
'hint': 'Enter Name',
|
||||
'path': 'child.name',
|
||||
},
|
||||
|
||||
|
||||
|
||||
],
|
||||
},
|
||||
),
|
||||
|
||||
|
||||
// 3) Value list picker â fill fields from selection (provide your loader)
|
||||
ValueListPickerField(
|
||||
fieldKey: 'value_list_field',
|
||||
label: 'Value List Field',
|
||||
optionsLoader: () async {
|
||||
try {
|
||||
await viewModel.getEntities();
|
||||
final response = viewModel.ad6List;
|
||||
return response;
|
||||
} catch (e) {
|
||||
// Return empty list if API fails
|
||||
return <Map<String, dynamic>>[];
|
||||
}
|
||||
},
|
||||
fillMappings: const {
|
||||
|
||||
|
||||
'name': 'name',
|
||||
|
||||
|
||||
|
||||
},
|
||||
),
|
||||
|
||||
FileUploadField(
|
||||
fieldKey: 'fileupload_fields',
|
||||
label: 'Fileupload Fields',
|
||||
isRequired: false,
|
||||
),
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,81 @@
|
||||
// ignore_for_file: use_build_context_synchronously
|
||||
import 'dart:convert';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../Ad6_viewModel/Ad6_view_model_screen.dart';
|
||||
import 'package:base_project/BuilderField/shared/ui/entity_screens.dart';
|
||||
import 'Ad6_fields.dart';import '../../../../utils/image_constant.dart';
|
||||
import '../../../../utils/size_utils.dart';
|
||||
import '../../../../theme/app_style.dart';
|
||||
import '../../../../widgets/app_bar/appbar_image.dart';
|
||||
import '../../../../widgets/app_bar/appbar_title.dart';
|
||||
import '../../../../widgets/app_bar/custom_app_bar.dart';
|
||||
import 'package:barcode_widget/barcode_widget.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
import '../../../../widgets/custom_button.dart';
|
||||
import '../../../../widgets/custom_text_form_field.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:autocomplete_textfield/autocomplete_textfield.dart';
|
||||
import 'package:qr_flutter/qr_flutter.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import 'dart:math';
|
||||
import '../../../../Reuseable/reusable_text_field.dart';
|
||||
import '../../../../Reuseable/reusable_date_picker_field.dart';
|
||||
import '../../../../Reuseable/reusable_date_time_picker_field.dart';
|
||||
import '../../../../Reuseable/reusable_dropdown_field.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
class Ad6UpdateEntityScreen extends StatefulWidget {
|
||||
final Map<String, dynamic> entity;
|
||||
|
||||
|
||||
Ad6UpdateEntityScreen({required this.entity});
|
||||
|
||||
@override
|
||||
_Ad6UpdateEntityScreenState createState() => _Ad6UpdateEntityScreenState();
|
||||
}
|
||||
|
||||
class _Ad6UpdateEntityScreenState extends State<Ad6UpdateEntityScreen> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer<Ad6ViewModelScreen>(
|
||||
builder: (context, viewModel, child) {
|
||||
// Start with all fields, then remove upload fields (generic filter by keys)
|
||||
final Set<String> hiddenKeys = {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
'fileupload_fields',
|
||||
|
||||
};
|
||||
final fields = Ad6Fields.getFields(context)
|
||||
.where((f) => !hiddenKeys.contains(f.fieldKey))
|
||||
.toList(); return EntityUpdateScreen(
|
||||
fields: fields,
|
||||
initialData: widget.entity,
|
||||
onSubmit: (data) => _handleSubmit(data),
|
||||
title: 'Ad6',
|
||||
isLoading: viewModel.isLoading,
|
||||
errorMessage:
|
||||
viewModel.errorMessage.isNotEmpty ? viewModel.errorMessage : null,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _handleSubmit(Map<String, dynamic> formData) async {
|
||||
final provider =
|
||||
Provider.of<Ad6ViewModelScreen>(context, listen: false);
|
||||
final success = await provider.updateEntity(widget.entity['id'], formData);
|
||||
|
||||
if (success && mounted) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,108 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import '../../../../data/network/base_network_service.dart';
|
||||
import '../../../../data/network/network_api_service.dart';
|
||||
import '../../../../resources/api_constants.dart';
|
||||
import 'package:base_project/data/response/api_response.dart';
|
||||
|
||||
class Ad6RepoScreen {
|
||||
|
||||
final String baseUrl = ApiConstants.baseUrl;
|
||||
final BaseNetworkService _helper = NetworkApiService();
|
||||
final String _endpointPath = '/Ad6/Ad6';
|
||||
|
||||
Future<ApiResponse<List<Map<String, dynamic>>>> getEntities() async {
|
||||
try {
|
||||
final response =
|
||||
await _helper.getGetApiResponse('$baseUrl$_endpointPath');
|
||||
print('Response received: $response');
|
||||
List<Map<String, dynamic>> entities = const [];
|
||||
if (response is List) {
|
||||
entities = response
|
||||
.whereType<Map>()
|
||||
.map((e) => Map<String, dynamic>.from(e as Map))
|
||||
.toList();
|
||||
} else if (response is Map<String, dynamic>) {
|
||||
final dynamic content = response['content'];
|
||||
if (content is List) {
|
||||
entities = content
|
||||
.whereType<Map>()
|
||||
.map((e) => Map<String, dynamic>.from(e as Map))
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
return ApiResponse.success(entities);
|
||||
} catch (e) {
|
||||
print(' error got $e');
|
||||
return ApiResponse.error('Failed to get all entities: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<ApiResponse<List<Map<String, dynamic>>>> getAllWithPagination(
|
||||
int page, int size) async {
|
||||
try {
|
||||
final response = await _helper.getGetApiResponse(
|
||||
'$baseUrl$_endpointPath/getall/page?page=$page&size=$size');
|
||||
|
||||
if (response is Map<String, dynamic> && response['content'] is List) {
|
||||
final List<Map<String, dynamic>> entities =
|
||||
(response['content'] as List).cast<Map<String, dynamic>>().toList();
|
||||
return ApiResponse.success(entities);
|
||||
} else {
|
||||
return ApiResponse.error('Invalid response format');
|
||||
}
|
||||
} catch (e) {
|
||||
return ApiResponse.error('Failed to get all without pagination: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<ApiResponse<Map<String, dynamic>>> createEntity(
|
||||
Map<String, dynamic> entity) async {
|
||||
try {
|
||||
print("in post api$entity");
|
||||
final response =
|
||||
await _helper.getPostApiResponse('$baseUrl$_endpointPath', entity);
|
||||
return ApiResponse.success(response as Map<String, dynamic>);
|
||||
} catch (e) {
|
||||
return ApiResponse.error('Failed to create entity: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<ApiResponse<Map<String, dynamic>>> updateEntity(
|
||||
int entityId, Map<String, dynamic> entity) async {
|
||||
try {
|
||||
final response = await _helper.getPutApiResponse(
|
||||
'$baseUrl$_endpointPath/$entityId', entity);
|
||||
return ApiResponse.success(response as Map<String, dynamic>);
|
||||
} catch (e) {
|
||||
return ApiResponse.error('Failed to update entity: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<ApiResponse<void>> deleteEntity(int entityId) async {
|
||||
try {
|
||||
await _helper.getDeleteApiResponse('$baseUrl$_endpointPath/$entityId');
|
||||
return ApiResponse.success(null);
|
||||
} catch (e) {
|
||||
return ApiResponse.error('Failed to delete entity: $e');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Future<dynamic> fileupload_fieldsUpload(
|
||||
String ref, String refTableNmae, FormData entity) async {
|
||||
try {
|
||||
String apiUrl = "$baseUrl/FileUpload/Uploadeddocs/$ref/$refTableNmae";
|
||||
final response = await _helper.getPostApiResponse(apiUrl, entity);
|
||||
return response;
|
||||
} catch (e) {
|
||||
throw Exception('Failed to Upload File: $e');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,426 @@
|
||||
import 'package:base_project/data/response/status.dart';
|
||||
import 'dart:typed_data';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
import '../../../../utils/toast_messages/toast_message_util.dart';
|
||||
import '../../../../BuilderField/shared/utils/entity_field_store.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../Ad6_Repo/Ad6_repo_screen.dart';
|
||||
|
||||
class Ad6ViewModelScreen extends ChangeNotifier{
|
||||
final Ad6RepoScreen repo = Ad6RepoScreen();
|
||||
|
||||
|
||||
// State variables
|
||||
List<Map<String, dynamic>> _ad6List = [];
|
||||
List<Map<String, dynamic>> _filteredList = [];
|
||||
bool _isLoading = false;
|
||||
String _errorMessage = '';
|
||||
int _currentPage = 0;
|
||||
int _pageSize = 10;
|
||||
bool _hasMoreData = true;
|
||||
String _searchQuery = '';
|
||||
|
||||
// Getters
|
||||
List<Map<String, dynamic>> get ad6List => _ad6List;
|
||||
List<Map<String, dynamic>> get filteredList => _filteredList;
|
||||
bool get isLoading => _isLoading;
|
||||
String get errorMessage => _errorMessage;
|
||||
bool get hasMoreData => _hasMoreData;
|
||||
String get searchQuery => _searchQuery;
|
||||
|
||||
// Set loading state
|
||||
void _setLoading(bool loading) {
|
||||
_isLoading = loading;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// Set error message
|
||||
void _setError(String error) {
|
||||
_errorMessage = error;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// Clear error
|
||||
void clearError() {
|
||||
_errorMessage = '';
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// Get ad6 list
|
||||
Future<void> getEntities() async {
|
||||
_setLoading(true);
|
||||
_setError('');
|
||||
|
||||
try {
|
||||
final response = await repo.getEntities();
|
||||
|
||||
if (response.status == Status.SUCCESS) {
|
||||
_ad6List = response.data ?? [];
|
||||
_filteredList = List.from(_ad6List);
|
||||
_currentPage = 0;
|
||||
_hasMoreData = true;
|
||||
} else {
|
||||
_setError(response.message ?? 'Failed to fetch ad6 list');
|
||||
}
|
||||
} catch (e) {
|
||||
_setError('Failed to fetch ad6 list: $e');
|
||||
} finally {
|
||||
_setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Get ad6 list with pagination
|
||||
Future<void> getAllWithPagination({bool refresh = false}) async {
|
||||
if (refresh) {
|
||||
_currentPage = 0;
|
||||
_ad6List.clear();
|
||||
_filteredList.clear();
|
||||
_hasMoreData = true;
|
||||
}
|
||||
|
||||
if (!_hasMoreData || _isLoading) return;
|
||||
|
||||
_setLoading(true);
|
||||
_setError('');
|
||||
|
||||
try {
|
||||
final response = await repo.getAllWithPagination(_currentPage, _pageSize);
|
||||
|
||||
if (response.status == Status.SUCCESS) {
|
||||
final newItems = response.data ?? [];
|
||||
|
||||
if (refresh) {
|
||||
_ad6List = newItems;
|
||||
} else {
|
||||
_ad6List.addAll(newItems);
|
||||
}
|
||||
|
||||
_filteredList = List.from(_ad6List);
|
||||
_currentPage++;
|
||||
|
||||
// Check if we have more data
|
||||
_hasMoreData = newItems.length == _pageSize;
|
||||
} else {
|
||||
_setError(response.message ?? 'Failed to fetch Ad6 list');
|
||||
}
|
||||
} catch (e) {
|
||||
_setError('Failed to fetch ad6 list: $e');
|
||||
} finally {
|
||||
_setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Variable to store image files
|
||||
List<Map<String, dynamic>> _fileupload_fieldsFiles = [];
|
||||
|
||||
// Create Ad6
|
||||
Future<bool> createEntity(Map<String, dynamic> entity) async {
|
||||
_setLoading(true);
|
||||
_setError('');
|
||||
|
||||
try {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Always source image selections from EntityFieldStore for simplicity
|
||||
final List<UploadItem> storefilefileupload_fields = EntityFieldStore.instance
|
||||
.get<List<UploadItem>>('fileupload_fields') ??
|
||||
<UploadItem>[];
|
||||
|
||||
_fileupload_fieldsFiles = storefilefileupload_fields
|
||||
.map((u) => {'path': u.fileName, 'bytes': u.bytes})
|
||||
.toList();
|
||||
|
||||
|
||||
entity.remove('fileupload_fields');
|
||||
|
||||
|
||||
final response = await repo.createEntity(entity);
|
||||
|
||||
if (response.status == Status.SUCCESS) {
|
||||
// Get the response ID for image upload
|
||||
|
||||
final responseId = response.data!['id'].toString();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Upload File if available
|
||||
if (_fileupload_fieldsFiles.isNotEmpty) {
|
||||
await _uploadfileupload_fields(responseId, _fileupload_fieldsFiles);
|
||||
_fileupload_fieldsFiles.clear(); // Clear after upload
|
||||
}
|
||||
|
||||
ToastMessageUtil.showToast(
|
||||
message: 'ad6 created successfully',
|
||||
toastType: ToastType.success,
|
||||
);
|
||||
|
||||
// Refresh the list
|
||||
await getEntities();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
EntityFieldStore.instance.remove('fileupload_fields');
|
||||
|
||||
|
||||
return true;
|
||||
} else {
|
||||
_setError(response.message ?? 'Failed to create Ad6');
|
||||
ToastMessageUtil.showToast(
|
||||
message: response.message ?? 'Failed to create Ad6',
|
||||
toastType: ToastType.error,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
_setError('Failed to create ad6: $e');
|
||||
ToastMessageUtil.showToast(
|
||||
message: 'Failed to create Ad6: $e',
|
||||
toastType: ToastType.error,
|
||||
);
|
||||
return false;
|
||||
} finally {
|
||||
_setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Update ad6
|
||||
Future<bool> updateEntity(int id, Map<String, dynamic> entity) async {
|
||||
_setLoading(true);
|
||||
_setError('');
|
||||
|
||||
try {
|
||||
final response = await repo.updateEntity(id, entity);
|
||||
|
||||
if (response.status == Status.SUCCESS) {
|
||||
ToastMessageUtil.showToast(
|
||||
message: 'Ad6 updated successfully',
|
||||
toastType: ToastType.success,
|
||||
);
|
||||
|
||||
// Update the item in the list
|
||||
final index = _ad6List.indexWhere((item) => item['id'] == id);
|
||||
if (index != -1) {
|
||||
_ad6List[index] = response.data!;
|
||||
_filteredList = List.from(_ad6List);
|
||||
notifyListeners();
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
_setError(response.message ?? 'Failed to update Ad6');
|
||||
ToastMessageUtil.showToast(
|
||||
message: response.message ?? 'Failed to update Ad6',
|
||||
toastType: ToastType.error,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
_setError('Failed to update ad6: $e');
|
||||
ToastMessageUtil.showToast(
|
||||
message: 'Failed to update Ad6: $e',
|
||||
toastType: ToastType.error,
|
||||
);
|
||||
return false;
|
||||
} finally {
|
||||
_setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Delete ad6
|
||||
Future<bool> deleteEntity(int id) async {
|
||||
_setLoading(true);
|
||||
_setError('');
|
||||
|
||||
try {
|
||||
final response = await repo.deleteEntity(id);
|
||||
|
||||
if (response.status == Status.SUCCESS) {
|
||||
ToastMessageUtil.showToast(
|
||||
message: 'Ad6 deleted successfully',
|
||||
toastType: ToastType.success,
|
||||
);
|
||||
|
||||
// Remove the item from the list
|
||||
_ad6List.removeWhere((item) => item['id'] == id);
|
||||
_filteredList = List.from(_ad6List);
|
||||
notifyListeners();
|
||||
return true;
|
||||
} else {
|
||||
_setError(response.message ?? 'Failed to delete Ad6');
|
||||
ToastMessageUtil.showToast(
|
||||
message: response.message ?? 'Failed to delete Ad6',
|
||||
toastType: ToastType.error,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
_setError('Failed to delete ad6: $e');
|
||||
ToastMessageUtil.showToast(
|
||||
message: 'Failed to delete Ad6: $e',
|
||||
toastType: ToastType.error,
|
||||
);
|
||||
return false;
|
||||
} finally {
|
||||
_setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Search ad6
|
||||
void searchad6(String query) {
|
||||
_searchQuery = query;
|
||||
|
||||
if (query.isEmpty) {
|
||||
_filteredList = List.from(_ad6List);
|
||||
} else {
|
||||
_filteredList = _ad6List.where((item) {
|
||||
return
|
||||
|
||||
|
||||
(item['name']?.toString().toLowerCase().contains(query.toLowerCase()) ??false) ||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(item['description']?.toString().toLowerCase().contains(query.toLowerCase()) ??false) ||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(item['child']?.toString().toLowerCase().contains(query.toLowerCase()) ??false)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
;
|
||||
}).toList();
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// Clear search
|
||||
void clearSearch() {
|
||||
_searchQuery = '';
|
||||
_filteredList = List.from(_ad6List);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// Refresh data
|
||||
Future<void> refreshData() async {
|
||||
await getAllWithPagination(refresh: true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Helper method to upload multiple image files
|
||||
Future<void> _uploadfileupload_fields(
|
||||
String responseId, List<dynamic> Files) async {
|
||||
try {
|
||||
for (var File in Files) {
|
||||
if (File is Map<String, dynamic> &&
|
||||
File.containsKey('path')) {
|
||||
String filePath = File['path'];
|
||||
Uint8List fileBytes = File['bytes'];
|
||||
|
||||
// Upload each image file
|
||||
await uploadfileupload_fields(
|
||||
responseId, 'Ad6', filePath, fileBytes);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
print('Error uploading files: $error');
|
||||
ToastMessageUtil.showToast(
|
||||
message: "Failed to upload images", toastType: ToastType.error);
|
||||
}
|
||||
}
|
||||
|
||||
// Modify the uploadfileupload_fieldsimage function
|
||||
Future<void> uploadfileupload_fields(String ref, String refTableNmae,
|
||||
String selectedFilePath, Uint8List imageTimageBytes) async {
|
||||
try {
|
||||
|
||||
final Uint8List fileBytes = imageTimageBytes!;
|
||||
final mimeType = fileupload_fieldslookupMimeType(selectedFilePath);
|
||||
|
||||
FormData formData = FormData.fromMap({
|
||||
'file': MultipartFile.fromBytes(
|
||||
fileBytes,
|
||||
filename: selectedFilePath
|
||||
.split('/')
|
||||
.last, // Get the file name from the path
|
||||
contentType: MediaType.parse(mimeType!),
|
||||
),
|
||||
});
|
||||
|
||||
|
||||
await repo.fileupload_fieldsUpload(ref, refTableNmae, formData).then((value) {
|
||||
ToastMessageUtil.showToast(
|
||||
message: "File uploaded successfully",
|
||||
toastType: ToastType.success);
|
||||
}).onError(
|
||||
(error, stackTrace) {
|
||||
print("error--$error");
|
||||
ToastMessageUtil.showToast(
|
||||
message: "Failed to upload file", toastType: ToastType.error);
|
||||
},
|
||||
);
|
||||
} catch (error) {
|
||||
print('Error occurred during form submission: $error');
|
||||
}
|
||||
}
|
||||
|
||||
// Modify the lookupMimeType function if needed
|
||||
String fileupload_fieldslookupMimeType(String filePath) {
|
||||
final ext = filePath.split('.').last;
|
||||
switch (ext) {
|
||||
case 'jpg':
|
||||
case 'jpeg':
|
||||
return 'image/jpeg';
|
||||
case 'png':
|
||||
return 'image/png';
|
||||
case 'pdf':
|
||||
return 'application/pdf';
|
||||
// Add more cases for other file types as needed
|
||||
default:
|
||||
return 'application/octet-stream'; // Default MIME type
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,80 @@
|
||||
import 'dart:typed_data';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
import '../../../../resources/api_constants.dart';
|
||||
import '../../../../data/network/base_network_service.dart';
|
||||
import '../../../../data/network/network_api_service.dart';
|
||||
|
||||
class ChildApiService {
|
||||
final String baseUrl = ApiConstants.baseUrl;
|
||||
|
||||
final BaseNetworkService _helper = NetworkApiService();
|
||||
|
||||
|
||||
|
||||
Future<List<Map<String, dynamic>>> getEntities() async {
|
||||
|
||||
try {
|
||||
final response = await _helper.getGetApiResponse('$baseUrl/Child/Child');
|
||||
final entities = (response as List).cast<Map<String, dynamic>>();
|
||||
return entities;
|
||||
} catch (e) {
|
||||
throw Exception('Failed to get all entities: $e');
|
||||
}
|
||||
}
|
||||
Future<List<Map<String, dynamic>>> getAllWithPagination(
|
||||
int page, int size) async {
|
||||
try {
|
||||
final response =
|
||||
await _helper.getGetApiResponse('$baseUrl/Child/Child/getall/page?page=$page&size=$size');
|
||||
final entities =
|
||||
(response['content'] as List).cast<Map<String, dynamic>>();
|
||||
return entities;
|
||||
} catch (e) {
|
||||
throw Exception('Failed to get all without pagination: $e');
|
||||
}
|
||||
}
|
||||
Future<Map<String, dynamic>> createEntity(
|
||||
Map<String, dynamic> entity) async {
|
||||
try {
|
||||
print("in post api$entity");
|
||||
final response =
|
||||
await _helper.getPostApiResponse('$baseUrl/Child/Child', entity);
|
||||
|
||||
print(entity);
|
||||
|
||||
// Assuming the response is a Map<String, dynamic>
|
||||
Map<String, dynamic> responseData = response;
|
||||
|
||||
return responseData;
|
||||
} catch (e) {
|
||||
throw Exception('Failed to create entity: $e');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Future<void> updateEntity( int entityId, Map<String, dynamic> entity) async {
|
||||
try {
|
||||
await _helper.getPutApiResponse('$baseUrl/Child/Child/$entityId',
|
||||
entity); print(entity);
|
||||
|
||||
} catch (e) {
|
||||
throw Exception('Failed to update entity: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteEntity( int entityId) async {
|
||||
try {
|
||||
await _helper.getDeleteApiResponse('$baseUrl/Child/Child/$entityId');
|
||||
} catch (e) {
|
||||
throw Exception('Failed to delete entity: $e');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,80 @@
|
||||
// ignore_for_file: use_build_context_synchronously
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../Child_viewModel/Child_view_model_screen.dart';
|
||||
import 'Child_fields.dart';import 'package:base_project/BuilderField/shared/ui/entity_screens.dart';
|
||||
import '../../../../utils/image_constant.dart';
|
||||
import '../../../../utils/size_utils.dart';
|
||||
import '../../../../theme/app_style.dart';
|
||||
import '../../../../widgets/app_bar/appbar_image.dart';
|
||||
import '../../../../widgets/app_bar/appbar_title.dart';
|
||||
import '../../../../widgets/app_bar/custom_app_bar.dart';
|
||||
import '../../../../widgets/custom_button.dart';
|
||||
import '../../../../widgets/custom_text_form_field.dart';
|
||||
import '../../../../widgets/custom_dropdown_field.dart';
|
||||
import 'dart:math';
|
||||
import 'package:qr_flutter/qr_flutter.dart';
|
||||
import 'package:barcode_widget/barcode_widget.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import 'package:autocomplete_textfield/autocomplete_textfield.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
import '../../../../Reuseable/reusable_date_picker_field.dart';
|
||||
import '../../../../Reuseable/reusable_date_time_picker_field.dart'
|
||||
;import 'package:multi_select_flutter/multi_select_flutter.dart';
|
||||
import 'package:just_audio/just_audio.dart';
|
||||
import 'package:video_player/video_player.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:lottie/lottie.dart';
|
||||
import '../../../../utils/toast_messages/toast_message_util.dart';
|
||||
import 'dart:io';
|
||||
import '../../../../Reuseable/reusable_text_field.dart';
|
||||
import '../../../../Reuseable/reusable_dropdown_field.dart';
|
||||
|
||||
|
||||
|
||||
|
||||
class ChildCreateEntityScreen extends StatefulWidget {
|
||||
const ChildCreateEntityScreen({super.key});
|
||||
|
||||
@override
|
||||
_ChildCreateEntityScreenState createState() => _ChildCreateEntityScreenState();
|
||||
}
|
||||
|
||||
class _ChildCreateEntityScreenState extends State<ChildCreateEntityScreen> {
|
||||
|
||||
final Map<String, dynamic> formData = {};
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer<ChildViewModelScreen>(
|
||||
builder: (context, viewModel, child) {
|
||||
return EntityCreateScreen(
|
||||
fields: ChildFields.getFields(context),
|
||||
onSubmit: (data) => _handleSubmit(data),
|
||||
title: 'Child',
|
||||
isLoading: viewModel.isLoading,
|
||||
errorMessage:
|
||||
viewModel.errorMessage.isNotEmpty ? viewModel.errorMessage : null,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _handleSubmit(Map<String, dynamic> formData) async {
|
||||
final provider =
|
||||
Provider.of<ChildViewModelScreen>(context, listen: false);
|
||||
final success = await provider.createEntity(formData);
|
||||
|
||||
if (success && mounted) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,88 @@
|
||||
// ignore_for_file: use_build_context_synchronously
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../../../BuilderField/shared/ui/entity_details.dart';
|
||||
import '../Child_viewModel/Child_view_model_screen.dart';
|
||||
import 'Child_update_entity_screen.dart';
|
||||
|
||||
class ChildDetailsScreen extends StatefulWidget {
|
||||
final Map<String, dynamic> entity;
|
||||
|
||||
const ChildDetailsScreen({
|
||||
super.key,
|
||||
required this.entity,
|
||||
});
|
||||
|
||||
@override
|
||||
State<ChildDetailsScreen> createState() => _ChildDetailsScreenState();
|
||||
}
|
||||
|
||||
class _ChildDetailsScreenState extends State<ChildDetailsScreen> {
|
||||
void _navigateToUpdateScreen(Map<String, dynamic> entity) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ChangeNotifierProvider(
|
||||
create: (context) => ChildViewModelScreen(),
|
||||
child: ChildUpdateEntityScreen(entity: entity),
|
||||
),
|
||||
),
|
||||
).then((_) {
|
||||
// Refresh the details screen with updated data
|
||||
setState(() {});
|
||||
});
|
||||
}
|
||||
|
||||
void _showDeleteDialog(Map<String, dynamic> entity) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('Confirm Deletion'),
|
||||
content: const Text('Are you sure you want to delete this Child?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: const Text('Cancel'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
TextButton(
|
||||
child: const Text('Delete'),
|
||||
onPressed: () async {
|
||||
Navigator.of(context).pop();
|
||||
final vm =
|
||||
Provider.of<ChildViewModelScreen>(context, listen: false);
|
||||
final success = await vm.deleteEntity(entity['id']);
|
||||
if (success && mounted) {
|
||||
Navigator.pop(context); // Go back to list
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer<ChildViewModelScreen>(
|
||||
builder: (context, viewModel, child) {
|
||||
return EntityDetails(
|
||||
entity: widget.entity,
|
||||
onEdit: (entity) => _navigateToUpdateScreen(entity),
|
||||
onDelete: (entity) => _showDeleteDialog(entity),
|
||||
title: 'Child',
|
||||
displayFields: [
|
||||
{'key': 'name', 'label': 'Name', 'type': 'text'},
|
||||
|
||||
{'key': 'description', 'label': 'Description', 'type': 'textarea'},
|
||||
|
||||
],
|
||||
isLoading: viewModel.isLoading,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,153 @@
|
||||
// ignore_for_file: use_build_context_synchronously
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:base_project/BuilderField/shared/ui/entity_list.dart';
|
||||
import 'Child_create_entity_screen.dart';
|
||||
import 'Child_update_entity_screen.dart';
|
||||
import '../Child_viewModel/Child_view_model_screen.dart';
|
||||
import 'Child_details_screen.dart';import 'package:flutter/services.dart';
|
||||
import 'package:speech_to_text/speech_to_text.dart' as stt;
|
||||
import '../../../../theme/app_style.dart';
|
||||
import '../../../../utils/size_utils.dart';
|
||||
import '../../../../widgets/custom_icon_button.dart';
|
||||
import '../../../../utils/image_constant.dart';
|
||||
import '../../../../widgets/app_bar/appbar_image.dart';
|
||||
import '../../../../widgets/app_bar/appbar_title.dart';
|
||||
import '../../../../widgets/app_bar/custom_app_bar.dart';
|
||||
import '../../../../theme/app_decoration.dart';
|
||||
import 'package:multi_select_flutter/multi_select_flutter.dart';
|
||||
import '../../../../Reuseable/reusable_text_field.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../../../utils/toast_messages/toast_message_util.dart';
|
||||
import '../../../../BuilderField/shared/fields/realted_entity_insert_field.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
|
||||
class Child_entity_list_screen extends StatefulWidget {
|
||||
static const String routeName = '/entity-list';
|
||||
|
||||
@override
|
||||
_Child_entity_list_screenState createState() => _Child_entity_list_screenState();
|
||||
}
|
||||
|
||||
class _Child_entity_list_screenState extends State<Child_entity_list_screen> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadData();
|
||||
}
|
||||
|
||||
void _loadData() {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (mounted) {
|
||||
final vm = Provider.of<ChildViewModelScreen>(context, listen: false);
|
||||
vm.getAllWithPagination(refresh: true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void _navigateToCreateScreen() {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ChangeNotifierProvider(
|
||||
create: (context) => ChildViewModelScreen(),
|
||||
child: const ChildCreateEntityScreen(),
|
||||
),
|
||||
),
|
||||
).then((_) {
|
||||
final vm = Provider.of<ChildViewModelScreen>(context, listen: false);
|
||||
vm.refreshData();
|
||||
});
|
||||
}
|
||||
|
||||
void _navigateToUpdateScreen(Map<String, dynamic> entity) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ChangeNotifierProvider(
|
||||
create: (context) => ChildViewModelScreen(),
|
||||
child: ChildUpdateEntityScreen(entity: entity),
|
||||
),
|
||||
),
|
||||
).then((_) {
|
||||
final vm = Provider.of<ChildViewModelScreen>(context, listen: false);
|
||||
vm.refreshData();
|
||||
});
|
||||
}
|
||||
|
||||
void _navigateToDetailsScreen(Map<String, dynamic> entity) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ChangeNotifierProvider(
|
||||
create: (context) => ChildViewModelScreen(),
|
||||
child: ChildDetailsScreen(entity: entity),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showDeleteDialog(Map<String, dynamic> entity) {
|
||||
final parentContext = context;
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('Confirm Deletion'),
|
||||
content: const Text('Are you sure you want to delete this Child?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: const Text('Cancel'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
TextButton(
|
||||
child: const Text('Delete'),
|
||||
onPressed: () async {
|
||||
Navigator.of(context).pop();
|
||||
final vm =
|
||||
Provider.of<ChildViewModelScreen>(parentContext, listen: false);
|
||||
await vm.deleteEntity(entity['id']);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer<ChildViewModelScreen>(
|
||||
builder: (context, viewModel, child) {
|
||||
return EntityList(
|
||||
entities: viewModel.filteredList,
|
||||
isLoading: viewModel.isLoading,
|
||||
errorMessage:
|
||||
viewModel.errorMessage.isNotEmpty ? viewModel.errorMessage : null,
|
||||
hasMoreData: viewModel.hasMoreData,
|
||||
searchQuery: viewModel.searchQuery,
|
||||
onSearchChanged: (query) => viewModel.searchchild(query),
|
||||
onEdit: (entity) => _navigateToUpdateScreen(entity),
|
||||
onDelete: (entity) => _showDeleteDialog(entity),
|
||||
onTap: (entity) => _navigateToDetailsScreen(entity),
|
||||
onRefresh: () => viewModel.refreshData(),
|
||||
onLoadMore: () => viewModel.getAllWithPagination(),
|
||||
title: 'Child',
|
||||
onAddNew: _navigateToCreateScreen,
|
||||
|
||||
|
||||
|
||||
|
||||
displayFields: [
|
||||
{'key': 'name', 'label': 'Name', 'type': 'text'},
|
||||
|
||||
{'key': 'description', 'label': 'Description', 'type': 'textarea'},
|
||||
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,71 @@
|
||||
import 'package:base_project/BuilderField/shared/fields/number_field.dart';
|
||||
import 'package:base_project/BuilderField/shared/fields/password_field.dart';
|
||||
import 'package:base_project/BuilderField/shared/fields/phone_field.dart';
|
||||
import 'package:base_project/BuilderField/shared/fields/custom_text_field.dart';
|
||||
|
||||
import '../../../../BuilderField/shared/fields/base_field.dart';
|
||||
|
||||
import '../../../../BuilderField/shared/fields/date_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/datetime_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/email_field.dart';
|
||||
import 'package:base_project/BuilderField/shared/fields/url_field.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../../../../BuilderField/shared/fields/custom_text_field.dart' as shared_text;
|
||||
import '../../../../BuilderField/shared/fields/one_to_one_relation_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/calculated_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/one_to_many_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/value_list_picker_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/captcha_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/switch_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/url_field.dart';
|
||||
|
||||
import '../../../../BuilderField/shared/fields/audio_upload_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/checkbox_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/file_upload_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/image_upload_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/radio_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/video_upload_field.dart';
|
||||
|
||||
import '../../../../BuilderField/shared/fields/autocomplete_dropdown_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/autocomplete_multiselect_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/one_to_one_relation_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/data_grid_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/dropdown_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/dynamic_dropdown_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/dynamic_multiselect_dropdown_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/static_multiselect_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/currency_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/field_group_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/qr_code_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/barcode_field.dart';
|
||||
import '../../../../BuilderField/shared/fields/dependent_dropdown_field.dart';
|
||||
import '../Child_viewModel/Child_view_model_screen.dart';/// Field definitions for Child entity
|
||||
/// This defines the structure and validation for Child forms
|
||||
class ChildFields {
|
||||
/// Get field definitions for Child entity
|
||||
static List<BaseField> getFields(BuildContext context) {
|
||||
final viewModel =
|
||||
Provider.of<ChildViewModelScreen>(context, listen: false);
|
||||
return [
|
||||
// Basic Information
|
||||
CustomTextField(
|
||||
fieldKey: 'name',
|
||||
label: 'Name',
|
||||
hint: 'Enter Name',
|
||||
isRequired: true,
|
||||
maxLength: 50,
|
||||
),
|
||||
|
||||
CustomTextField(
|
||||
fieldKey: 'description',
|
||||
label: 'Description',
|
||||
hint: 'Enter Description',
|
||||
isRequired: false,
|
||||
maxLength: 1000,
|
||||
),
|
||||
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,75 @@
|
||||
// ignore_for_file: use_build_context_synchronously
|
||||
import 'dart:convert';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../Child_viewModel/Child_view_model_screen.dart';
|
||||
import 'package:base_project/BuilderField/shared/ui/entity_screens.dart';
|
||||
import 'Child_fields.dart';import '../../../../utils/image_constant.dart';
|
||||
import '../../../../utils/size_utils.dart';
|
||||
import '../../../../theme/app_style.dart';
|
||||
import '../../../../widgets/app_bar/appbar_image.dart';
|
||||
import '../../../../widgets/app_bar/appbar_title.dart';
|
||||
import '../../../../widgets/app_bar/custom_app_bar.dart';
|
||||
import 'package:barcode_widget/barcode_widget.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
import '../../../../widgets/custom_button.dart';
|
||||
import '../../../../widgets/custom_text_form_field.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:autocomplete_textfield/autocomplete_textfield.dart';
|
||||
import 'package:qr_flutter/qr_flutter.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import 'dart:math';
|
||||
import '../../../../Reuseable/reusable_text_field.dart';
|
||||
import '../../../../Reuseable/reusable_date_picker_field.dart';
|
||||
import '../../../../Reuseable/reusable_date_time_picker_field.dart';
|
||||
import '../../../../Reuseable/reusable_dropdown_field.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
class ChildUpdateEntityScreen extends StatefulWidget {
|
||||
final Map<String, dynamic> entity;
|
||||
|
||||
|
||||
ChildUpdateEntityScreen({required this.entity});
|
||||
|
||||
@override
|
||||
_ChildUpdateEntityScreenState createState() => _ChildUpdateEntityScreenState();
|
||||
}
|
||||
|
||||
class _ChildUpdateEntityScreenState extends State<ChildUpdateEntityScreen> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer<ChildViewModelScreen>(
|
||||
builder: (context, viewModel, child) {
|
||||
// Start with all fields, then remove upload fields (generic filter by keys)
|
||||
final Set<String> hiddenKeys = {
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
final fields = ChildFields.getFields(context)
|
||||
.where((f) => !hiddenKeys.contains(f.fieldKey))
|
||||
.toList(); return EntityUpdateScreen(
|
||||
fields: fields,
|
||||
initialData: widget.entity,
|
||||
onSubmit: (data) => _handleSubmit(data),
|
||||
title: 'Child',
|
||||
isLoading: viewModel.isLoading,
|
||||
errorMessage:
|
||||
viewModel.errorMessage.isNotEmpty ? viewModel.errorMessage : null,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _handleSubmit(Map<String, dynamic> formData) async {
|
||||
final provider =
|
||||
Provider.of<ChildViewModelScreen>(context, listen: false);
|
||||
final success = await provider.updateEntity(widget.entity['id'], formData);
|
||||
|
||||
if (success && mounted) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,93 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import '../../../../data/network/base_network_service.dart';
|
||||
import '../../../../data/network/network_api_service.dart';
|
||||
import '../../../../resources/api_constants.dart';
|
||||
import 'package:base_project/data/response/api_response.dart';
|
||||
|
||||
class ChildRepoScreen {
|
||||
|
||||
final String baseUrl = ApiConstants.baseUrl;
|
||||
final BaseNetworkService _helper = NetworkApiService();
|
||||
final String _endpointPath = '/Child/Child';
|
||||
|
||||
Future<ApiResponse<List<Map<String, dynamic>>>> getEntities() async {
|
||||
try {
|
||||
final response =
|
||||
await _helper.getGetApiResponse('$baseUrl$_endpointPath');
|
||||
print('Response received: $response');
|
||||
List<Map<String, dynamic>> entities = const [];
|
||||
if (response is List) {
|
||||
entities = response
|
||||
.whereType<Map>()
|
||||
.map((e) => Map<String, dynamic>.from(e as Map))
|
||||
.toList();
|
||||
} else if (response is Map<String, dynamic>) {
|
||||
final dynamic content = response['content'];
|
||||
if (content is List) {
|
||||
entities = content
|
||||
.whereType<Map>()
|
||||
.map((e) => Map<String, dynamic>.from(e as Map))
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
return ApiResponse.success(entities);
|
||||
} catch (e) {
|
||||
print(' error got $e');
|
||||
return ApiResponse.error('Failed to get all entities: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<ApiResponse<List<Map<String, dynamic>>>> getAllWithPagination(
|
||||
int page, int size) async {
|
||||
try {
|
||||
final response = await _helper.getGetApiResponse(
|
||||
'$baseUrl$_endpointPath/getall/page?page=$page&size=$size');
|
||||
|
||||
if (response is Map<String, dynamic> && response['content'] is List) {
|
||||
final List<Map<String, dynamic>> entities =
|
||||
(response['content'] as List).cast<Map<String, dynamic>>().toList();
|
||||
return ApiResponse.success(entities);
|
||||
} else {
|
||||
return ApiResponse.error('Invalid response format');
|
||||
}
|
||||
} catch (e) {
|
||||
return ApiResponse.error('Failed to get all without pagination: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<ApiResponse<Map<String, dynamic>>> createEntity(
|
||||
Map<String, dynamic> entity) async {
|
||||
try {
|
||||
print("in post api$entity");
|
||||
final response =
|
||||
await _helper.getPostApiResponse('$baseUrl$_endpointPath', entity);
|
||||
return ApiResponse.success(response as Map<String, dynamic>);
|
||||
} catch (e) {
|
||||
return ApiResponse.error('Failed to create entity: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<ApiResponse<Map<String, dynamic>>> updateEntity(
|
||||
int entityId, Map<String, dynamic> entity) async {
|
||||
try {
|
||||
final response = await _helper.getPutApiResponse(
|
||||
'$baseUrl$_endpointPath/$entityId', entity);
|
||||
return ApiResponse.success(response as Map<String, dynamic>);
|
||||
} catch (e) {
|
||||
return ApiResponse.error('Failed to update entity: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<ApiResponse<void>> deleteEntity(int entityId) async {
|
||||
try {
|
||||
await _helper.getDeleteApiResponse('$baseUrl$_endpointPath/$entityId');
|
||||
return ApiResponse.success(null);
|
||||
} catch (e) {
|
||||
return ApiResponse.error('Failed to delete entity: $e');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,292 @@
|
||||
import 'package:base_project/data/response/status.dart';
|
||||
import 'dart:typed_data';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
import '../../../../utils/toast_messages/toast_message_util.dart';
|
||||
import '../../../../BuilderField/shared/utils/entity_field_store.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../Child_Repo/Child_repo_screen.dart';
|
||||
|
||||
class ChildViewModelScreen extends ChangeNotifier{
|
||||
final ChildRepoScreen repo = ChildRepoScreen();
|
||||
|
||||
|
||||
// State variables
|
||||
List<Map<String, dynamic>> _childList = [];
|
||||
List<Map<String, dynamic>> _filteredList = [];
|
||||
bool _isLoading = false;
|
||||
String _errorMessage = '';
|
||||
int _currentPage = 0;
|
||||
int _pageSize = 10;
|
||||
bool _hasMoreData = true;
|
||||
String _searchQuery = '';
|
||||
|
||||
// Getters
|
||||
List<Map<String, dynamic>> get childList => _childList;
|
||||
List<Map<String, dynamic>> get filteredList => _filteredList;
|
||||
bool get isLoading => _isLoading;
|
||||
String get errorMessage => _errorMessage;
|
||||
bool get hasMoreData => _hasMoreData;
|
||||
String get searchQuery => _searchQuery;
|
||||
|
||||
// Set loading state
|
||||
void _setLoading(bool loading) {
|
||||
_isLoading = loading;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// Set error message
|
||||
void _setError(String error) {
|
||||
_errorMessage = error;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// Clear error
|
||||
void clearError() {
|
||||
_errorMessage = '';
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// Get child list
|
||||
Future<void> getEntities() async {
|
||||
_setLoading(true);
|
||||
_setError('');
|
||||
|
||||
try {
|
||||
final response = await repo.getEntities();
|
||||
|
||||
if (response.status == Status.SUCCESS) {
|
||||
_childList = response.data ?? [];
|
||||
_filteredList = List.from(_childList);
|
||||
_currentPage = 0;
|
||||
_hasMoreData = true;
|
||||
} else {
|
||||
_setError(response.message ?? 'Failed to fetch child list');
|
||||
}
|
||||
} catch (e) {
|
||||
_setError('Failed to fetch child list: $e');
|
||||
} finally {
|
||||
_setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Get child list with pagination
|
||||
Future<void> getAllWithPagination({bool refresh = false}) async {
|
||||
if (refresh) {
|
||||
_currentPage = 0;
|
||||
_childList.clear();
|
||||
_filteredList.clear();
|
||||
_hasMoreData = true;
|
||||
}
|
||||
|
||||
if (!_hasMoreData || _isLoading) return;
|
||||
|
||||
_setLoading(true);
|
||||
_setError('');
|
||||
|
||||
try {
|
||||
final response = await repo.getAllWithPagination(_currentPage, _pageSize);
|
||||
|
||||
if (response.status == Status.SUCCESS) {
|
||||
final newItems = response.data ?? [];
|
||||
|
||||
if (refresh) {
|
||||
_childList = newItems;
|
||||
} else {
|
||||
_childList.addAll(newItems);
|
||||
}
|
||||
|
||||
_filteredList = List.from(_childList);
|
||||
_currentPage++;
|
||||
|
||||
// Check if we have more data
|
||||
_hasMoreData = newItems.length == _pageSize;
|
||||
} else {
|
||||
_setError(response.message ?? 'Failed to fetch Child list');
|
||||
}
|
||||
} catch (e) {
|
||||
_setError('Failed to fetch child list: $e');
|
||||
} finally {
|
||||
_setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Create Child
|
||||
Future<bool> createEntity(Map<String, dynamic> entity) async {
|
||||
_setLoading(true);
|
||||
_setError('');
|
||||
|
||||
try {
|
||||
|
||||
|
||||
|
||||
|
||||
final response = await repo.createEntity(entity);
|
||||
|
||||
if (response.status == Status.SUCCESS) {
|
||||
// Get the response ID for image upload
|
||||
|
||||
final responseId = response.data!['id'].toString();
|
||||
|
||||
|
||||
|
||||
|
||||
ToastMessageUtil.showToast(
|
||||
message: 'child created successfully',
|
||||
toastType: ToastType.success,
|
||||
);
|
||||
|
||||
// Refresh the list
|
||||
await getEntities();
|
||||
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
} else {
|
||||
_setError(response.message ?? 'Failed to create Child');
|
||||
ToastMessageUtil.showToast(
|
||||
message: response.message ?? 'Failed to create Child',
|
||||
toastType: ToastType.error,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
_setError('Failed to create child: $e');
|
||||
ToastMessageUtil.showToast(
|
||||
message: 'Failed to create Child: $e',
|
||||
toastType: ToastType.error,
|
||||
);
|
||||
return false;
|
||||
} finally {
|
||||
_setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Update child
|
||||
Future<bool> updateEntity(int id, Map<String, dynamic> entity) async {
|
||||
_setLoading(true);
|
||||
_setError('');
|
||||
|
||||
try {
|
||||
final response = await repo.updateEntity(id, entity);
|
||||
|
||||
if (response.status == Status.SUCCESS) {
|
||||
ToastMessageUtil.showToast(
|
||||
message: 'Child updated successfully',
|
||||
toastType: ToastType.success,
|
||||
);
|
||||
|
||||
// Update the item in the list
|
||||
final index = _childList.indexWhere((item) => item['id'] == id);
|
||||
if (index != -1) {
|
||||
_childList[index] = response.data!;
|
||||
_filteredList = List.from(_childList);
|
||||
notifyListeners();
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
_setError(response.message ?? 'Failed to update Child');
|
||||
ToastMessageUtil.showToast(
|
||||
message: response.message ?? 'Failed to update Child',
|
||||
toastType: ToastType.error,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
_setError('Failed to update child: $e');
|
||||
ToastMessageUtil.showToast(
|
||||
message: 'Failed to update Child: $e',
|
||||
toastType: ToastType.error,
|
||||
);
|
||||
return false;
|
||||
} finally {
|
||||
_setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Delete child
|
||||
Future<bool> deleteEntity(int id) async {
|
||||
_setLoading(true);
|
||||
_setError('');
|
||||
|
||||
try {
|
||||
final response = await repo.deleteEntity(id);
|
||||
|
||||
if (response.status == Status.SUCCESS) {
|
||||
ToastMessageUtil.showToast(
|
||||
message: 'Child deleted successfully',
|
||||
toastType: ToastType.success,
|
||||
);
|
||||
|
||||
// Remove the item from the list
|
||||
_childList.removeWhere((item) => item['id'] == id);
|
||||
_filteredList = List.from(_childList);
|
||||
notifyListeners();
|
||||
return true;
|
||||
} else {
|
||||
_setError(response.message ?? 'Failed to delete Child');
|
||||
ToastMessageUtil.showToast(
|
||||
message: response.message ?? 'Failed to delete Child',
|
||||
toastType: ToastType.error,
|
||||
);
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
_setError('Failed to delete child: $e');
|
||||
ToastMessageUtil.showToast(
|
||||
message: 'Failed to delete Child: $e',
|
||||
toastType: ToastType.error,
|
||||
);
|
||||
return false;
|
||||
} finally {
|
||||
_setLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Search child
|
||||
void searchchild(String query) {
|
||||
_searchQuery = query;
|
||||
|
||||
if (query.isEmpty) {
|
||||
_filteredList = List.from(_childList);
|
||||
} else {
|
||||
_filteredList = _childList.where((item) {
|
||||
return
|
||||
|
||||
|
||||
(item['name']?.toString().toLowerCase().contains(query.toLowerCase()) ??false) ||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(item['description']?.toString().toLowerCase().contains(query.toLowerCase()) ??false)
|
||||
|
||||
|
||||
;
|
||||
}).toList();
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// Clear search
|
||||
void clearSearch() {
|
||||
_searchQuery = '';
|
||||
_filteredList = List.from(_childList);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// Refresh data
|
||||
Future<void> refreshData() async {
|
||||
await getAllWithPagination(refresh: true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -69,6 +69,12 @@ public class BuilderService {
|
||||
executeDump(true);
|
||||
|
||||
// ADD OTHER SERVICE
|
||||
addCustomMenu( "Child","Child", "Transcations");
|
||||
|
||||
|
||||
addCustomMenu( "Ad6","Ad6", "Transcations");
|
||||
|
||||
|
||||
|
||||
System.out.println("dashboard and menu inserted...");
|
||||
|
||||
|
||||
@ -0,0 +1,115 @@
|
||||
package com.realnet.angulardatatype.Controllers;
|
||||
import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.realnet.config.EmailService;
|
||||
import com.realnet.users.entity1.AppUser;
|
||||
import com.realnet.users.service1.AppUserServiceImpl;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.data.domain.*;
|
||||
import com.realnet.fnd.response.EntityResponse;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.beans.factory.annotation.*;
|
||||
import com.realnet.angulardatatype.Entity.Ad6;
|
||||
import com.realnet.angulardatatype.Services.Ad6Service ;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@RequestMapping(value = "/Ad6")
|
||||
@CrossOrigin("*")
|
||||
@RestController
|
||||
public class Ad6Controller {
|
||||
@Autowired
|
||||
private Ad6Service Service;
|
||||
|
||||
@Value("${projectPath}")
|
||||
private String projectPath;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@PostMapping("/Ad6")
|
||||
public Ad6 Savedata(@RequestBody Ad6 data) {
|
||||
Ad6 save = Service.Savedata(data) ;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
System.out.println("data saved..." + save);
|
||||
|
||||
return save;
|
||||
}
|
||||
@PutMapping("/Ad6/{id}")
|
||||
public Ad6 update(@RequestBody Ad6 data,@PathVariable Integer id ) {
|
||||
Ad6 update = Service.update(data,id);
|
||||
System.out.println("data update..." + update);
|
||||
return update;
|
||||
}
|
||||
// get all with pagination
|
||||
@GetMapping("/Ad6/getall/page")
|
||||
public Page<Ad6> getall(@RequestParam(value = "page", required = false) Integer page,
|
||||
@RequestParam(value = "size", required = false) Integer size) {
|
||||
Pageable paging = PageRequest.of(page, size);
|
||||
Page<Ad6> get = Service.getAllWithPagination(paging);
|
||||
|
||||
return get;
|
||||
|
||||
}
|
||||
@GetMapping("/Ad6")
|
||||
public List<Ad6> getdetails() {
|
||||
List<Ad6> get = Service.getdetails();
|
||||
return get;
|
||||
}
|
||||
// get all without authentication
|
||||
|
||||
@GetMapping("/token/Ad6")
|
||||
public List<Ad6> getallwioutsec() {
|
||||
List<Ad6> get = Service.getdetails();
|
||||
return get;
|
||||
}
|
||||
@GetMapping("/Ad6/{id}")
|
||||
public Ad6 getdetailsbyId(@PathVariable Integer id ) {
|
||||
Ad6 get = Service.getdetailsbyId(id);
|
||||
return get;
|
||||
}
|
||||
@DeleteMapping("/Ad6/{id}")
|
||||
public ResponseEntity<?> delete_by_id(@PathVariable Integer id ) {
|
||||
Service.delete_by_id(id);
|
||||
return new ResponseEntity<>(new EntityResponse("Deleted"), HttpStatus.OK);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,91 @@
|
||||
package com.realnet.angulardatatype.Controllers;
|
||||
import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.realnet.config.EmailService;
|
||||
import com.realnet.users.entity1.AppUser;
|
||||
import com.realnet.users.service1.AppUserServiceImpl;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.data.domain.*;
|
||||
import com.realnet.fnd.response.EntityResponse;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.beans.factory.annotation.*;
|
||||
import com.realnet.angulardatatype.Entity.Child;
|
||||
import com.realnet.angulardatatype.Services.ChildService ;
|
||||
|
||||
|
||||
|
||||
|
||||
@RequestMapping(value = "/Child")
|
||||
@CrossOrigin("*")
|
||||
@RestController
|
||||
public class ChildController {
|
||||
@Autowired
|
||||
private ChildService Service;
|
||||
|
||||
@Value("${projectPath}")
|
||||
private String projectPath;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@PostMapping("/Child")
|
||||
public Child Savedata(@RequestBody Child data) {
|
||||
Child save = Service.Savedata(data) ;
|
||||
|
||||
|
||||
|
||||
System.out.println("data saved..." + save);
|
||||
|
||||
return save;
|
||||
}
|
||||
@PutMapping("/Child/{id}")
|
||||
public Child update(@RequestBody Child data,@PathVariable Integer id ) {
|
||||
Child update = Service.update(data,id);
|
||||
System.out.println("data update..." + update);
|
||||
return update;
|
||||
}
|
||||
// get all with pagination
|
||||
@GetMapping("/Child/getall/page")
|
||||
public Page<Child> getall(@RequestParam(value = "page", required = false) Integer page,
|
||||
@RequestParam(value = "size", required = false) Integer size) {
|
||||
Pageable paging = PageRequest.of(page, size);
|
||||
Page<Child> get = Service.getAllWithPagination(paging);
|
||||
|
||||
return get;
|
||||
|
||||
}
|
||||
@GetMapping("/Child")
|
||||
public List<Child> getdetails() {
|
||||
List<Child> get = Service.getdetails();
|
||||
return get;
|
||||
}
|
||||
// get all without authentication
|
||||
|
||||
@GetMapping("/token/Child")
|
||||
public List<Child> getallwioutsec() {
|
||||
List<Child> get = Service.getdetails();
|
||||
return get;
|
||||
}
|
||||
@GetMapping("/Child/{id}")
|
||||
public Child getdetailsbyId(@PathVariable Integer id ) {
|
||||
Child get = Service.getdetailsbyId(id);
|
||||
return get;
|
||||
}
|
||||
@DeleteMapping("/Child/{id}")
|
||||
public ResponseEntity<?> delete_by_id(@PathVariable Integer id ) {
|
||||
Service.delete_by_id(id);
|
||||
return new ResponseEntity<>(new EntityResponse("Deleted"), HttpStatus.OK);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,115 @@
|
||||
package com.realnet.angulardatatype.Controllers;
|
||||
import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.realnet.config.EmailService;
|
||||
import com.realnet.users.entity1.AppUser;
|
||||
import com.realnet.users.service1.AppUserServiceImpl;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.data.domain.*;
|
||||
import com.realnet.fnd.response.EntityResponse;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.beans.factory.annotation.*;
|
||||
import com.realnet.angulardatatype.Entity.Ad6;
|
||||
import com.realnet.angulardatatype.Services.Ad6Service ;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@RequestMapping(value = "/token/Ad6")
|
||||
@CrossOrigin("*")
|
||||
@RestController
|
||||
public class tokenFree_Ad6Controller {
|
||||
@Autowired
|
||||
private Ad6Service Service;
|
||||
|
||||
@Value("${projectPath}")
|
||||
private String projectPath;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@PostMapping("/Ad6")
|
||||
public Ad6 Savedata(@RequestBody Ad6 data) {
|
||||
Ad6 save = Service.Savedata(data) ;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
System.out.println("data saved..." + save);
|
||||
|
||||
return save;
|
||||
}
|
||||
@PutMapping("/Ad6/{id}")
|
||||
public Ad6 update(@RequestBody Ad6 data,@PathVariable Integer id ) {
|
||||
Ad6 update = Service.update(data,id);
|
||||
System.out.println("data update..." + update);
|
||||
return update;
|
||||
}
|
||||
// get all with pagination
|
||||
@GetMapping("/Ad6/getall/page")
|
||||
public Page<Ad6> getall(@RequestParam(value = "page", required = false) Integer page,
|
||||
@RequestParam(value = "size", required = false) Integer size) {
|
||||
Pageable paging = PageRequest.of(page, size);
|
||||
Page<Ad6> get = Service.getAllWithPagination(paging);
|
||||
|
||||
return get;
|
||||
|
||||
}
|
||||
@GetMapping("/Ad6")
|
||||
public List<Ad6> getdetails() {
|
||||
List<Ad6> get = Service.getdetails();
|
||||
return get;
|
||||
}
|
||||
// get all without authentication
|
||||
|
||||
@GetMapping("/token/Ad6")
|
||||
public List<Ad6> getallwioutsec() {
|
||||
List<Ad6> get = Service.getdetails();
|
||||
return get;
|
||||
}
|
||||
@GetMapping("/Ad6/{id}")
|
||||
public Ad6 getdetailsbyId(@PathVariable Integer id ) {
|
||||
Ad6 get = Service.getdetailsbyId(id);
|
||||
return get;
|
||||
}
|
||||
@DeleteMapping("/Ad6/{id}")
|
||||
public ResponseEntity<?> delete_by_id(@PathVariable Integer id ) {
|
||||
Service.delete_by_id(id);
|
||||
return new ResponseEntity<>(new EntityResponse("Deleted"), HttpStatus.OK);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,91 @@
|
||||
package com.realnet.angulardatatype.Controllers;
|
||||
import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.realnet.config.EmailService;
|
||||
import com.realnet.users.entity1.AppUser;
|
||||
import com.realnet.users.service1.AppUserServiceImpl;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.data.domain.*;
|
||||
import com.realnet.fnd.response.EntityResponse;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.beans.factory.annotation.*;
|
||||
import com.realnet.angulardatatype.Entity.Child;
|
||||
import com.realnet.angulardatatype.Services.ChildService ;
|
||||
|
||||
|
||||
|
||||
|
||||
@RequestMapping(value = "/token/Child")
|
||||
@CrossOrigin("*")
|
||||
@RestController
|
||||
public class tokenFree_ChildController {
|
||||
@Autowired
|
||||
private ChildService Service;
|
||||
|
||||
@Value("${projectPath}")
|
||||
private String projectPath;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@PostMapping("/Child")
|
||||
public Child Savedata(@RequestBody Child data) {
|
||||
Child save = Service.Savedata(data) ;
|
||||
|
||||
|
||||
|
||||
System.out.println("data saved..." + save);
|
||||
|
||||
return save;
|
||||
}
|
||||
@PutMapping("/Child/{id}")
|
||||
public Child update(@RequestBody Child data,@PathVariable Integer id ) {
|
||||
Child update = Service.update(data,id);
|
||||
System.out.println("data update..." + update);
|
||||
return update;
|
||||
}
|
||||
// get all with pagination
|
||||
@GetMapping("/Child/getall/page")
|
||||
public Page<Child> getall(@RequestParam(value = "page", required = false) Integer page,
|
||||
@RequestParam(value = "size", required = false) Integer size) {
|
||||
Pageable paging = PageRequest.of(page, size);
|
||||
Page<Child> get = Service.getAllWithPagination(paging);
|
||||
|
||||
return get;
|
||||
|
||||
}
|
||||
@GetMapping("/Child")
|
||||
public List<Child> getdetails() {
|
||||
List<Child> get = Service.getdetails();
|
||||
return get;
|
||||
}
|
||||
// get all without authentication
|
||||
|
||||
@GetMapping("/token/Child")
|
||||
public List<Child> getallwioutsec() {
|
||||
List<Child> get = Service.getdetails();
|
||||
return get;
|
||||
}
|
||||
@GetMapping("/Child/{id}")
|
||||
public Child getdetailsbyId(@PathVariable Integer id ) {
|
||||
Child get = Service.getdetailsbyId(id);
|
||||
return get;
|
||||
}
|
||||
@DeleteMapping("/Child/{id}")
|
||||
public ResponseEntity<?> delete_by_id(@PathVariable Integer id ) {
|
||||
Service.delete_by_id(id);
|
||||
return new ResponseEntity<>(new EntityResponse("Deleted"), HttpStatus.OK);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
package com.realnet.angulardatatype.Entity;
|
||||
import lombok.*;
|
||||
import com.realnet.WhoColumn.Entity.Extension;
|
||||
import javax.persistence.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
|
||||
|
||||
import com.realnet.angulardatatype.Entity.Child;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
public class Ad6 extends Extension {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String description;
|
||||
|
||||
@OneToOne( cascade=CascadeType.ALL)
|
||||
private Child child;
|
||||
|
||||
|
||||
|
||||
private String fileupload_fieldsname;
|
||||
private String fileupload_fieldspath ;
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
package com.realnet.angulardatatype.Entity;
|
||||
import lombok.*;
|
||||
import com.realnet.WhoColumn.Entity.Extension;
|
||||
import javax.persistence.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
|
||||
|
||||
@Entity
|
||||
@Data
|
||||
public class Child extends Extension {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer id;
|
||||
|
||||
private String name;
|
||||
|
||||
@Column(length = 2000)
|
||||
private String description;
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
package com.realnet.angulardatatype.Repository;
|
||||
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
import com.realnet.angulardatatype.Entity.Ad6;
|
||||
|
||||
@Repository
|
||||
public interface Ad6Repository extends JpaRepository<Ad6, Integer> {
|
||||
|
||||
@Query(value = "select * from ad6 where created_by=?1", nativeQuery = true)
|
||||
List<Ad6> findAll(Long creayedBy);
|
||||
|
||||
@Query(value = "select * from ad6 where created_by=?1", nativeQuery = true)
|
||||
Page<Ad6> findAll( Long creayedBy,Pageable page);
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
package com.realnet.angulardatatype.Repository;
|
||||
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
import com.realnet.angulardatatype.Entity.Child;
|
||||
|
||||
@Repository
|
||||
public interface ChildRepository extends JpaRepository<Child, Integer> {
|
||||
|
||||
@Query(value = "select * from child where created_by=?1", nativeQuery = true)
|
||||
List<Child> findAll(Long creayedBy);
|
||||
|
||||
@Query(value = "select * from child where created_by=?1", nativeQuery = true)
|
||||
Page<Child> findAll( Long creayedBy,Pageable page);
|
||||
}
|
||||
@ -0,0 +1,113 @@
|
||||
package com.realnet.angulardatatype.Services;
|
||||
import com.realnet.angulardatatype.Repository.Ad6Repository;
|
||||
import com.realnet.angulardatatype.Entity.Ad6
|
||||
;import java.util.*;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import com.realnet.SequenceGenerator.Service.SequenceService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import com.realnet.realm.Entity.Realm;
|
||||
import com.realnet.realm.Services.RealmService;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.*;
|
||||
import com.realnet.users.service1.AppUserServiceImpl;
|
||||
import com.realnet.users.entity1.AppUser;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class Ad6Service {
|
||||
@Autowired
|
||||
private Ad6Repository Repository;
|
||||
@Autowired
|
||||
private AppUserServiceImpl userService;
|
||||
@Autowired
|
||||
private RealmService realmService;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public Ad6 Savedata(Ad6 data) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
data.setUpdatedBy(getUser().getUserId());
|
||||
data.setCreatedBy(getUser().getUserId());
|
||||
data.setAccountId(getUser().getAccount().getAccount_id());
|
||||
Ad6 save = Repository.save(data);
|
||||
return save;
|
||||
}
|
||||
|
||||
|
||||
// get all with pagination
|
||||
public Page<Ad6> getAllWithPagination(Pageable page) {
|
||||
return Repository.findAll( getUser().getUserId(),page);
|
||||
}
|
||||
public List<Ad6> getdetails() {
|
||||
List<Realm> realm = realmService.findByUserId(getUser().getUserId());
|
||||
List<Ad6> all = Repository.findAll(getUser().getUserId());
|
||||
|
||||
return all ; }
|
||||
|
||||
|
||||
public Ad6 getdetailsbyId(Integer id) {
|
||||
return Repository.findById(id).get();
|
||||
}
|
||||
|
||||
|
||||
public void delete_by_id(Integer id) {
|
||||
Repository.deleteById(id);
|
||||
}
|
||||
|
||||
|
||||
public Ad6 update(Ad6 data,Integer id) {
|
||||
Ad6 old = Repository.findById(id).get();
|
||||
old.setName(data.getName());
|
||||
|
||||
old.setDescription(data.getDescription());
|
||||
|
||||
old.setChild(data.getChild());
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
final Ad6 test = Repository.save(old);
|
||||
data.setUpdatedBy(getUser().getUserId());
|
||||
return test;}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public AppUser getUser() {
|
||||
AppUser user = userService.getLoggedInUser();
|
||||
return user;
|
||||
|
||||
}}
|
||||
@ -0,0 +1,83 @@
|
||||
package com.realnet.angulardatatype.Services;
|
||||
import com.realnet.angulardatatype.Repository.ChildRepository;
|
||||
import com.realnet.angulardatatype.Entity.Child
|
||||
;import java.util.*;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import com.realnet.SequenceGenerator.Service.SequenceService;
|
||||
import org.springframework.data.domain.Page;
|
||||
import com.realnet.realm.Entity.Realm;
|
||||
import com.realnet.realm.Services.RealmService;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.*;
|
||||
import com.realnet.users.service1.AppUserServiceImpl;
|
||||
import com.realnet.users.entity1.AppUser;
|
||||
|
||||
|
||||
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class ChildService {
|
||||
@Autowired
|
||||
private ChildRepository Repository;
|
||||
@Autowired
|
||||
private AppUserServiceImpl userService;
|
||||
@Autowired
|
||||
private RealmService realmService;
|
||||
|
||||
|
||||
|
||||
public Child Savedata(Child data) {
|
||||
|
||||
|
||||
|
||||
|
||||
data.setUpdatedBy(getUser().getUserId());
|
||||
data.setCreatedBy(getUser().getUserId());
|
||||
data.setAccountId(getUser().getAccount().getAccount_id());
|
||||
Child save = Repository.save(data);
|
||||
return save;
|
||||
}
|
||||
|
||||
|
||||
// get all with pagination
|
||||
public Page<Child> getAllWithPagination(Pageable page) {
|
||||
return Repository.findAll( getUser().getUserId(),page);
|
||||
}
|
||||
public List<Child> getdetails() {
|
||||
List<Realm> realm = realmService.findByUserId(getUser().getUserId());
|
||||
List<Child> all = Repository.findAll(getUser().getUserId());
|
||||
|
||||
return all ; }
|
||||
|
||||
|
||||
public Child getdetailsbyId(Integer id) {
|
||||
return Repository.findById(id).get();
|
||||
}
|
||||
|
||||
|
||||
public void delete_by_id(Integer id) {
|
||||
Repository.deleteById(id);
|
||||
}
|
||||
|
||||
|
||||
public Child update(Child data,Integer id) {
|
||||
Child old = Repository.findById(id).get();
|
||||
old.setName(data.getName());
|
||||
|
||||
old.setDescription(data.getDescription());
|
||||
|
||||
final Child test = Repository.save(old);
|
||||
data.setUpdatedBy(getUser().getUserId());
|
||||
return test;}
|
||||
|
||||
|
||||
|
||||
|
||||
public AppUser getUser() {
|
||||
AppUser user = userService.getLoggedInUser();
|
||||
return user;
|
||||
|
||||
}}
|
||||
Loading…
x
Reference in New Issue
Block a user