Skip to content

Commit

Permalink
Merge pull request #270 from mdgspace/casper/hostel_change
Browse files Browse the repository at this point in the history
feat: Adds Hostel Change UI and API
  • Loading branch information
A-Kashif108 authored Apr 13, 2024
2 parents e57147a + 83bbc57 commit ec045c3
Show file tree
Hide file tree
Showing 16 changed files with 690 additions and 30 deletions.
1 change: 1 addition & 0 deletions lib/data/constants/api_endpoints.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ class ApiEndpoints {
static const String oAuthRedirect = '/api/user/oauth/omniport/redirect/';
static const String oAuthComplete = '/api/user/oauth/complete/';
static const String notifications = '/api/user/message/list/';
static const String hostelChange = '/api/user/hostel-change/';
}
1 change: 1 addition & 0 deletions lib/data/core/router/registry/paths.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class AppPathsRegistry {
static const String weekMenu = 'weekMenu';
static const String leavesAndRebate = 'leavesAndRebate';
static const String feedback = 'feedback';
static const String hostelChange = 'hostelChange';
static const String resetPassword = 'resetPassword';

static const String noInternetWrapper = '/noInternetWrapper';
Expand Down
4 changes: 4 additions & 0 deletions lib/data/core/router/registry/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ class AppRoutesRegistry {
path: AppPathsRegistry.resetPassword,
page: ResetPasswordRoute.page,
),
CustomRoute(
path: AppPathsRegistry.hostelChange,
page: HostelChangeRoute.page,
),
],
),
CustomRoute(
Expand Down
12 changes: 12 additions & 0 deletions lib/data/services/remote/api_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:appetizer/domain/models/appetizer_version.dart';
import 'package:appetizer/domain/models/coupon/coupon.dart';
import 'package:appetizer/domain/models/feedback/appetizer_feedback.dart';
import 'package:appetizer/domain/models/feedback/feedback_response.dart';
import 'package:appetizer/domain/models/hostel_change_request/hostel_change_request.dart';
import 'package:appetizer/domain/models/leaves/paginated_leaves.dart';
import 'package:appetizer/domain/models/menu/week_menu_tmp.dart';
import 'package:appetizer/domain/models/transaction/faq.dart';
Expand Down Expand Up @@ -181,4 +182,15 @@ abstract class ApiService {

@GET(ApiEndpoints.notifications)
Future getNotifications();

@POST(ApiEndpoints.hostelChange)
Future<void> postChangeHostel(
@Body() Map<String, dynamic> map,
);

@GET(ApiEndpoints.hostelChange)
Future<HostelChangeRequest> getHostelChangeStatus();

@DELETE(ApiEndpoints.hostelChange)
Future deleteChangeHostel();
}
20 changes: 20 additions & 0 deletions lib/domain/models/hostel_change_request/hostel_change_request.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:freezed_annotation/freezed_annotation.dart';

part 'hostel_change_request.freezed.dart';
part 'hostel_change_request.g.dart';

@freezed
class HostelChangeRequest with _$HostelChangeRequest {
@JsonSerializable(fieldRename: FieldRename.snake)
const factory HostelChangeRequest(
{required int user,
required int id,
required String hostelCode,
required String newRoomNo,
bool? isApprovedByAdmin,
required String timestamp,
required int newHostel}) = _HostelChangeRequest;

factory HostelChangeRequest.fromJson(Map<String, dynamic> json) =>
_$HostelChangeRequestFromJson(json);
}
31 changes: 31 additions & 0 deletions lib/domain/repositories/user/user_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,35 @@ class UserRepository {
throw Failure(AppConstants.GENERIC_FAILURE);
}
}

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);
} catch (e) {
debugPrint(e.toString());
throw Failure(AppConstants.GENERIC_FAILURE);
}
}

Future<dynamic> getHostelChangeStatus() async {
try {
return await _apiService.getHostelChangeStatus();
} catch (e) {
debugPrint(e.toString());
throw Failure(AppConstants.GENERIC_FAILURE);
}
}

Future<dynamic> deleteChangeHostel() async {
try {
return await _apiService.deleteChangeHostel();
} catch (e) {
debugPrint(e.toString());
throw Failure(AppConstants.GENERIC_FAILURE);
}
}
}
50 changes: 50 additions & 0 deletions lib/presentation/hostel_change/bloc/hostel_change_bloc.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import 'dart:async';

import 'package:appetizer/data/constants/constants.dart';
import 'package:appetizer/domain/repositories/user/user_repository.dart';
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';

part 'hostel_change_event.dart';
part 'hostel_change_state.dart';

class HostelChangeBloc extends Bloc<HostelChangeEvent, HostelChangeState> {
final UserRepository repo;
HostelChangeBloc({required this.repo}) : super(const HostelChangeInitial()) {
on<HostelChangePressed>(_onHostelChangePressed);
on<HostelSearchQueryChanged>(_onHostelSearchQueryChanged);
}

FutureOr<void> _onHostelChangePressed(
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, roomNo);
emit(HostelChangeSuccess());
} catch (e) {
emit(const HostelChangeInitial(error: AppConstants.GENERIC_FAILURE));
}
}

FutureOr<void> _onHostelSearchQueryChanged(
HostelSearchQueryChanged event, Emitter<HostelChangeState> emit) async {
if (event.query == "") {
emit(const HostelChangeInitial());
} else {
emit(Loading());
emit(HostelQueryChanged(query: event.query));
}
// emit(const HostelChangeInitial());
}
}
19 changes: 19 additions & 0 deletions lib/presentation/hostel_change/bloc/hostel_change_event.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
part of 'hostel_change_bloc.dart';

abstract class HostelChangeEvent {}

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

class HostelSearchQueryChanged extends HostelChangeEvent {
final String query;
HostelSearchQueryChanged({
required this.query,
});
}
22 changes: 22 additions & 0 deletions lib/presentation/hostel_change/bloc/hostel_change_state.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
part of 'hostel_change_bloc.dart';

abstract class HostelChangeState extends Equatable {
const HostelChangeState();

@override
List<Object?> get props => [];
}

class HostelChangeInitial extends HostelChangeState {
final String? error;
const HostelChangeInitial({this.error});
}

class Loading extends HostelChangeState {}

class HostelChangeSuccess extends HostelChangeState {}

class HostelQueryChanged extends HostelChangeState {
final String query;
const HostelQueryChanged({required this.query});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import 'package:appetizer/app_theme.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';
import 'package:flutter/material.dart';

class HostelChangeBanner extends StatelessWidget {
const HostelChangeBanner({super.key});

@override
Widget build(BuildContext context) {
return AppBanner(
height: 140.toAutoScaledHeight,
child: Row(
children: [
IconButton(
onPressed: () => context.router.pop(),
icon: const Icon(
Icons.arrow_back,
color: Colors.white,
),
),
Text(
"Hostel Change",
style: AppTheme.headline1,
),
],
),
);
}
}
Loading

0 comments on commit ec045c3

Please sign in to comment.