-
Notifications
You must be signed in to change notification settings - Fork 32
Upgrade Indexes-related methods to the v0.25.0 #120
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import 'package:meilisearch/src/client_impl.dart'; | ||
| import 'package:meilisearch/src/update_status.dart'; | ||
|
|
||
| import 'pending_update.dart'; | ||
|
|
||
| class ClientTaskImpl implements PendingUpdate { | ||
| final int updateId; | ||
| final MeiliSearchClientImpl client; | ||
|
|
||
| ClientTaskImpl(this.client, this.updateId); | ||
|
|
||
| factory ClientTaskImpl.fromMap( | ||
| MeiliSearchClientImpl client, | ||
| Map<String, dynamic> map, | ||
| ) => | ||
| ClientTaskImpl(client, map['uid'] as int); | ||
|
|
||
| @override | ||
| Future<UpdateStatus> getStatus() async { | ||
| final response = await client.http.getMethod(('/tasks/${this.updateId}')); | ||
|
|
||
| return UpdateStatus.fromMap(response.data); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,21 +69,18 @@ class MeiliSearchIndexImpl implements MeiliSearchIndex { | |
| // | ||
|
|
||
| @override | ||
| Future<void> update({String? primaryKey}) async { | ||
| Future<PendingUpdateImpl> update({String? primaryKey}) async { | ||
| final data = <String, dynamic>{ | ||
| 'primaryKey': primaryKey, | ||
| }; | ||
| data.removeWhere((k, v) => v == null); | ||
| final response = await http.putMethod('/indexes/$uid', data: data); | ||
|
|
||
| _primaryKey = response.data['primaryKey'] as String?; | ||
| _createdAt = DateTime.parse(response.data['createdAt'] as String); | ||
| _updatedAt = DateTime.parse(response.data['updatedAt'] as String); | ||
| return await _update(http.putMethod('/indexes/$uid', data: data)); | ||
| } | ||
|
|
||
| @override | ||
| Future<void> delete() async { | ||
| await http.deleteMethod('/indexes/$uid'); | ||
| Future<PendingUpdateImpl> delete() async { | ||
| return await _update(http.deleteMethod('/indexes/$uid')); | ||
| } | ||
|
|
||
| @override | ||
|
|
@@ -430,15 +427,15 @@ class MeiliSearchIndexImpl implements MeiliSearchIndex { | |
| /// | ||
|
|
||
| Future<List<UpdateStatus>?> getAllUpdateStatus() async { | ||
| final response = await http.getMethod('/indexes/$uid/updates'); | ||
| final response = await http.getMethod('/indexes/$uid/tasks'); | ||
|
|
||
| return (response.data as List) | ||
| return (response.data['results'] as List) | ||
| .map((update) => UpdateStatus.fromMap(update)) | ||
| .toList(); | ||
| } | ||
|
|
||
| Future<UpdateStatus> getUpdateStatus(int updateId) async { | ||
| final response = await http.getMethod(('/indexes/$uid/updates/$updateId')); | ||
| final response = await http.getMethod(('/tasks/$updateId')); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this method should call
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, this was one of my biggest nightmares when I was implementing this... Since we have this extension defined here test/utils/client.dart:73 test('Delete an existing index', () async {
final uid = randomUid();
await client.createIndex(uid).waitFor();
final index = await client.getIndex(uid);
await index.delete().waitFor(); // waitFor() => this causes the issue...
expect(client.getIndex(uid), throwsA(isA<MeiliSearchApiException>()));
});The problem here is because
That is the current situation here, I hope you understand if not, don’t hesitate to make a comment ;) FYI @curquiza (maybe this is an API design situation that I need to be aware of)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had the same issue on another SDK, I rewrite the test to get the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Could you link here to this change you made?
*(on the dart integration you will have the waitFor for all the methods that respond with a Task object (formerly PendingUpdate)), so my
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hello, sorry I read this kind of quickly, so I hope I correctly understood the situation. The Sorry again if this answer does not solve your problem @brunoocasali, tell me! |
||
|
|
||
| return UpdateStatus.fromMap(response.data); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did this method will become
getTask?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought the name will be changed in the next PR but I think this
getStatusmethod andgetUpdateStatusshould be renamed ingetTaskandgetTasks.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I just tried to reduce the scope of changes haha, but I'll do that, thanks for the reminder ;)