diff --git a/lib/tosti/blocs/home_cubit.dart b/lib/tosti/blocs/home_cubit.dart index 032cc83be..222ab0cdd 100644 --- a/lib/tosti/blocs/home_cubit.dart +++ b/lib/tosti/blocs/home_cubit.dart @@ -29,7 +29,7 @@ class TostiHomeCubit extends Cubit { final venues = venuesResponse.results.map((final venue) { final shift = shiftsResponse.results.firstWhereOrNull( - (final shift) => shift.venue == venue.id, + (final shift) => shift.venue.venue.id == venue.id, ); return shift != null ? venue.copyWithShift(shift) : venue; diff --git a/lib/tosti/models/shift.dart b/lib/tosti/models/shift.dart index 294368fd9..f0bd503d1 100644 --- a/lib/tosti/models/shift.dart +++ b/lib/tosti/models/shift.dart @@ -1,13 +1,13 @@ import 'package:json_annotation/json_annotation.dart'; import 'package:reaxit/tosti/models/user.dart'; +import 'package:reaxit/tosti/models/venue.dart'; part 'shift.g.dart'; @JsonSerializable(fieldRename: FieldRename.snake) class TostiShift { final int id; - final int venue; - final String venueName; + final TostiOrderVenue venue; final DateTime start; final DateTime end; final bool canOrder; @@ -21,7 +21,6 @@ class TostiShift { TostiShift( this.id, this.venue, - this.venueName, this.start, this.end, this.canOrder, diff --git a/lib/tosti/models/shift.g.dart b/lib/tosti/models/shift.g.dart index 15204be84..93747288d 100644 --- a/lib/tosti/models/shift.g.dart +++ b/lib/tosti/models/shift.g.dart @@ -8,8 +8,7 @@ part of 'shift.dart'; TostiShift _$TostiShiftFromJson(Map json) => TostiShift( json['id'] as int, - json['venue'] as int, - json['venue_name'] as String, + TostiOrderVenue.fromJson(json['venue'] as Map), DateTime.parse(json['start'] as String), DateTime.parse(json['end'] as String), json['can_order'] as bool, @@ -27,7 +26,6 @@ Map _$TostiShiftToJson(TostiShift instance) => { 'id': instance.id, 'venue': instance.venue, - 'venue_name': instance.venueName, 'start': instance.start.toIso8601String(), 'end': instance.end.toIso8601String(), 'can_order': instance.canOrder, diff --git a/lib/tosti/models/venue.dart b/lib/tosti/models/venue.dart index c08f15307..1fc8d5789 100644 --- a/lib/tosti/models/venue.dart +++ b/lib/tosti/models/venue.dart @@ -37,3 +37,13 @@ class TostiVenue { TostiVenue copyWithPlayer(ThaliedjePlayer? player) => TostiVenue(id, name, slug, colorInCalendar, canBeReserved, shift, player); } + +@JsonSerializable(fieldRename: FieldRename.snake) +class TostiOrderVenue { + final TostiVenue venue; + + TostiOrderVenue(this.venue); + + factory TostiOrderVenue.fromJson(Map json) => + _$TostiOrderVenueFromJson(json); +} diff --git a/lib/tosti/models/venue.g.dart b/lib/tosti/models/venue.g.dart index 5b86b286c..0584d0a13 100644 --- a/lib/tosti/models/venue.g.dart +++ b/lib/tosti/models/venue.g.dart @@ -22,3 +22,13 @@ Map _$TostiVenueToJson(TostiVenue instance) => 'color_in_calendar': instance.colorInCalendar, 'can_be_reserved': instance.canBeReserved, }; + +TostiOrderVenue _$TostiOrderVenueFromJson(Map json) => + TostiOrderVenue( + TostiVenue.fromJson(json['venue'] as Map), + ); + +Map _$TostiOrderVenueToJson(TostiOrderVenue instance) => + { + 'venue': instance.venue, + }; diff --git a/lib/tosti/tosti_shift_screen.dart b/lib/tosti/tosti_shift_screen.dart index 870a37867..a86ab6f7b 100644 --- a/lib/tosti/tosti_shift_screen.dart +++ b/lib/tosti/tosti_shift_screen.dart @@ -57,7 +57,7 @@ class TostiShiftScreen extends StatelessWidget { children: [ const SizedBox(height: 16), Text( - shift.venueName.toUpperCase(), + shift.venue.venue.name.toUpperCase(), style: textTheme.titleLarge, ), const Divider(height: 24),