Skip to content

Commit

Permalink
Merge pull request #34 from aninarafath6/admin
Browse files Browse the repository at this point in the history
batch  functions :- admin 🔢
  • Loading branch information
aninarafath6 committed Dec 2, 2022
2 parents c9915bf + c9c0f17 commit 6f78a60
Show file tree
Hide file tree
Showing 24 changed files with 797 additions and 489 deletions.
Binary file modified .DS_Store
Binary file not shown.
8 changes: 8 additions & 0 deletions arnhss-app/lib/common/routes/app_routes.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import 'package:arnhss/common/routes/index_routes.dart';
import 'package:arnhss/features/users/admin/admission/model/batch_model.dart';
import 'package:arnhss/features/users/admin/admission/model/course_model.dart';
import 'package:arnhss/features/users/admin/admission/views/admission_view.dart';
import 'package:arnhss/features/users/admin/admission/views/batch_view.dart';
import 'package:arnhss/features/users/admin/home.admin/views/notice.view.admin.dart';
import 'package:arnhss/features/users/role_wrapper.dart';
import 'package:arnhss/features/users/student/profile/view/profile_view.dart';
Expand All @@ -22,6 +25,11 @@ class AppRoutes {
return MaterialPageRoute(builder: (_) => const NoticeView());
case AdmissionView.routeName:
return MaterialPageRoute(builder: (_) => const AdmissionView());
case BatchView.routeName:
return MaterialPageRoute(builder: (_) {
final Course args = settings.arguments as Course;
return BatchView(selectedCourse: args);
});

// case UserRole.routeName:
// return MaterialPageRoute(builder: (_) => const UserRole());
Expand Down
38 changes: 38 additions & 0 deletions arnhss-app/lib/common/widgets/custom_modal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:arnhss/extensions/string_extension.dart';
import 'package:arnhss/features/authentication/login/view_model/login_view_model.dart';
import 'package:arnhss/features/authentication/otp_verification/view/index.dart';
import 'package:arnhss/features/users/admin/admission/view_model/admission_view_model.dart';
import 'package:arnhss/features/users/admin/admission/view_model/batch_view_model.dart';
import 'package:arnhss/features/users/view_model/notice_view_model.dart';
import 'package:flutter/cupertino.dart';

Expand Down Expand Up @@ -124,6 +125,43 @@ Future<dynamic> courseModal(
);
}

Future<dynamic> batchModal(
BuildContext context, {
required String content,
required String title,
String deny = 'EDIT',
required Widget done,
VoidCallback? onDeny,
VoidCallback? onDone,
}) {
return showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text(title),
content: Text(
content,
style: CustomTextTheme(context: context)
.paragraph()
.copyWith(fontSize: 15),
),
actions: [
TextButton(onPressed: onDeny, child: Text(deny)),
TextButton(
onPressed: onDone,
child: Provider.of<BatchViewModel>(context).getDeleteLoading
? const CupertinoActivityIndicator(
color: CustomColors.dark,
)
: done,
),
],
actionsAlignment: MainAxisAlignment.spaceBetween,
);
},
);
}

customModal<T>(
BuildContext context, {
required String content,
Expand Down
2 changes: 1 addition & 1 deletion arnhss-app/lib/common/widgets/custom_selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CustomSelector extends StatelessWidget {
fontSize: 13,
),
),
// SizedBox(height: 2),
const SizedBox(height: 2),
Text(
content ?? "",
style: const TextStyle(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// ignore_for_file: non_constant_identifier_names

import 'package:cloud_firestore/cloud_firestore.dart';

class Batch {
final String id;
late final String code;
final String name;
final DateTime startDate;
final DateTime endDate;

Batch({
required this.name,
required this.code,
required this.id,
required this.endDate,
required this.startDate,
});

Map<String, dynamic> toMap() => {
"code": code.toUpperCase(),
"name": name,
"start_date": Timestamp.fromDate(startDate),
"end_date": Timestamp.fromDate(endDate),
};

factory Batch.fromMap(Map<String, dynamic> batchMap) {
Timestamp _startDate = batchMap["start_date"] as Timestamp;
Timestamp _endDate = batchMap["end_date"] as Timestamp;

return Batch(
id: batchMap["id"],
name: batchMap["name"].toString().toUpperCase(),
code: batchMap["code"].toString(),
startDate: _startDate.toDate(),
endDate: _endDate.toDate(),
);
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:developer';

import 'package:arnhss/common/routes/index_routes.dart';
import 'package:arnhss/features/users/admin/admission/model/batch_model.dart';
import 'package:arnhss/features/users/admin/admission/model/course_model.dart';
import 'package:arnhss/services/base/exception/app_exceptions.dart';
import 'package:arnhss/services/base/exception/handle_exception.dart';
Expand Down Expand Up @@ -78,4 +79,71 @@ class AdmissionService with HandleException {
handleException(e);
}
}

//* batch service

Future<List<Batch>?> getBatches(Course course) async {
try {
//* fetching sorted course data by course code
QuerySnapshot<Map<String, dynamic>> querySnapshot = await _firestore
.collection("course/${course.id}/batches")
.orderBy("code")
.get();

return querySnapshot.docs
.map((e) => Batch.fromMap(
{
...e.data(),
"id": e.id,
},
))
.toList();
} catch (e) {
print(e);
handleException(
InvalidException("Something wrong with course 🤯", false));
return null;
}
}

Future<Batch?> addBatch(Batch newBatch, {required String courseId}) async {
try {
CollectionReference collectionRef =
_firestore.collection("course/$courseId/batches");

DocumentReference docRef = await collectionRef.add(newBatch.toMap());
var data = await docRef.get();

return Batch.fromMap(
{
...(data.data() as Map<String, dynamic>),
"id": docRef.id,
},
);
} catch (e) {
handleException(
InvalidException(
"Batch cannot be added because there is something wrong with them 🤯",
false,
),
);
return null;
}
}

Future<void> deleteBatch(Batch batch, {required String courseId}) async {
try {
CollectionReference collectionReference =
_firestore.collection("course/$courseId/batches");
collectionReference.doc(batch.id).delete().then((value) {
debugPrint("batch deleted successfully");
return null;
}).catchError((onError) {
debugPrint("batch is not deleted");
throw InvalidException("batch deletion failed..😟", false);
});
} catch (e) {
handleException(e);
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ class AdmissionViewModel with ChangeNotifier, HandleException {
}

//* add course functionality

Future<bool> addCourse() async {
bool isValid = validate();

Expand Down
Loading

0 comments on commit 6f78a60

Please sign in to comment.