Skip to content

Commit

Permalink
chore : creates HostelChangeRequest model
Browse files Browse the repository at this point in the history
  • Loading branch information
am-casper committed Jan 3, 2024
1 parent 1bd2df5 commit babab58
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 16 deletions.
3 changes: 2 additions & 1 deletion 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 @@ -188,7 +189,7 @@ abstract class ApiService {
);

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

@DELETE(ApiEndpoints.hostelChange)
Future deleteChangeHostel();
Expand Down
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? isApproved,
required String timestamp,
required int newHostel}) = _HostelChangeRequest;

factory HostelChangeRequest.fromJson(Map<String, dynamic> json) =>
_$HostelChangeRequestFromJson(json);
}
32 changes: 27 additions & 5 deletions lib/presentation/profile/bloc/profile_page_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';

import 'package:appetizer/domain/models/hostel_change_request/hostel_change_request.dart';
import 'package:appetizer/domain/models/user/user.dart';
import 'package:appetizer/domain/repositories/user/user_repository.dart';
import 'package:bloc/bloc.dart';
Expand All @@ -20,15 +21,27 @@ class ProfilePageBloc extends Bloc<ProfilePageEvent, ProfilePageState> {
// TODO: implement event handler
User user = await repo.getCurrentUser();
try {
dynamic hostelChangeStatus = await repo.getHostelChangeStatus();
HostelChangeRequest hostelChangeStatus =
await repo.getHostelChangeStatus();
emit(
ProfilePageFetchedState(
user: user, hostelChangeStatus: hostelChangeStatus),
user: user,
hostelChangeStatus: hostelChangeStatus,
),
);
} catch (e) {
emit(
ProfilePageFetchedState(
user: user, hostelChangeStatus: const {'detail': 'No Request'}),
user: user,
hostelChangeStatus: const HostelChangeRequest(
user: 0,
id: 0,
hostelCode: "",
newRoomNo: "",
timestamp: "",
newHostel: 0,
isApproved: null),
),
);
}
}
Expand All @@ -37,10 +50,19 @@ class ProfilePageBloc extends Bloc<ProfilePageEvent, ProfilePageState> {
DeleteHostelChangeRequest event, Emitter<ProfilePageState> emit) async {
emit(const ProfilePageInitialState());
User user = await repo.getCurrentUser();
dynamic hostelChangeStatus = await repo.deleteChangeHostel();
await repo.deleteChangeHostel();
emit(
ProfilePageFetchedState(
user: user, hostelChangeStatus: hostelChangeStatus),
user: user,
hostelChangeStatus: const HostelChangeRequest(
user: 0,
id: 0,
hostelCode: "",
newRoomNo: "",
timestamp: "",
newHostel: 0,
isApproved: null),
),
);
}
}
14 changes: 4 additions & 10 deletions lib/presentation/profile/profile_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,7 @@ class ProfileScreen extends StatelessWidget {
],
),
10.toVerticalSizedBox,
if (state.hostelChangeStatus['detail'] !=
null ||
(state.hostelChangeStatus['is_approved'] !=
null &&
state
.hostelChangeStatus['is_approved']))
if (state.hostelChangeStatus.isApproved == null)
ProfileTextButton(
title: 'Request for Hostel Change',
onPressed: () {
Expand All @@ -109,7 +104,7 @@ class ProfileScreen extends StatelessWidget {
horizontalPadding: 50,
width: 248,
),
if (state.hostelChangeStatus['detail'] == null)
if (state.hostelChangeStatus.isApproved != null)
TextButton(
onPressed: () => {
showDialog(
Expand Down Expand Up @@ -152,7 +147,7 @@ class ProfileScreen extends StatelessWidget {
Align(
alignment: Alignment.centerLeft,
child: Text(
"Requested for hostel change to ${state.hostelChangeStatus['hostel_code']}",
"Requested for hostel change to ${state.hostelChangeStatus.hostelCode}",
style: TextStyle(
color: const Color(0xFF111111),
fontSize: 13.toAutoScaledFont,
Expand All @@ -164,7 +159,7 @@ class ProfileScreen extends StatelessWidget {
Align(
alignment: Alignment.centerLeft,
child: Text(
"New Room No: ${state.hostelChangeStatus['new_room_no']}",
"New Room No: ${state.hostelChangeStatus.newRoomNo}",
textAlign: TextAlign.justify,
style: TextStyle(
color: const Color(0xFF2F2F2F),
Expand Down Expand Up @@ -244,7 +239,6 @@ class ProfileScreen extends StatelessWidget {
],
);
}

return SizedBox(
height: 200.toAutoScaledHeight,
child: const Align(
Expand Down

0 comments on commit babab58

Please sign in to comment.