Files
syncrow-app/lib/services/api/spaces_api.dart
2024-06-05 03:42:00 +03:00

60 lines
1.9 KiB
Dart

import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:syncrow_app/features/app_layout/model/space_model.dart';
import 'package:syncrow_app/features/auth/model/user_model.dart';
import 'package:syncrow_app/features/devices/model/room_model.dart';
import 'package:syncrow_app/services/api/api_links_endpoints.dart';
import 'package:syncrow_app/services/api/http_service.dart';
class SpacesAPI {
static final HTTPService _httpService = HTTPService();
static Future<List<SpaceModel>> getUnitsByUserId() async {
var uuid = await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
final response = await _httpService.get(
path: "${ApiEndpoints.unitUser}$uuid",
showServerMessage: false,
expectedResponseModel: (json) => SpaceModel.fromJsonList(json),
);
return response;
}
static Future<List<RoomModel>> getRoomsBySpaceId(String unitId) async {
final response = await _httpService.get(
path: "${ApiEndpoints.unitChild}$unitId",
queryParameters: {"page": 1, "pageSize": 10},
showServerMessage: false,
expectedResponseModel: (json) {
List<RoomModel> rooms = [];
for (var room in json['children']) {
rooms.add(RoomModel.fromJson(room));
}
return rooms;
},
);
return response;
}
static Future<String> generateInvitationCode(
String unitId,
) async {
final response = await _httpService.get(
path: ApiEndpoints.invitationCode.replaceAll('{unitUuid}', unitId),
showServerMessage: false,
expectedResponseModel: (json) => json['invitationCode'],
);
return response;
}
static Future<bool> joinUnit(
Map<String, String> body,
) async {
final response = await _httpService.post(
path: ApiEndpoints.verifyInvitationCode,
showServerMessage: false,
body: body,
expectedResponseModel: (json) => json['success'],
);
return response;
}
}