Skip to content

Commit

Permalink
updated with repository code
Browse files Browse the repository at this point in the history
  • Loading branch information
MeherajUlMahmmud committed Mar 6, 2024
1 parent 69b0b0a commit 8e9847b
Show file tree
Hide file tree
Showing 8 changed files with 426 additions and 223 deletions.
1 change: 0 additions & 1 deletion lib/pages/award/AwardPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class _AwardPageState extends State<AwardPage> {

fetchAwards(String resumeId) {
Map<String, dynamic> response = awardRepository.getAwards(widget.resumeId);
print(response);

if (response['status'] == Constants.httpOkCode) {
setState(() {
Expand Down
11 changes: 7 additions & 4 deletions lib/pages/contact/ContactPage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ class _ContactPageState extends State<ContactPage> {
}

fetchContactDetails() {
Map<String, dynamic> response =
contactRepository.getContactDetails(widget.resumeId);
Map<String, dynamic> response = contactRepository.getContactDetails(
widget.resumeId,
);
print(response);

if (response['status'] == Constants.httpOkCode) {
Expand Down Expand Up @@ -111,8 +112,10 @@ class _ContactPageState extends State<ContactPage> {
}

handleUpdateContactDetails() {
Map<String, dynamic> response =
contactRepository.updateContactDetails(contactId, updatedContactData);
Map<String, dynamic> response = contactRepository.updateContactDetails(
contactId,
updatedContactData,
);
print(response);

if (response['status'] == Constants.httpOkCode) {
Expand Down
303 changes: 181 additions & 122 deletions lib/pages/education/AddEditEducation.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import 'package:flutter/material.dart';
import 'package:gocv/apis/api.dart';
import 'package:gocv/models/education.dart';
import 'package:gocv/repositories/education.dart';
import 'package:gocv/utils/constants.dart';
import 'package:gocv/utils/helper.dart';
import 'package:gocv/utils/urls.dart';
import 'package:gocv/widgets/custom_button.dart';
import 'package:gocv/widgets/custom_text_form_field.dart';

Expand Down Expand Up @@ -78,7 +76,7 @@ class _AddEditEducationPageState extends State<AddEditEducationPage> {

fetchData() async {
if (widget.educationId != null) {
fetchEducation(widget.educationId!);
fetchEducationDetails(widget.educationId!);
} else {
educationData['resume'] = widget.resumeId;
setState(() {
Expand Down Expand Up @@ -112,120 +110,190 @@ class _AddEditEducationPageState extends State<AddEditEducationPage> {
});
}

fetchEducation(String educationId) {
// String url = '${URLS.kEducationUrl}$educationId/details/';
// APIService()
// .sendGetRequest(
// accessToken,
// url,
// )
// .then((data) {
// if (data['status'] == Constants.HTTP_OK) {
// setState(() {
// education = Education.fromJson(data['data']);
// isError = false;
// });

// initiateControllers();
// } else {
// setState(() {
// isLoading = false;
// isError = true;
// errorText = data['data']['detail'];
// });
// Helper().showSnackBar(
// context,
// errorText,
// Colors.red,
// );
// }
// });
fetchEducationDetails(String educationId) async {
try {
final response = await educationRepository.getEducationDetails(
educationId,
);

if (response['status'] == Constants.httpOkCode) {
setState(() {
education = Education.fromJson(response['data']);
isError = false;
});

initiateControllers();
} else {
if (Helper().isUnauthorizedAccess(response['status'])) {
if (!mounted) return;
Helper().showSnackBar(
context,
Constants.sessionExpiredMsg,
Colors.red,
);
Helper().logoutUser(context);
} else {
setState(() {
isLoading = false;
isError = true;
errorText = response['error'];
});
if (!mounted) return;
Helper().showSnackBar(
context,
'Failed to fetch education details',
Colors.red,
);
Navigator.pop(context);
}
}
} catch (error) {
setState(() {
isLoading = false;
isError = true;
errorText = 'Error fetching education details: $error';
});
if (!mounted) return;
Helper().showSnackBar(
context,
'Error fetching education details',
Colors.red,
);
}
}

createEducation() {
// EducationService()
// .createEducation(
// tokens['access'],
// widget.resumeId,
// schoolName,
// degree,
// department,
// gradeScale,
// grade,
// startDate,
// endDate,
// description,
// isCurrentlyEnrolled,
// )
// .then((value) {
// if (value['status'] == Constants.HTTP_CREATED) {
// Navigator.pop(context);
// } else {
// setState(() {
// isLoading = false;
// isError = true;
// errorText = value['error'];
// });
// }
// }).catchError((error) {
// setState(() {
// isLoading = false;
// isError = true;
// errorText = error.toString();
// });
// Helper().showSnackBar(
// context,
// error.toString(),
// Colors.red,
// );
// });
createEducation() async {
try {
final response = await educationRepository.createEducation(educationData);

if (response['status'] == Constants.httpCreatedCode) {
setState(() {
education = Education.fromJson(response['data']);
isError = false;
});

if (!mounted) return;
Helper().showSnackBar(
context,
'Education details added',
Colors.green,
);
Navigator.pop(context);
} else {
setState(() {
isLoading = false;
isError = true;
errorText = response['error'];
});
if (!mounted) return;
Helper().showSnackBar(
context,
'Failed to add education details',
Colors.red,
);
}
} catch (error) {
setState(() {
isLoading = false;
isError = true;
errorText = 'Error adding education details: $error';
});
Helper().showSnackBar(
context,
'Error adding education details',
Colors.red,
);
}
}

updateEducation(String educationId) {
// String url = '${URLS.kEducationUrl}$educationId/update/';
// APIService()
// .sendPatchRequest(
// accessToken,
// educationData,
// url,
// )
// .then((data) async {
// if (data['status'] == Constants.HTTP_OK) {
// setState(() {
// education = Education.fromJson(data['data']);
// isLoading = false;
// isError = false;
// });

// Helper().showSnackBar(
// context,
// 'Education details updated',
// Colors.green,
// );
// } else {
// setState(() {
// isLoading = false;
// isError = true;
// errorText = data['data']['detail'];
// });
// Helper().showSnackBar(
// context,
// errorText,
// Colors.red,
// );
// }
// }).catchError((error) {
// setState(() {
// isLoading = false;
// isError = true;
// errorText = error.toString();
// });
// Helper().showSnackBar(
// context,
// 'Error updating education',
// Colors.red,
// );
// });
try {
final response = educationRepository.updateEducation(
educationId,
educationData,
);

if (response['status'] == Constants.httpOkCode) {
setState(() {
education = Education.fromJson(response['data']);
isError = false;
});

if (!mounted) return;
Helper().showSnackBar(
context,
'Education details updated',
Colors.green,
);
Navigator.pop(context);
} else {
setState(() {
isLoading = false;
isError = true;
errorText = response['error'];
});
if (!mounted) return;
Helper().showSnackBar(
context,
'Failed to update education details',
Colors.red,
);
}
} catch (error) {
setState(() {
isLoading = false;
isError = true;
errorText = 'Error updating education details: $error';
});
Helper().showSnackBar(
context,
'Error updating education details',
Colors.red,
);
}
}

deleteEducation(String educationId) {
try {
final response = educationRepository.deleteEducation(educationId);

if (response['status'] == Constants.httpDeletedCode) {
setState(() {
isError = false;
});

if (!mounted) return;
Helper().showSnackBar(
context,
'Education details deleted',
Colors.green,
);
Navigator.pop(context);
} else {
setState(() {
isLoading = false;
isError = true;
errorText = response['error'];
});
if (!mounted) return;
Helper().showSnackBar(
context,
'Failed to delete education details',
Colors.red,
);
}
} catch (error) {
setState(() {
isLoading = false;
isError = true;
errorText = 'Error deleting education details: $error';
});
Helper().showSnackBar(
context,
'Error deleting education details',
Colors.red,
);
}
}

handleSubmit() {
Expand Down Expand Up @@ -299,10 +367,7 @@ class _AddEditEducationPageState extends State<AddEditEducationPage> {
),
TextButton(
onPressed: () {
// deleteExperience(
// tokens['access'],
// widget.experienceId!,
// );
deleteEducation(widget.educationId!);
},
child: const Text(
'Delete',
Expand Down Expand Up @@ -333,12 +398,6 @@ class _AddEditEducationPageState extends State<AddEditEducationPage> {
],
),
resizeToAvoidBottomInset: false,
// floatingActionButton: FloatingActionButton(
// child: const Icon(Icons.save),
// onPressed: () {
// if (_formKey.currentState!.validate()) handleSubmit();
// },
// ),
bottomNavigationBar: Container(
padding: const EdgeInsets.symmetric(
horizontal: 10.0,
Expand Down
Loading

0 comments on commit 8e9847b

Please sign in to comment.