mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-11-27 21:34:55 +00:00
updated models
This commit is contained in:
67
lib/pages/spaces_management/model/space_response_model.dart
Normal file
67
lib/pages/spaces_management/model/space_response_model.dart
Normal file
@ -0,0 +1,67 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'space_model.dart';
|
||||
|
||||
class SpacesResponse {
|
||||
final List<SpaceModel> data;
|
||||
final String message;
|
||||
final int page;
|
||||
final int size;
|
||||
final int totalItem;
|
||||
final int totalPage;
|
||||
final bool hasNext;
|
||||
final bool hasPrevious;
|
||||
|
||||
SpacesResponse({
|
||||
required this.data,
|
||||
required this.message,
|
||||
required this.page,
|
||||
required this.size,
|
||||
required this.totalItem,
|
||||
required this.totalPage,
|
||||
required this.hasNext,
|
||||
required this.hasPrevious,
|
||||
});
|
||||
|
||||
factory SpacesResponse.fromJson(Map<String, dynamic> json) {
|
||||
return SpacesResponse(
|
||||
data: (json['data'] as List)
|
||||
.map((jsonItem) => SpaceModel.fromJson(jsonItem))
|
||||
.toList(),
|
||||
message: json['message'],
|
||||
page: json['page'],
|
||||
size: json['size'],
|
||||
totalItem: json['totalItem'],
|
||||
totalPage: json['totalPage'],
|
||||
hasNext: json['hasNext'],
|
||||
hasPrevious: json['hasPrevious'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class CommunitySpaceManagementApi {
|
||||
Future<SpacesResponse> fetchSpaces(String communityId) async {
|
||||
try {
|
||||
final response = await HTTPService().get(
|
||||
path: ApiEndpoints.listSpaces.replaceAll('{communityId}', communityId),
|
||||
showServerMessage: true,
|
||||
expectedResponseModel: (json) {
|
||||
return SpacesResponse.fromJson(json);
|
||||
},
|
||||
);
|
||||
return response;
|
||||
} catch (e) {
|
||||
debugPrint('Error fetching spaces: $e');
|
||||
return SpacesResponse(
|
||||
data: [],
|
||||
message: 'Error fetching spaces',
|
||||
page: 1,
|
||||
size: 10,
|
||||
totalItem: 0,
|
||||
totalPage: 0,
|
||||
hasNext: false,
|
||||
hasPrevious: false,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user