Skip to content

Commit babab58

Browse files
committed
chore : creates HostelChangeRequest model
1 parent 1bd2df5 commit babab58

4 files changed

Lines changed: 53 additions & 16 deletions

File tree

lib/data/services/remote/api_service.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'package:appetizer/domain/models/appetizer_version.dart';
33
import 'package:appetizer/domain/models/coupon/coupon.dart';
44
import 'package:appetizer/domain/models/feedback/appetizer_feedback.dart';
55
import 'package:appetizer/domain/models/feedback/feedback_response.dart';
6+
import 'package:appetizer/domain/models/hostel_change_request/hostel_change_request.dart';
67
import 'package:appetizer/domain/models/leaves/paginated_leaves.dart';
78
import 'package:appetizer/domain/models/menu/week_menu_tmp.dart';
89
import 'package:appetizer/domain/models/transaction/faq.dart';
@@ -188,7 +189,7 @@ abstract class ApiService {
188189
);
189190

190191
@GET(ApiEndpoints.hostelChange)
191-
Future getHostelChangeStatus();
192+
Future<HostelChangeRequest> getHostelChangeStatus();
192193

193194
@DELETE(ApiEndpoints.hostelChange)
194195
Future deleteChangeHostel();
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import 'package:freezed_annotation/freezed_annotation.dart';
2+
3+
part 'hostel_change_request.freezed.dart';
4+
part 'hostel_change_request.g.dart';
5+
6+
@freezed
7+
class HostelChangeRequest with _$HostelChangeRequest {
8+
@JsonSerializable(fieldRename: FieldRename.snake)
9+
const factory HostelChangeRequest(
10+
{required int user,
11+
required int id,
12+
required String hostelCode,
13+
required String newRoomNo,
14+
bool? isApproved,
15+
required String timestamp,
16+
required int newHostel}) = _HostelChangeRequest;
17+
18+
factory HostelChangeRequest.fromJson(Map<String, dynamic> json) =>
19+
_$HostelChangeRequestFromJson(json);
20+
}

lib/presentation/profile/bloc/profile_page_bloc.dart

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'dart:async';
22

3+
import 'package:appetizer/domain/models/hostel_change_request/hostel_change_request.dart';
34
import 'package:appetizer/domain/models/user/user.dart';
45
import 'package:appetizer/domain/repositories/user/user_repository.dart';
56
import 'package:bloc/bloc.dart';
@@ -20,15 +21,27 @@ class ProfilePageBloc extends Bloc<ProfilePageEvent, ProfilePageState> {
2021
// TODO: implement event handler
2122
User user = await repo.getCurrentUser();
2223
try {
23-
dynamic hostelChangeStatus = await repo.getHostelChangeStatus();
24+
HostelChangeRequest hostelChangeStatus =
25+
await repo.getHostelChangeStatus();
2426
emit(
2527
ProfilePageFetchedState(
26-
user: user, hostelChangeStatus: hostelChangeStatus),
28+
user: user,
29+
hostelChangeStatus: hostelChangeStatus,
30+
),
2731
);
2832
} catch (e) {
2933
emit(
3034
ProfilePageFetchedState(
31-
user: user, hostelChangeStatus: const {'detail': 'No Request'}),
35+
user: user,
36+
hostelChangeStatus: const HostelChangeRequest(
37+
user: 0,
38+
id: 0,
39+
hostelCode: "",
40+
newRoomNo: "",
41+
timestamp: "",
42+
newHostel: 0,
43+
isApproved: null),
44+
),
3245
);
3346
}
3447
}
@@ -37,10 +50,19 @@ class ProfilePageBloc extends Bloc<ProfilePageEvent, ProfilePageState> {
3750
DeleteHostelChangeRequest event, Emitter<ProfilePageState> emit) async {
3851
emit(const ProfilePageInitialState());
3952
User user = await repo.getCurrentUser();
40-
dynamic hostelChangeStatus = await repo.deleteChangeHostel();
53+
await repo.deleteChangeHostel();
4154
emit(
4255
ProfilePageFetchedState(
43-
user: user, hostelChangeStatus: hostelChangeStatus),
56+
user: user,
57+
hostelChangeStatus: const HostelChangeRequest(
58+
user: 0,
59+
id: 0,
60+
hostelCode: "",
61+
newRoomNo: "",
62+
timestamp: "",
63+
newHostel: 0,
64+
isApproved: null),
65+
),
4466
);
4567
}
4668
}

lib/presentation/profile/profile_view.dart

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,7 @@ class ProfileScreen extends StatelessWidget {
9595
],
9696
),
9797
10.toVerticalSizedBox,
98-
if (state.hostelChangeStatus['detail'] !=
99-
null ||
100-
(state.hostelChangeStatus['is_approved'] !=
101-
null &&
102-
state
103-
.hostelChangeStatus['is_approved']))
98+
if (state.hostelChangeStatus.isApproved == null)
10499
ProfileTextButton(
105100
title: 'Request for Hostel Change',
106101
onPressed: () {
@@ -109,7 +104,7 @@ class ProfileScreen extends StatelessWidget {
109104
horizontalPadding: 50,
110105
width: 248,
111106
),
112-
if (state.hostelChangeStatus['detail'] == null)
107+
if (state.hostelChangeStatus.isApproved != null)
113108
TextButton(
114109
onPressed: () => {
115110
showDialog(
@@ -152,7 +147,7 @@ class ProfileScreen extends StatelessWidget {
152147
Align(
153148
alignment: Alignment.centerLeft,
154149
child: Text(
155-
"Requested for hostel change to ${state.hostelChangeStatus['hostel_code']}",
150+
"Requested for hostel change to ${state.hostelChangeStatus.hostelCode}",
156151
style: TextStyle(
157152
color: const Color(0xFF111111),
158153
fontSize: 13.toAutoScaledFont,
@@ -164,7 +159,7 @@ class ProfileScreen extends StatelessWidget {
164159
Align(
165160
alignment: Alignment.centerLeft,
166161
child: Text(
167-
"New Room No: ${state.hostelChangeStatus['new_room_no']}",
162+
"New Room No: ${state.hostelChangeStatus.newRoomNo}",
168163
textAlign: TextAlign.justify,
169164
style: TextStyle(
170165
color: const Color(0xFF2F2F2F),
@@ -244,7 +239,6 @@ class ProfileScreen extends StatelessWidget {
244239
],
245240
);
246241
}
247-
248242
return SizedBox(
249243
height: 200.toAutoScaledHeight,
250244
child: const Align(

0 commit comments

Comments
 (0)