Skip to content

Commit

Permalink
feat: adds Room No change request
Browse files Browse the repository at this point in the history
  • Loading branch information
am-casper committed Jan 2, 2024
1 parent 66448bb commit e3de526
Show file tree
Hide file tree
Showing 6 changed files with 256 additions and 206 deletions.
3 changes: 2 additions & 1 deletion lib/domain/repositories/user/user_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,10 @@ class UserRepository {
}
}

Future<void> postChangeHostel(String hostelCode) async {
Future<void> postChangeHostel(String hostelCode, String roomNo) async {
Map<String, dynamic> map = {
'new_hostel_code': hostelCode,
'new_room_no': roomNo
};
try {
return await _apiService.postChangeHostel(map);
Expand Down
12 changes: 11 additions & 1 deletion lib/presentation/hostel_change/bloc/hostel_change_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,18 @@ class HostelChangeBloc extends Bloc<HostelChangeEvent, HostelChangeState> {
HostelChangePressed event, Emitter<HostelChangeState> emit) async {
emit(Loading());
String hostel = event.hostel;
String roomNo = event.roomNo;
if (hostel == "") {
emit(const HostelChangeInitial(error: "Please select a hostel"));
return;
}
if (roomNo == "") {
emit(const HostelChangeInitial(error: "Please enter a room number"));
if (hostel != "") emit(HostelQueryChanged(query: hostel));
return;
}
try {
await repo.postChangeHostel(hostel);
await repo.postChangeHostel(hostel, roomNo);
emit(HostelChangeSuccess());
} catch (e) {
emit(const HostelChangeInitial(error: AppConstants.GENERIC_FAILURE));
Expand Down
2 changes: 2 additions & 0 deletions lib/presentation/hostel_change/bloc/hostel_change_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ abstract class HostelChangeEvent {}

class HostelChangePressed extends HostelChangeEvent {
final String hostel;
final String roomNo;
HostelChangePressed({
required this.hostel,
required this.roomNo,
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:appetizer/app_theme.dart';
import 'package:appetizer/data/core/router/intrinsic_router/intrinsic_router.gr.dart';
import 'package:appetizer/data/core/theme/dimensional/dimensional.dart';
import 'package:appetizer/presentation/components/app_banner.dart';
import 'package:auto_route/auto_route.dart';
Expand All @@ -15,7 +14,7 @@ class HostelChangeBanner extends StatelessWidget {
child: Row(
children: [
IconButton(
onPressed: () => context.router.replace(const ProfileRoute()),
onPressed: () => context.router.pop(),
icon: const Icon(
Icons.arrow_back,
color: Colors.white,
Expand Down
Loading

0 comments on commit e3de526

Please sign in to comment.