-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(digital-guide): add data layer for rooms section
- Loading branch information
1 parent
1badbad
commit c7ae02d
Showing
2 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
lib/features/digital_guide_view/tabs/rooms/data/models/digital_guide_room.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import "package:freezed_annotation/freezed_annotation.dart"; | ||
|
||
part "digital_guide_room.freezed.dart"; | ||
part "digital_guide_room.g.dart"; | ||
|
||
@freezed | ||
class DigitalGuideRoom with _$DigitalGuideRoom { | ||
const factory DigitalGuideRoom({ | ||
required int id, | ||
required DigitalGuideTranslationsRoom translations, | ||
@JsonKey(name: "images") required List<int>? imagesIds, | ||
}) = _DigitalGuideRoom; | ||
|
||
factory DigitalGuideRoom.fromJson(Map<String, dynamic> json) => | ||
_$DigitalGuideRoomFromJson(json); | ||
} | ||
|
||
@freezed | ||
class DigitalGuideTranslationsRoom with _$DigitalGuideTranslationsRoom { | ||
const factory DigitalGuideTranslationsRoom({ | ||
required DigitalGuideTranslationRoom pl, | ||
}) = _DigitalGuideTranslationsRoom; | ||
|
||
factory DigitalGuideTranslationsRoom.fromJson(Map<String, dynamic> json) => | ||
_$DigitalGuideTranslationsRoomFromJson(json); | ||
} | ||
|
||
@freezed | ||
class DigitalGuideTranslationRoom with _$DigitalGuideTranslationRoom { | ||
const factory DigitalGuideTranslationRoom({ | ||
@JsonKey(name: "name") required String name, | ||
@JsonKey(name: "room_purpose") required String roomPurpose, | ||
@JsonKey(name: "location") required String location, | ||
@JsonKey(name: "working_days_and_hours") | ||
required String workingDaysAndHours, | ||
@JsonKey(name: "are_entrances_comment") required String areEntrancesComment, | ||
@JsonKey(name: "is_one_level_floor_comment") | ||
required String isOneLevelFloorComment, | ||
@JsonKey(name: "are_places_for_wheelchairs_comment") | ||
required String arePlacesForWheelchairsComment, | ||
@JsonKey(name: "comment") required String comment, | ||
}) = _DigitalGuideTranslationRoom; | ||
|
||
factory DigitalGuideTranslationRoom.fromJson(Map<String, dynamic> json) => | ||
_$DigitalGuideTranslationRoomFromJson(json); | ||
} |
26 changes: 26 additions & 0 deletions
26
lib/features/digital_guide_view/tabs/rooms/data/repository/rooms_repository.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import "package:fast_immutable_collections/fast_immutable_collections.dart"; | ||
import "package:flutter_riverpod/flutter_riverpod.dart"; | ||
import "package:riverpod_annotation/riverpod_annotation.dart"; | ||
|
||
import "../../../../data/api/digital_guide_get_and_cache.dart"; | ||
import "../../../../data/models/digital_guide_response.dart"; | ||
import "../models/digital_guide_room.dart"; | ||
|
||
part "rooms_repository.g.dart"; | ||
|
||
@riverpod | ||
Future<IList<DigitalGuideRoom>> roomsRepository( | ||
Ref ref, | ||
DigitalGuideResponse building, | ||
) async { | ||
final String endpoint = "rooms/?building=${building.id}"; | ||
|
||
return ref.getAndCacheDataFromDigitalGuide( | ||
endpoint, | ||
(List<dynamic> json) => json | ||
.whereType<Map<String, dynamic>>() | ||
.map(DigitalGuideRoom.fromJson) | ||
.toIList(), | ||
onRetry: () => ref.invalidateSelf(), | ||
); | ||
} |