claude refactorings, flutter best practices, platform dependent changes, general cleanup
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import '../../mhsl_api.dart';
|
||||
import 'get_custom_timetable_event_params.dart';
|
||||
import 'get_custom_timetable_event_response.dart';
|
||||
|
||||
class GetCustomTimetableEvent extends MhslApi<GetCustomTimetableEventResponse> {
|
||||
GetCustomTimetableEventParams params;
|
||||
GetCustomTimetableEvent(this.params) : super('server/timetable/customEvents?user=${params.user}');
|
||||
|
||||
@override
|
||||
GetCustomTimetableEventResponse assemble(String raw) => GetCustomTimetableEventResponse.fromJson({'events': jsonDecode(raw)});
|
||||
|
||||
@override
|
||||
Future<Response>? request(Uri uri) => http.get(uri);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import '../../../request_cache.dart';
|
||||
import 'get_custom_timetable_event.dart';
|
||||
import 'get_custom_timetable_event_params.dart';
|
||||
import 'get_custom_timetable_event_response.dart';
|
||||
|
||||
class GetCustomTimetableEventCache extends SimpleCache<GetCustomTimetableEventResponse> {
|
||||
GetCustomTimetableEventCache(
|
||||
GetCustomTimetableEventParams params, {
|
||||
super.onUpdate,
|
||||
super.onError,
|
||||
super.renew,
|
||||
}) : super(
|
||||
cacheTime: RequestCache.cacheMinute,
|
||||
loader: () => GetCustomTimetableEvent(params).run(),
|
||||
fromJson: GetCustomTimetableEventResponse.fromJson,
|
||||
) {
|
||||
start('customTimetableEvents');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'get_custom_timetable_event_params.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class GetCustomTimetableEventParams {
|
||||
String user;
|
||||
|
||||
GetCustomTimetableEventParams(this.user);
|
||||
|
||||
factory GetCustomTimetableEventParams.fromJson(Map<String, dynamic> json) => _$GetCustomTimetableEventParamsFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetCustomTimetableEventParamsToJson(this);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'get_custom_timetable_event_params.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
GetCustomTimetableEventParams _$GetCustomTimetableEventParamsFromJson(
|
||||
Map<String, dynamic> json,
|
||||
) => GetCustomTimetableEventParams(json['user'] as String);
|
||||
|
||||
Map<String, dynamic> _$GetCustomTimetableEventParamsToJson(
|
||||
GetCustomTimetableEventParams instance,
|
||||
) => <String, dynamic>{'user': instance.user};
|
||||
@@ -0,0 +1,16 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import '../../../api_response.dart';
|
||||
import '../custom_timetable_event.dart';
|
||||
|
||||
part 'get_custom_timetable_event_response.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class GetCustomTimetableEventResponse extends ApiResponse {
|
||||
List<CustomTimetableEvent> events;
|
||||
|
||||
GetCustomTimetableEventResponse(this.events);
|
||||
|
||||
factory GetCustomTimetableEventResponse.fromJson(Map<String, dynamic> json) => _$GetCustomTimetableEventResponseFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$GetCustomTimetableEventResponseToJson(this);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'get_custom_timetable_event_response.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
GetCustomTimetableEventResponse _$GetCustomTimetableEventResponseFromJson(
|
||||
Map<String, dynamic> json,
|
||||
) =>
|
||||
GetCustomTimetableEventResponse(
|
||||
(json['events'] as List<dynamic>)
|
||||
.map(
|
||||
(e) => CustomTimetableEvent.fromJson(e as Map<String, dynamic>),
|
||||
)
|
||||
.toList(),
|
||||
)
|
||||
..headers = (json['headers'] as Map<String, dynamic>?)?.map(
|
||||
(k, e) => MapEntry(k, e as String),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$GetCustomTimetableEventResponseToJson(
|
||||
GetCustomTimetableEventResponse instance,
|
||||
) => <String, dynamic>{'headers': ?instance.headers, 'events': instance.events};
|
||||
Reference in New Issue
Block a user