claude refactorings, flutter best practices, platform dependent changes, general cleanup
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import '../../webuntis_api.dart';
|
||||
import 'get_rooms_response.dart';
|
||||
|
||||
class GetRooms extends WebuntisApi {
|
||||
GetRooms() : super('getRooms', null);
|
||||
|
||||
@override
|
||||
Future<GetRoomsResponse> run() async {
|
||||
final rawAnswer = await query(this);
|
||||
try {
|
||||
return finalize(GetRoomsResponse.fromJson(jsonDecode(rawAnswer) as Map<String, dynamic>));
|
||||
} catch (e, trace) {
|
||||
log(trace.toString());
|
||||
log('Failed to parse getRoom data with server response: $rawAnswer');
|
||||
}
|
||||
|
||||
throw Exception('Failed to parse getRoom server response: $rawAnswer');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import '../../../request_cache.dart';
|
||||
import 'get_rooms.dart';
|
||||
import 'get_rooms_response.dart';
|
||||
|
||||
class GetRoomsCache extends SimpleCache<GetRoomsResponse> {
|
||||
GetRoomsCache({super.onUpdate, super.onError, super.renew})
|
||||
: super(
|
||||
cacheTime: RequestCache.cacheHour,
|
||||
loader: () => GetRooms().run(),
|
||||
fromJson: GetRoomsResponse.fromJson,
|
||||
) {
|
||||
start('wu-rooms');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import '../../../api_response.dart';
|
||||
|
||||
part 'get_rooms_response.g.dart';
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class GetRoomsResponse extends ApiResponse {
|
||||
Set<GetRoomsResponseObject> result;
|
||||
|
||||
GetRoomsResponse(this.result);
|
||||
|
||||
factory GetRoomsResponse.fromJson(Map<String, dynamic> json) => _$GetRoomsResponseFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetRoomsResponseToJson(this);
|
||||
}
|
||||
|
||||
@JsonSerializable(explicitToJson: true)
|
||||
class GetRoomsResponseObject {
|
||||
int id;
|
||||
String name;
|
||||
String longName;
|
||||
bool active;
|
||||
String building;
|
||||
|
||||
GetRoomsResponseObject(this.id, this.name, this.longName, this.active, this.building);
|
||||
|
||||
factory GetRoomsResponseObject.fromJson(Map<String, dynamic> json) => _$GetRoomsResponseObjectFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetRoomsResponseObjectToJson(this);
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'get_rooms_response.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
GetRoomsResponse _$GetRoomsResponseFromJson(Map<String, dynamic> json) =>
|
||||
GetRoomsResponse(
|
||||
(json['result'] as List<dynamic>)
|
||||
.map(
|
||||
(e) => GetRoomsResponseObject.fromJson(e as Map<String, dynamic>),
|
||||
)
|
||||
.toSet(),
|
||||
)
|
||||
..headers = (json['headers'] as Map<String, dynamic>?)?.map(
|
||||
(k, e) => MapEntry(k, e as String),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$GetRoomsResponseToJson(GetRoomsResponse instance) =>
|
||||
<String, dynamic>{
|
||||
'headers': ?instance.headers,
|
||||
'result': instance.result.map((e) => e.toJson()).toList(),
|
||||
};
|
||||
|
||||
GetRoomsResponseObject _$GetRoomsResponseObjectFromJson(
|
||||
Map<String, dynamic> json,
|
||||
) => GetRoomsResponseObject(
|
||||
(json['id'] as num).toInt(),
|
||||
json['name'] as String,
|
||||
json['longName'] as String,
|
||||
json['active'] as bool,
|
||||
json['building'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$GetRoomsResponseObjectToJson(
|
||||
GetRoomsResponseObject instance,
|
||||
) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'name': instance.name,
|
||||
'longName': instance.longName,
|
||||
'active': instance.active,
|
||||
'building': instance.building,
|
||||
};
|
||||
Reference in New Issue
Block a user