Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adds Hostel Change UI and API #270

Merged
merged 16 commits into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,4 +16,5 @@ class AppPathsRegistry {
static const String weekMenu = 'weekMenu';
static const String leavesAndRebate = 'leavesAndRebate';
static const String feedback = 'feedback';
static const String hostelChange = 'hostelChange';
}
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 @@ -55,6 +55,10 @@ class AppRoutesRegistry {
path: AppPathsRegistry.feedback,
page: FeedbackRoute.page,
),
CustomRoute(
path: AppPathsRegistry.hostelChange,
page: HostelChangeRoute.page,
),
],
),
];
Expand Down
11 changes: 11 additions & 0 deletions lib/data/services/remote/api_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,15 @@ abstract class ApiService {

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

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

@GET(ApiEndpoints.hostelChange)
Future getHostelChangeStatus();

@DELETE(ApiEndpoints.hostelChange)
Future deleteChangeHostel();
}
30 changes: 30 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,34 @@ class UserRepository {
throw Failure(AppConstants.GENERIC_FAILURE);
}
}

Future<void> postChangeHostel(String hostelCode) async {
Map<String, dynamic> map = {
'new_hostel_code': hostelCode,
};
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);
}
}
}
40 changes: 40 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,40 @@
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;
try {
await repo.postChangeHostel(hostel);
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());
}
}
17 changes: 17 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,17 @@
part of 'hostel_change_bloc.dart';

abstract class HostelChangeEvent {}

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

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,32 @@
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';
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.replace(const ProfileRoute()),
icon: const Icon(
Icons.arrow_back,
color: Colors.white,
),
),
Text(
"Hostel Change",
style: AppTheme.headline1,
),
],
),
);
}
}
Loading