Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fetch sections by positions #24

Merged
merged 4 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions packages/crossword_repository/lib/src/crossword_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,21 @@ class CrosswordRepository {
}

/// Watches all the sections of the crossword board
B0berman marked this conversation as resolved.
Show resolved Hide resolved
Stream<List<BoardSection>> watchSections() {
final snapshot = sectionCollection.snapshots();
return snapshot.map(
(snapshot) => snapshot.toBoardSectionList(),
);
}

/// Watches all the sections of the crossword board
Stream<List<BoardSection>> watchSectionsFromPositions(
List<Point<int>> positions,
Stream<BoardSection> watchSectionFromPositions(
B0berman marked this conversation as resolved.
Show resolved Hide resolved
Point<int> position,
) {
final snapshot = sectionCollection
.where(
'position',
whereIn: positions,
'position.x',
isEqualTo: position.x,
)
.where(
'position.y',
isEqualTo: position.y,
)
.snapshots();
return snapshot.map(
(snapshot) => snapshot.toBoardSectionList(),
(snapshot) => snapshot.toBoardSectionList().first,
jsgalarraga marked this conversation as resolved.
Show resolved Hide resolved
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,6 @@ void main() {
);
});

group('watchSections', () {
test('returns all the sections', () {
expect(
crosswordRepository.watchSections(),
emits([boardSection1]),
);
});
});

group('watchSection', () {
test('returns the requested section', () async {
expect(
Expand Down Expand Up @@ -85,8 +76,8 @@ void main() {

test('returns the requested sections depending on position', () {
expect(
crosswordRepository.watchSectionsFromPositions([Point(0, 1)]),
emits([section]),
crosswordRepository.watchSectionFromPositions(Point(0, 1)),
emits(section),
);
});
});
Expand Down
Loading