Browse Source

Replace double quoted strings to single quoted

master
Jonas Franz 2 years ago
parent
commit
64ab40762a
Signed by: JonasFranzDEV
GPG Key ID: 7293A220B7C38080
  1. 1
      analysis_options.yaml
  2. 22
      lib/src/models/connection.dart
  3. 6
      lib/src/models/connection_type.dart
  4. 2
      lib/src/models/connection_type_converter.dart
  5. 38
      lib/src/models/construction_report.dart
  6. 26
      lib/src/models/region.dart
  7. 2
      lib/src/models/region_converter.dart
  8. 4
      lib/src/services/connection_service.dart
  9. 3
      pubspec.yaml
  10. 20
      test/connection_test.dart
  11. 10
      test/construction_report_test.dart
  12. 2
      test/db_construction_site_test.dart

1
analysis_options.yaml

@ -0,0 +1 @@ @@ -0,0 +1 @@
include: package:pedantic/analysis_options.yaml

22
lib/src/models/connection.dart

@ -10,30 +10,30 @@ part 'connection.g.dart'; @@ -10,30 +10,30 @@ part 'connection.g.dart';
class Connection {
final String id;
final String name;
@JsonKey(name: "von")
@JsonKey(name: 'von')
final String origin;
@JsonKey(name: "nach")
@JsonKey(name: 'nach')
final String destination;
@JsonKey(name: "kbnr")
@JsonKey(name: 'kbnr')
final String courseBookNumber;
@JsonKey(name: "verlauf")
@JsonKey(name: 'verlauf')
final List<String> stops;
@JsonKey(name: "via")
@JsonKey(name: 'via')
final String via;
final DateTime timestamp;
@JsonKey(name: "verfall")
@JsonKey(name: 'verfall')
final DateTime expiryDate;
@JsonKey(name: "verbindung")
@JsonKey(name: 'verbindung')
final ConnectionType type;
@JsonKey(name: "land")
@JsonKey(name: 'land')
final Region region;
final String url;
@JsonKey(name: "ics")
@JsonKey(name: 'ics')
final String icsUrl;
@JsonKey(name: "doc")
@JsonKey(name: 'doc')
final String documentUrl;
@JsonKey(name: "meldungen")
@JsonKey(name: 'meldungen')
final List<ConstructionReport> reports;
const Connection({

6
lib/src/models/connection_type.dart

@ -1,10 +1,10 @@ @@ -1,10 +1,10 @@
import 'package:json_annotation/json_annotation.dart';
enum ConnectionType {
@JsonValue("fern")
@JsonValue('fern')
longDistance,
@JsonValue("regional")
@JsonValue('regional')
regional,
@JsonValue("sbahn")
@JsonValue('sbahn')
sBahn,
}

2
lib/src/models/connection_type_converter.dart

@ -11,5 +11,5 @@ class ConnectionTypeConverter { @@ -11,5 +11,5 @@ class ConnectionTypeConverter {
const ConnectionTypeConverter(this.type);
@JsonKey(ignore: true)
String get value => _$ConnectionTypeConverterToJson(this)["type"];
String get value => _$ConnectionTypeConverterToJson(this)['type'];
}

38
lib/src/models/construction_report.dart

@ -5,46 +5,46 @@ part 'construction_report.g.dart'; @@ -5,46 +5,46 @@ part 'construction_report.g.dart';
@JsonSerializable(createToJson: false)
class ConstructionReport {
final String id;
@JsonKey(name: "nr", fromJson: int.parse)
@JsonKey(name: 'nr', fromJson: int.parse)
final int index;
@JsonKey(name: "termin", fromJson: _parseListOrString)
@JsonKey(name: 'termin', fromJson: _parseListOrString)
final List<String> timePeriodTexts;
@JsonKey(name: "termin_pins", fromJson: _parseListOrString)
@JsonKey(name: 'termin_pins', fromJson: _parseListOrString)
final List<String> timePeriodPinsTexts;
@JsonKey(name: "termin_zeit", fromJson: _parseListOrString)
@JsonKey(name: 'termin_zeit', fromJson: _parseListOrString)
final List<String> timePeriodTimeTexts;
final String headline;
final String headlinePins;
@JsonKey(name: "meldung", fromJson: _parseListOrString)
@JsonKey(name: 'meldung', fromJson: _parseListOrString)
final List<String> messages;
@JsonKey(name: "meldung_pins", fromJson: _parseListOrString)
@JsonKey(name: 'meldung_pins', fromJson: _parseListOrString)
final List<String> messagesPins;
@JsonKey(name: "meldung_hinweis", fromJson: _parseListOrString)
@JsonKey(name: 'meldung_hinweis', fromJson: _parseListOrString)
final List<String> messagesHint;
@JsonKey(name: "hinweis_tabelle", fromJson: _parseListOrString)
@JsonKey(name: 'hinweis_tabelle', fromJson: _parseListOrString)
final List<String> hintTable;
@JsonKey(name: "grund")
@JsonKey(name: 'grund')
final String reason;
@JsonKey(name: "abschnitt")
@JsonKey(name: 'abschnitt')
final List<String> affectedStations;
final DateTime lastChange;
@JsonKey(name: "ics")
@JsonKey(name: 'ics')
final String icsUrl;
@JsonKey(name: "termine", fromJson: _parseTimeRanges)
@JsonKey(name: 'termine', fromJson: _parseTimeRanges)
final List<TimeRange> timeRanges;
@JsonKey(name: "von")
@JsonKey(name: 'von')
final DateTime startDate;
@JsonKey(name: "bis")
@JsonKey(name: 'bis')
final DateTime endDate;
ConstructionReport(
@ -97,11 +97,11 @@ class TimeRange { @@ -97,11 +97,11 @@ class TimeRange {
const TimeRange({this.begin, this.end, this.allDay, this.weekdays});
TimeRange._fromJson(Map<String, dynamic> json)
: begin = _parseTimeStamp(json, "von"),
end = _parseTimeStamp(json, "bis"),
allDay = json["ganztaegig"] == "1",
weekdays = json["wochentage"] is List
? (json["wochentage"] as List<dynamic>)
: begin = _parseTimeStamp(json, 'von'),
end = _parseTimeStamp(json, 'bis'),
allDay = json['ganztaegig'] == '1',
weekdays = json['wochentage'] is List
? (json['wochentage'] as List<dynamic>)
.map((day) => int.parse(day))
.toList()
: null;

26
lib/src/models/region.dart

@ -2,54 +2,54 @@ import 'package:json_annotation/json_annotation.dart'; @@ -2,54 +2,54 @@ import 'package:json_annotation/json_annotation.dart';
enum Region {
/// Lower Saxony and Bremen
@JsonValue("niedersachen-bremen")
@JsonValue('niedersachen-bremen')
lowerSaxonyBremen,
/// Schleswig Holstein
@JsonValue("norden")
@JsonValue('norden')
north,
/// Mecklenburg Western Pomerania
@JsonValue("mvp")
@JsonValue('mvp')
mecklenburgWesternPomerania,
/// Berlin and Brandenburg
@JsonValue("berlin-bb")
@JsonValue('berlin-bb')
berlinBrandenburg,
/// Saxony-Anhalt
@JsonValue("sachsen-anhalt")
@JsonValue('sachsen-anhalt')
saxonyAnhalt,
/// Saxony
@JsonValue("sachsen")
@JsonValue('sachsen')
saxony,
/// Bavaria
@JsonValue("bayern")
@JsonValue('bayern')
bavaria,
/// Thuringia
@JsonValue("thueringen")
@JsonValue('thueringen')
thuringia,
/// Baden-Württemberg
@JsonValue("baden-w")
@JsonValue('baden-w')
badenWuerttemberg,
/// Rhineland Palatinate
@JsonValue("rheinland-pfalz")
@JsonValue('rheinland-pfalz')
rhinelandPalatinate,
/// Hesse
@JsonValue("hessen")
@JsonValue('hessen')
hesse,
/// Northrhine-Westphalia
@JsonValue("nrw")
@JsonValue('nrw')
northrhineWestphalia,
/// Long distance trains with multiple regions
@JsonValue("fernverkehr")
@JsonValue('fernverkehr')
longDistance,
}

2
lib/src/models/region_converter.dart

@ -11,5 +11,5 @@ class RegionConverter { @@ -11,5 +11,5 @@ class RegionConverter {
const RegionConverter(this.region);
@JsonKey(ignore: true)
String get value => _$RegionConverterToJson(this)["region"];
String get value => _$RegionConverterToJson(this)['region'];
}

4
lib/src/services/connection_service.dart

@ -1,5 +1,4 @@ @@ -1,5 +1,4 @@
import 'dart:convert';
import 'dart:io';
import 'package:db_construction_site/src/models/connection.dart';
import 'package:db_construction_site/src/models/connection_type.dart';
@ -23,8 +22,7 @@ class ConnectionService { @@ -23,8 +22,7 @@ class ConnectionService {
}
final result = await http.get(url);
if (result.statusCode ~/ 100 != 2) {
throw HttpException("unexpected status code ${result.statusCode}",
uri: result.request.url);
throw Exception('unexpected status code ${result.statusCode}');
}
final List<dynamic> connections = JsonDecoder().convert(result.body);
return connections

3
pubspec.yaml

@ -16,6 +16,3 @@ dev_dependencies: @@ -16,6 +16,3 @@ dev_dependencies:
build_runner: ^1.10.1
json_serializable: ^3.3.0
pedantic: ^1.9.2
# enable linting rules
include: package:pedantic/analysis_options.yaml

20
test/connection_test.dart

@ -6,7 +6,7 @@ import 'package:test/test.dart'; @@ -6,7 +6,7 @@ import 'package:test/test.dart';
void main() {
test('test if json parsing works as expected', () {
const exampleConnectionJsonString = """
const exampleConnectionJsonString = '''
{
"id": "3",
"name": "RE 17",
@ -33,23 +33,23 @@ void main() { @@ -33,23 +33,23 @@ void main() {
"meldungen": [],
"infos": []
}
""";
''';
Map<String, dynamic> json;
try {
json = JsonDecoder().convert(exampleConnectionJsonString);
assert(json != null);
} catch (e) {
print("JSON decoding failed, skipping test.");
print('JSON decoding failed, skipping test.');
return;
}
final connection = Connection.fromJson(json);
expect(connection.id, "3");
expect(connection.name, "RE 17");
expect(connection.courseBookNumber, "430");
expect(connection.origin, "Warburg");
expect(connection.stops, contains("Hagen Hbf"));
expect(connection.destination, "Kassel");
expect(connection.via, "");
expect(connection.id, '3');
expect(connection.name, 'RE 17');
expect(connection.courseBookNumber, '430');
expect(connection.origin, 'Warburg');
expect(connection.stops, contains('Hagen Hbf'));
expect(connection.destination, 'Kassel');
expect(connection.via, '');
expect(connection.timestamp, DateTime(2018, 11, 16, 05, 15, 43));
expect(connection.expiryDate, DateTime(2018, 12, 02, 23, 15, 00));
expect(connection.type, ConnectionType.regional);

10
test/construction_report_test.dart

@ -5,7 +5,7 @@ import 'package:test/test.dart'; @@ -5,7 +5,7 @@ import 'package:test/test.dart';
void main() {
test('test if json parsing works as expected', () {
const exampleReportJsonString = """
const exampleReportJsonString = '''
{
"id": "5604",
"nr": "1",
@ -65,20 +65,20 @@ void main() { @@ -65,20 +65,20 @@ void main() {
}
]
}
""";
''';
Map<String, dynamic> json;
try {
json = JsonDecoder().convert(exampleReportJsonString);
assert(json != null);
} catch (e) {
print("JSON decoding failed, skipping test.");
print('JSON decoding failed, skipping test.');
return;
}
final connection = ConstructionReport.fromJson(json);
expect(connection.id, "5604");
expect(connection.id, '5604');
expect(connection.index, 1);
expect(connection.messages, [
"Die Züge der Linien RE 4 und RE 14 enden/beginnen in Frankfurt-Höchst und fallen zwischen Frankfurt-Höchst und Frankfurt (Main) Hbf aus. Als Ersatz nutzen Sie bitte die noch verkehrenden Züge in diesem Abschnitt."
'Die Züge der Linien RE 4 und RE 14 enden/beginnen in Frankfurt-Höchst und fallen zwischen Frankfurt-Höchst und Frankfurt (Main) Hbf aus. Als Ersatz nutzen Sie bitte die noch verkehrenden Züge in diesem Abschnitt.'
]);
expect(connection.timeRanges.length, 1);
expect(connection.timeRanges[0].begin, connection.startDate);

2
test/db_construction_site_test.dart

@ -14,7 +14,7 @@ void main() { @@ -14,7 +14,7 @@ void main() {
await DBConstructionSite(baseUrl: 'https://noanurl.local')
.connections
.findConnections(Region.hesse);
fail("Request succeeds although it should fail");
fail('Request succeeds although it should fail');
} catch (e) {
// success
}

Loading…
Cancel
Save