Skip to content

Commit 67af07f

Browse files
bstolinskidt-iohk
andauthored
feat(cat-voices): Migrate document index to v2 endpoint (#3599)
* feat: Migrate document index to v2 endpoint * Update catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/dio_cat_gateway_service.dart Co-authored-by: Dominik Toton <[email protected]> * Update catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/dio_cat_gateway_service.dart Co-authored-by: Dominik Toton <[email protected]> * chore: Simplify comments in API models --------- Co-authored-by: Dominik Toton <[email protected]>
1 parent 0be246c commit 67af07f

File tree

7 files changed

+88
-80
lines changed

7 files changed

+88
-80
lines changed

catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/dio_cat_gateway_service.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ abstract interface class CatGatewayService {
3737

3838
void close();
3939

40-
/// Post A Signed Document Index Query.
41-
/// This endpoint produces a summary of signed documents that meet the criteria
42-
/// defined in the request body.
40+
/// Post A Signed Document Index Query for Newer Versions of v0.0.4.
41+
/// Produces a summary of signed documents that meet the criteria
42+
/// defined in the request body for new signed document versions of v0.0.4.
4343
///
4444
/// It does not return the actual documents, just an index of the document identifiers
4545
/// which allows the documents to be retrieved by the `GET document` endpoint.
@@ -137,7 +137,7 @@ final class DioCatGatewayService implements CatGatewayService {
137137
int? page,
138138
}) {
139139
return _dio.post<dynamic, DocumentIndexList>(
140-
'/v1/document/index',
140+
'/v2/document/index',
141141
queryParameters: {
142142
'limit': ?limit,
143143
'page': ?page,

catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/models/document_index_query_filter.dart

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ part 'document_index_query_filter.g.dart';
1212
/// which do not strictly match the metadata or payload fields included in the query
1313
/// itself.
1414
///
15-
/// Used as request body for POST /api/v1/document/index
15+
/// Used as request body for POST /api/v2/document/index
1616
@JsonSerializable(createFactory: false, includeIfNull: false)
1717
final class DocumentIndexQueryFilter {
1818
/// ## Signed Document Type.
@@ -21,23 +21,26 @@ final class DocumentIndexQueryFilter {
2121
/// [Registered Document Types](https://input-output-hk.github.io/catalyst-libs/architecture/08_concepts/signed_doc/types/)
2222
///
2323
/// UUIDv4 Formatted 128bit value.
24-
final String? type;
24+
///
25+
/// Max items 10
26+
final List<String>? type;
2527

26-
/// Document ID Selector
2728
/// ## Document ID
2829
///
2930
/// Either an absolute single Document ID or a range of
3031
/// [Document IDs](https://input-output-hk.github.io/catalyst-libs/architecture/08_concepts/signed_doc/spec/#id)
31-
final EqOrRangedId? id;
32+
///
33+
/// Max items 10
34+
final List<EqOrRangedId>? id;
3235

33-
/// Document Version Selector
3436
/// ## Document Version
3537
///
3638
/// Either an absolute single Document Version or a range of
3739
/// [Document Versions](https://input-output-hk.github.io/catalyst-libs/architecture/08_concepts/signed_doc/spec/#ver)
38-
final EqOrRangedVer? ver;
40+
///
41+
/// Max items 10
42+
final List<EqOrRangedVer>? ver;
3943

40-
/// Document Reference
4144
/// ## Document Reference
4245
///
4346
/// A [reference](https://input-output-hk.github.io/catalyst-libs/architecture/08_concepts/signed_doc/meta/#ref-document-reference)
@@ -48,9 +51,10 @@ final class DocumentIndexQueryFilter {
4851
///
4952
/// The kind of document that the reference refers to is defined by the
5053
/// [Document Type](https://input-output-hk.github.io/catalyst-libs/architecture/08_concepts/signed_doc/types/)
51-
final IdAndVerRef? ref;
54+
///
55+
/// Max items 10
56+
final List<IdAndVerRef>? ref;
5257

53-
/// Document Reference
5458
/// ## Document Template
5559
///
5660
/// Documents that are created based on a template include the
@@ -64,9 +68,10 @@ final class DocumentIndexQueryFilter {
6468
/// [Document Type](https://input-output-hk.github.io/catalyst-libs/architecture/08_concepts/signed_doc/types/)
6569
/// however, it will always be a template type document that matches the document
6670
/// itself.
67-
final IdAndVerRef? template;
71+
///
72+
/// Max items 10
73+
final List<IdAndVerRef>? template;
6874

69-
/// Document Reference
7075
/// ## Document Reply
7176
///
7277
/// This is a
@@ -80,9 +85,10 @@ final class DocumentIndexQueryFilter {
8085
///
8186
/// The kind of document that the reference refers to is defined by the
8287
/// [Document Type](https://input-output-hk.github.io/catalyst-libs/architecture/08_concepts/signed_doc/types/).
83-
final IdAndVerRef? reply;
88+
///
89+
/// Max items 10
90+
final List<IdAndVerRef>? reply;
8491

85-
/// Document Reference
8692
/// ## Brand
8793
///
8894
/// This is a
@@ -95,9 +101,10 @@ final class DocumentIndexQueryFilter {
95101
///
96102
/// Whether a Document Type has a brand reference is defined by its
97103
/// [Document Type](https://input-output-hk.github.io/catalyst-libs/architecture/08_concepts/signed_doc/types/).
98-
final IdAndVerRef? brand;
104+
///
105+
/// Max items 10
106+
final List<IdAndVerRef>? brand;
99107

100-
/// Document Reference
101108
/// ## Campaign
102109
///
103110
/// This is a
@@ -110,9 +117,10 @@ final class DocumentIndexQueryFilter {
110117
///
111118
/// Whether a Document Type has a campaign reference is defined by its
112119
/// [Document Type](https://input-output-hk.github.io/catalyst-libs/architecture/08_concepts/signed_doc/types/).
113-
final IdAndVerRef? campaign;
120+
///
121+
/// Max items 10
122+
final List<IdAndVerRef>? campaign;
114123

115-
/// Document Reference
116124
/// ## Category
117125
///
118126
/// This is a
@@ -125,7 +133,9 @@ final class DocumentIndexQueryFilter {
125133
///
126134
/// Whether a Document Type has a category reference is defined by its
127135
/// [Document Type](https://input-output-hk.github.io/catalyst-libs/architecture/08_concepts/signed_doc/types/).
128-
final IdAndVerRef? category;
136+
///
137+
/// Max items 10
138+
final List<IdAndVerRef>? category;
129139

130140
const DocumentIndexQueryFilter({
131141
this.type,

catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/models/document_reference.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@ part 'document_reference.g.dart';
77
@JsonSerializable()
88
final class DocumentReference {
99
/// Signed Document ID
10-
/// Document ID Reference
1110
final String id;
1211

1312
/// Signed Document Version
14-
/// Document Version
1513
final String ver;
1614

15+
/// Signed Document Locator
16+
final String? cid;
17+
1718
const DocumentReference({
1819
required this.id,
1920
required this.ver,
21+
this.cid,
2022
});
2123

2224
factory DocumentReference.fromJson(Json json) => _$DocumentReferenceFromJson(json);

catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/models/indexed_document_version.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,22 @@ final class IndexedDocumentVersion {
1515
/// Document Type that matches the filter
1616
final String type;
1717

18-
/// Document Reference for filtered Documents.
1918
/// Document Reference that matches the filter
20-
final DocumentReference? ref;
19+
/// Max items 10
20+
final List<DocumentReference>? ref;
2121

22-
/// Document Reference for filtered Documents.
2322
/// DDocument Reply Reference that matches the filter
24-
final DocumentReference? reply;
23+
/// Max items 10
24+
final List<DocumentReference>? reply;
2525

26-
/// Document Reference for filtered Documents.
2726
/// Document Template Reference that matches the filter
28-
final DocumentReference? template;
27+
/// Max items 10
28+
final List<DocumentReference>? template;
2929

30-
/// Document Reference for filtered Documents.
3130
/// Document Parameter Reference that matches the filter
31+
/// Max items 10
3232
@JsonKey(name: 'doc_parameters')
33-
final DocumentReference? parameters;
33+
final List<DocumentReference>? parameters;
3434

3535
IndexedDocumentVersion({
3636
required this.ver,

catalyst_voices/packages/internal/catalyst_voices_repositories/lib/src/api/models/staked_txo_asset_info.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@ final class StakedTxoAssetInfo {
1212
final String policyHash;
1313

1414
/// Cardano Native Asset Name
15-
/// Token policies Asset Name.
1615
@JsonKey(name: 'asset_name')
1716
final String assetName;
1817

1918
/// Cardano native Asset Value
20-
/// Token Asset Value.
2119
final int amount;
2220

2321
const StakedTxoAssetInfo({

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

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import 'package:catalyst_voices_models/catalyst_voices_models.dart';
22
import 'package:catalyst_voices_repositories/catalyst_voices_repositories.dart';
3-
import 'package:catalyst_voices_repositories/src/api/models/current_page.dart';
43
import 'package:catalyst_voices_repositories/src/api/models/document_index_list.dart';
54
import 'package:catalyst_voices_repositories/src/api/models/document_index_query_filter.dart';
65
import 'package:catalyst_voices_repositories/src/api/models/document_reference.dart';
76
import 'package:catalyst_voices_repositories/src/api/models/eq_or_ranged_id.dart';
7+
import 'package:catalyst_voices_repositories/src/api/models/id_and_ver_ref.dart';
88
import 'package:catalyst_voices_repositories/src/common/future_response_mapper.dart';
99
import 'package:catalyst_voices_repositories/src/document/document_data_factory.dart';
1010
import 'package:collection/collection.dart';
@@ -49,7 +49,7 @@ final class CatGatewayDocumentDataSource implements DocumentDataRemoteSource {
4949
try {
5050
final index = await _api.gateway
5151
.documentIndex(
52-
filter: DocumentIndexQueryFilter(id: EqOrRangedId.eq(id)),
52+
filter: DocumentIndexQueryFilter(id: [EqOrRangedId.eq(id)]),
5353
limit: 1,
5454
)
5555
.successBodyOrThrow();
@@ -76,28 +76,15 @@ final class CatGatewayDocumentDataSource implements DocumentDataRemoteSource {
7676
var remaining = 0;
7777

7878
do {
79-
final response =
80-
await _getDocumentIndexList(
81-
page: page,
82-
limit: maxPerPage,
83-
campaign: campaign,
84-
)
85-
// TODO(damian-molinski): Remove this workaround when migrated to V2 endpoint.
86-
// https://github.com/input-output-hk/catalyst-voices/issues/3199#issuecomment-3204803465
87-
.onError<NotFoundException>(
88-
(_, _) {
89-
return DocumentIndexList(
90-
docs: [],
91-
page: CurrentPage(page: page, limit: maxPerPage, remaining: 0),
92-
);
93-
},
94-
);
79+
final response = await _getDocumentIndexList(
80+
page: page,
81+
limit: maxPerPage,
82+
campaign: campaign,
83+
);
9584

9685
allRefs.addAll(response.refs);
9786

98-
// TODO(damian-molinski): Remove this workaround when migrated to V2 endpoint.
99-
// https://github.com/input-output-hk/catalyst-voices/issues/3199#issuecomment-3204803465
100-
remaining = response.docs.length < maxPerPage ? 0 : response.page.remaining;
87+
remaining = response.page.remaining;
10188
page = response.page.page + 1;
10289
} while (remaining > 0);
10390

@@ -115,16 +102,17 @@ final class CatGatewayDocumentDataSource implements DocumentDataRemoteSource {
115102
required int limit,
116103
required Campaign campaign,
117104
}) async {
118-
// TODO(bstolinski): previously it was possible to use `inside` filter for categories.
119-
// final categoriesIds = campaign.categories.map((e) => e.selfRef.id).toList();
120-
// final categoryFilter = DocumentIndexQueryFilter(
121-
// parameters: IdRefOnly(id: IdSelectorDto.inside(categoriesIds)).toJson(),
122-
// );
123-
const filter = DocumentIndexQueryFilter();
105+
assert(campaign.categories.length <= 10, 'Max 10 categories are allowed in the filter.');
106+
107+
final categoryFilter = campaign.categories
108+
.take(10)
109+
.map((e) => IdAndVerRef.idOnly(EqOrRangedId.eq(e.selfRef.id)))
110+
.toList();
111+
final documentFilter = DocumentIndexQueryFilter(category: categoryFilter);
124112

125113
return _api.gateway
126114
.documentIndex(
127-
filter: filter,
115+
filter: documentFilter,
128116
limit: limit,
129117
page: page,
130118
)
@@ -155,24 +143,32 @@ extension on DocumentIndexList {
155143
type: documentType,
156144
),
157145
if (ver.ref case final ref?)
158-
TypedDocumentRef(
159-
ref: ref.toRef(),
160-
type: DocumentType.unknown,
146+
...ref.map(
147+
(ref) => TypedDocumentRef(
148+
ref: ref.toRef(),
149+
type: DocumentType.unknown,
150+
),
161151
),
162152
if (ver.reply case final reply?)
163-
TypedDocumentRef(
164-
ref: reply.toRef(),
165-
type: DocumentType.unknown,
153+
...reply.map(
154+
(reply) => TypedDocumentRef(
155+
ref: reply.toRef(),
156+
type: DocumentType.unknown,
157+
),
166158
),
167159
if (ver.parameters case final parameters?)
168-
TypedDocumentRef(
169-
ref: parameters.toRef(),
170-
type: DocumentType.categoryParametersDocument,
160+
...parameters.map(
161+
(parameters) => TypedDocumentRef(
162+
ref: parameters.toRef(),
163+
type: DocumentType.categoryParametersDocument,
164+
),
171165
),
172166
if (ver.template case final template?)
173-
TypedDocumentRef(
174-
ref: template.toRef(),
175-
type: documentType.template ?? DocumentType.unknown,
167+
...template.map(
168+
(template) => TypedDocumentRef(
169+
ref: template.toRef(),
170+
type: documentType.template ?? DocumentType.unknown,
171+
),
176172
),
177173
];
178174
})

catalyst_voices/packages/internal/catalyst_voices_repositories/test/src/document/source/document_data_remote_source_test.dart

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,12 @@ void main() {
105105
return IndexedDocumentVersion(
106106
ver: e.version!,
107107
type: DocumentType.proposalDocument.uuid,
108-
template: DocumentReference(
109-
id: templateRef.id,
110-
ver: templateRef.version!,
111-
),
108+
template: [
109+
DocumentReference(
110+
id: templateRef.id,
111+
ver: templateRef.version!,
112+
),
113+
],
112114
);
113115
}).toList(),
114116
),
@@ -142,8 +144,8 @@ void main() {
142144

143145
IndexedDocument _buildDocumentIndexList({
144146
int verCount = 2,
145-
DocumentReference? template,
146-
DocumentReference? ref,
147+
List<DocumentReference>? template,
148+
List<DocumentReference>? ref,
147149
}) {
148150
return IndexedDocument(
149151
id: DocumentRefFactory.randomUuidV7(),

0 commit comments

Comments
 (0)