Skip to content

Commit a5e8acf

Browse files
separate get and getWhere
1 parent 566acd6 commit a5e8acf

File tree

8 files changed

+61
-56
lines changed

8 files changed

+61
-56
lines changed

catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/document/document_repository.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -298,21 +298,21 @@ final class DocumentRepositoryImpl implements DocumentRepository {
298298
Future<DocumentData?> getLatestDocument({
299299
CatalystId? authorId,
300300
}) async {
301-
final latestDocument = await _localDocuments.get(authorId: authorId);
302-
final latestDraft = await _drafts.get();
301+
final latestDocument = await _localDocuments.getWhere(authorId: authorId);
302+
final latestDraft = await _drafts.getWhere();
303303

304304
return [latestDocument, latestDraft].nonNulls.sorted((a, b) => a.compareTo(b)).firstOrNull;
305305
}
306306

307307
// TODO(damian-molinski): consider also checking with remote source.
308308
@override
309309
Future<DocumentRef?> getLatestOf({required DocumentRef ref}) async {
310-
final draft = await _drafts.getLatestOf(ref: ref);
310+
final draft = await _drafts.getLatestRefOf(ref);
311311
if (draft != null) {
312312
return draft;
313313
}
314314

315-
return _localDocuments.getLatestOf(ref: ref);
315+
return _localDocuments.getLatestRefOf(ref);
316316
}
317317

318318
@override
@@ -328,7 +328,7 @@ final class DocumentRepositoryImpl implements DocumentRepository {
328328
required DocumentRef refTo,
329329
required DocumentType type,
330330
}) {
331-
return _localDocuments.get(refTo: refTo, type: type);
331+
return _localDocuments.getWhere(refTo: refTo, type: type);
332332
}
333333

334334
@override
@@ -614,7 +614,7 @@ final class DocumentRepositoryImpl implements DocumentRepository {
614614
Future<DocumentData?> _getDraftDocumentData({
615615
required DraftRef ref,
616616
}) async {
617-
return _drafts.get(ref: ref);
617+
return _drafts.get(ref);
618618
}
619619

620620
Future<DocumentData?> _getSignedDocumentData({
@@ -631,10 +631,10 @@ final class DocumentRepositoryImpl implements DocumentRepository {
631631

632632
final isCached = useCache && await _localDocuments.exists(ref: ref);
633633
if (isCached) {
634-
return _localDocuments.get(ref: ref);
634+
return _localDocuments.get(ref);
635635
}
636636

637-
final document = await _remoteDocuments.get(ref: ref);
637+
final document = await _remoteDocuments.get(ref);
638638

639639
if (useCache && document != null) {
640640
await _localDocuments.save(data: document);

catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/document/source/database_documents_data_source.dart

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,7 @@ final class DatabaseDocumentsDataSource
5050
}
5151

5252
@override
53-
Future<DocumentData?> get({
54-
DocumentType? type,
55-
DocumentRef? ref,
56-
DocumentRef? refTo,
57-
CatalystId? authorId,
58-
}) {
59-
return _database.documentsV2Dao
60-
.getDocument(type: type, ref: ref, refTo: refTo, author: authorId)
61-
.then((value) => value?.toModel());
62-
}
53+
Future<DocumentData?> get(DocumentRef ref) => getWhere(ref: ref);
6354

6455
@override
6556
Future<List<DocumentData>> getAll({
@@ -83,7 +74,7 @@ final class DatabaseDocumentsDataSource
8374
}
8475

8576
@override
86-
Future<DocumentRef?> getLatestOf({required DocumentRef ref}) {
77+
Future<DocumentRef?> getLatestRefOf(DocumentRef ref) {
8778
return _database.documentsV2Dao.getLatestOf(ref);
8879
}
8980

@@ -95,6 +86,18 @@ final class DatabaseDocumentsDataSource
9586
return _database.proposalsV2Dao.getProposalsTotalTask(filters: filters, nodeId: nodeId);
9687
}
9788

89+
@override
90+
Future<DocumentData?> getWhere({
91+
DocumentType? type,
92+
DocumentRef? ref,
93+
DocumentRef? refTo,
94+
CatalystId? authorId,
95+
}) {
96+
return _database.documentsV2Dao
97+
.getDocument(type: type, ref: ref, refTo: refTo, author: authorId)
98+
.then((value) => value?.toModel());
99+
}
100+
98101
@override
99102
Future<void> save({required DocumentData data}) => saveAll([data]);
100103

catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/document/source/database_drafts_data_source.dart

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,7 @@ final class DatabaseDraftsDataSource implements DraftDataSource {
4040
}
4141

4242
@override
43-
Future<DocumentData?> get({
44-
DocumentType? type,
45-
DocumentRef? ref,
46-
DocumentRef? refTo,
47-
}) {
48-
return _database.localDocumentsV2Dao
49-
.getDocument(type: type, ref: ref, refTo: refTo)
50-
.then((value) => value?.toModel());
51-
}
43+
Future<DocumentData?> get(DocumentRef ref) => getWhere(ref: ref);
5244

5345
@override
5446
Future<List<DocumentData>> getAll({
@@ -72,10 +64,21 @@ final class DatabaseDraftsDataSource implements DraftDataSource {
7264
}
7365

7466
@override
75-
Future<DocumentRef?> getLatestOf({required DocumentRef ref}) async {
67+
Future<DocumentRef?> getLatestRefOf(DocumentRef ref) async {
7668
return _database.localDocumentsV2Dao.getLatestOf(ref);
7769
}
7870

71+
@override
72+
Future<DocumentData?> getWhere({
73+
DocumentType? type,
74+
DocumentRef? ref,
75+
DocumentRef? refTo,
76+
}) {
77+
return _database.localDocumentsV2Dao
78+
.getDocument(type: type, ref: ref, refTo: refTo)
79+
.then((value) => value?.toModel());
80+
}
81+
7982
@override
8083
Future<void> save({required DocumentData data}) => saveAll([data]);
8184

catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/document/source/document_data_local_source.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,19 @@ abstract interface class DocumentDataLocalSource implements DocumentDataSource {
1717

1818
Future<List<DocumentRef>> filterExisting(List<DocumentRef> refs);
1919

20-
@override
21-
Future<DocumentData?> get({
20+
Future<List<DocumentData>> getAll({
2221
DocumentType? type,
2322
DocumentRef? ref,
2423
DocumentRef? refTo,
24+
bool latestOnly,
25+
int limit,
26+
int offset,
2527
});
2628

27-
Future<List<DocumentData>> getAll({
29+
Future<DocumentData?> getWhere({
2830
DocumentType? type,
2931
DocumentRef? ref,
3032
DocumentRef? refTo,
31-
bool latestOnly,
32-
int limit,
33-
int offset,
3433
});
3534

3635
Future<void> save({required DocumentData data});

catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/document/source/document_data_remote_source.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ final class CatGatewayDocumentDataSource implements DocumentDataRemoteSource {
1818
);
1919

2020
@override
21-
Future<DocumentData> get({DocumentRef? ref}) async {
21+
Future<DocumentData> get(DocumentRef ref) async {
2222
final bytes = await _api.gateway
2323
.apiV1DocumentDocumentIdGet(
24-
documentId: ref?.id,
25-
version: ref?.version,
24+
documentId: ref.id,
25+
version: ref.version,
2626
)
2727
.successBodyBytesOrThrow();
2828

@@ -31,7 +31,7 @@ final class CatGatewayDocumentDataSource implements DocumentDataRemoteSource {
3131
}
3232

3333
@override
34-
Future<DocumentRef?> getLatestOf({required DocumentRef ref}) async {
34+
Future<DocumentRef?> getLatestRefOf(DocumentRef ref) async {
3535
final ver = await getLatestVersion(ref.id);
3636
if (ver == null) {
3737
return null;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'package:catalyst_voices_models/catalyst_voices_models.dart';
22

33
abstract interface class DocumentDataSource {
4-
Future<DocumentData?> get({DocumentRef? ref});
4+
Future<DocumentData?> get(DocumentRef ref);
55

6-
Future<DocumentRef?> getLatestOf({required DocumentRef ref});
6+
Future<DocumentRef?> getLatestRefOf(DocumentRef ref);
77
}

catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/document/source/signed_document_data_local_source.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'package:catalyst_voices_repositories/catalyst_voices_repositories.dart';
44
/// See [DatabaseDocumentsDataSource].
55
abstract interface class SignedDocumentDataSource implements DocumentDataLocalSource {
66
@override
7-
Future<DocumentData?> get({
7+
Future<DocumentData?> getWhere({
88
DocumentType? type,
99
DocumentRef? ref,
1010
DocumentRef? refTo,

catalyst_voices/packages/internal/catalyst_voices_repositories/test/src/document/document_repository_test.dart

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ void main() {
6666
);
6767

6868
when(
69-
() => remoteDocuments.get(ref: template.ref),
69+
() => remoteDocuments.get(template.ref),
7070
).thenAnswer((_) => Future.value(template));
7171
when(
72-
() => remoteDocuments.get(ref: proposal.ref),
72+
() => remoteDocuments.get(proposal.ref),
7373
).thenAnswer((_) => Future.value(proposal));
7474

7575
// When
@@ -97,10 +97,10 @@ void main() {
9797
template: templateRef,
9898
);
9999

100-
when(() => remoteDocuments.get(ref: templateRef)).thenAnswer(
100+
when(() => remoteDocuments.get(templateRef)).thenAnswer(
101101
(_) => Future.error(DocumentNotFoundException(ref: templateRef)),
102102
);
103-
when(() => remoteDocuments.get(ref: proposal.ref)).thenAnswer(
103+
when(() => remoteDocuments.get(proposal.ref)).thenAnswer(
104104
(_) => Future.error(DocumentNotFoundException(ref: templateRef)),
105105
);
106106

@@ -133,14 +133,14 @@ void main() {
133133

134134
final ref = documentData.ref;
135135

136-
when(() => remoteDocuments.get(ref: ref)).thenAnswer((_) => Future.value(documentData));
136+
when(() => remoteDocuments.get(ref)).thenAnswer((_) => Future.value(documentData));
137137

138138
// When
139139
await repository.getDocumentData(ref: ref);
140140
await repository.getDocumentData(ref: ref);
141141

142142
// Then
143-
verify(() => remoteDocuments.get(ref: ref)).called(1);
143+
verify(() => remoteDocuments.get(ref)).called(1);
144144
},
145145
onPlatform: driftOnPlatforms,
146146
);
@@ -162,15 +162,15 @@ void main() {
162162
when(() => remoteDocuments.getLatestVersion(id)).thenAnswer((_) => Future.value(version));
163163

164164
when(
165-
() => remoteDocuments.get(ref: exactRef),
165+
() => remoteDocuments.get(exactRef),
166166
).thenAnswer((_) => Future.value(documentData));
167167

168168
// When
169169
await repository.getDocumentData(ref: ref);
170170

171171
// Then
172172
verify(() => remoteDocuments.getLatestVersion(id)).called(1);
173-
verify(() => remoteDocuments.get(ref: exactRef)).called(1);
173+
verify(() => remoteDocuments.get(exactRef)).called(1);
174174
},
175175
onPlatform: driftOnPlatforms,
176176
);
@@ -189,10 +189,10 @@ void main() {
189189
final proposal = DocumentDataFactory.build(template: templateRef);
190190

191191
when(
192-
() => remoteDocuments.get(ref: template.ref),
192+
() => remoteDocuments.get(template.ref),
193193
).thenAnswer((_) => Future.value(template));
194194
when(
195-
() => remoteDocuments.get(ref: proposal.ref),
195+
() => remoteDocuments.get(proposal.ref),
196196
).thenAnswer((_) => Future.value(proposal));
197197

198198
// When
@@ -233,13 +233,13 @@ void main() {
233233
final proposal2 = DocumentDataFactory.build(template: templateRef);
234234

235235
when(
236-
() => remoteDocuments.get(ref: template.ref),
236+
() => remoteDocuments.get(template.ref),
237237
).thenAnswer((_) => Future.value(template));
238238
when(
239-
() => remoteDocuments.get(ref: proposal1.ref),
239+
() => remoteDocuments.get(proposal1.ref),
240240
).thenAnswer((_) => Future.value(proposal1));
241241
when(
242-
() => remoteDocuments.get(ref: proposal2.ref),
242+
() => remoteDocuments.get(proposal2.ref),
243243
).thenAnswer((_) => Future.value(proposal2));
244244

245245
// When
@@ -262,7 +262,7 @@ void main() {
262262
expect(proposals[0]!.data.ref, proposal1.ref);
263263
expect(proposals[1]!.data.ref, proposal2.ref);
264264

265-
verify(() => remoteDocuments.get(ref: template.ref)).called(1);
265+
verify(() => remoteDocuments.get(template.ref)).called(1);
266266
},
267267
onPlatform: driftOnPlatforms,
268268
);

0 commit comments

Comments
 (0)