Skip to content

Commit

Permalink
feat(digital-guide): setup data layer
Browse files Browse the repository at this point in the history
  • Loading branch information
mikolaj-jalocha committed Jan 22, 2025
1 parent a44f76e commit 5ba3792
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
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);
}
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(),
);
}

0 comments on commit 5ba3792

Please sign in to comment.