-
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): setup data layer
- Loading branch information
1 parent
a44f76e
commit 5ba3792
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
lib/features/digital_guide_view/tabs/lodge/data/models/digital_guide_lodge.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,38 @@ | ||
import "package:freezed_annotation/freezed_annotation.dart"; | ||
|
||
part "digital_guide_lodge.freezed.dart"; | ||
part "digital_guide_lodge.g.dart"; | ||
|
||
@freezed | ||
class DigitalGuideLodge with _$DigitalGuideLodge { | ||
const factory DigitalGuideLodge({ | ||
required int id, | ||
required DigitalGuideTranslationsLodge translations, | ||
@JsonKey(name: "images") required List<int>? imagesIds, | ||
}) = _DigitalGuideLodge; | ||
|
||
factory DigitalGuideLodge.fromJson(Map<String, dynamic> json) => | ||
_$DigitalGuideLodgeFromJson(json); | ||
} | ||
|
||
@freezed | ||
class DigitalGuideTranslationsLodge with _$DigitalGuideTranslationsLodge { | ||
const factory DigitalGuideTranslationsLodge({ | ||
required DigitalGuideTranslationLodge pl, | ||
}) = _DigitalGuideTranslationsLodge; | ||
|
||
factory DigitalGuideTranslationsLodge.fromJson(Map<String, dynamic> json) => | ||
_$DigitalGuideTranslationsLodgeFromJson(json); | ||
} | ||
|
||
@freezed | ||
class DigitalGuideTranslationLodge with _$DigitalGuideTranslationLodge { | ||
@JsonSerializable(fieldRename: FieldRename.snake) | ||
const factory DigitalGuideTranslationLodge({ | ||
required String location, | ||
required String workingDaysAndHours, | ||
required String comment, | ||
}) = _DigitalGuideTranslationLodge; | ||
factory DigitalGuideTranslationLodge.fromJson(Map<String, dynamic> json) => | ||
_$DigitalGuideTranslationLodgeFromJson(json); | ||
} |
25 changes: 25 additions & 0 deletions
25
lib/features/digital_guide_view/tabs/lodge/data/repository/lodges_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,25 @@ | ||
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_lodge.dart"; | ||
|
||
part "lodges_repository.g.dart"; | ||
|
||
@riverpod | ||
Future<IList<DigitalGuideLodge>> lodgesRepository( | ||
Ref ref, | ||
DigitalGuideResponse building, | ||
) async { | ||
final endpoint = "lodges/?building=${building.id}"; | ||
return ref.getAndCacheDataFromDigitalGuide( | ||
endpoint, | ||
(List<dynamic> json) => json | ||
.whereType<Map<String, dynamic>>() | ||
.map(DigitalGuideLodge.fromJson) | ||
.toIList(), | ||
onRetry: () => ref.invalidateSelf(), | ||
); | ||
} |