Skip to content

Commit

Permalink
feat(digital-guide): add data layer for rooms section
Browse files Browse the repository at this point in the history
  • Loading branch information
mikolaj-jalocha committed Jan 15, 2025
1 parent 1badbad commit c7ae02d
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
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);
}
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(),
);
}

0 comments on commit c7ae02d

Please sign in to comment.