getDocuments method
Retrieves a paginated list of documents for a specific document type.
documentType - The type of documents to retrieve (e.g., 'article', 'page')
search - Optional search query to filter documents
limit - Maximum number of documents to return (default: 20)
offset - Number of documents to skip for pagination (default: 0)
Returns a DocumentList containing the documents and pagination info.
Throws DeskDataSourceException if the operation fails.
Implementation
@override
Future<DocumentList> getDocuments(
String documentType, {
String? search,
int limit = 20,
int offset = 0,
}) async {
var docs = _documents.values
.where((d) => d.documentType == documentType)
.toList();
if (search != null && search.isNotEmpty) {
final query = search.toLowerCase();
docs = docs.where((d) => d.title.toLowerCase().contains(query)).toList();
}
final total = docs.length;
final paged = docs.skip(offset).take(limit).toList();
return DocumentList(
documents: paged,
total: total,
page: (offset ~/ limit) + 1,
pageSize: limit,
);
}