-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #270 from mdgspace/casper/hostel_change
feat: Adds Hostel Change UI and API
- Loading branch information
Showing
16 changed files
with
690 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
lib/domain/models/hostel_change_request/hostel_change_request.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
lib/presentation/hostel_change/bloc/hostel_change_bloc.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
19
lib/presentation/hostel_change/bloc/hostel_change_event.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
22
lib/presentation/hostel_change/bloc/hostel_change_state.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}); | ||
} |
31 changes: 31 additions & 0 deletions
31
lib/presentation/hostel_change/components/hostel_change_banner.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} |
Oops, something went wrong.