Skip to content

Commit 541cb0b

Browse files
committed
Fix due to review and linter
1 parent 8560a7b commit 541cb0b

File tree

4 files changed

+20
-21
lines changed

4 files changed

+20
-21
lines changed

src/main/java/com/meilisearch/sdk/Client.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ public TaskInfo createIndex(String uid, String primaryKey) throws MeilisearchExc
6868
}
6969

7070
/**
71-
* Gets all indexes
72-
* https://docs.meilisearch.com/reference/api/indexes.html#list-all-indexes
71+
* Gets all indexes https://docs.meilisearch.com/reference/api/indexes.html#list-all-indexes
7372
*
7473
* @return Results containing a list of indexes from the Meilisearch API
7574
* @throws MeilisearchException if an error occurs
@@ -83,10 +82,9 @@ public Results<Index> getIndexes() throws MeilisearchException {
8382
}
8483

8584
/**
86-
* Gets indexes
87-
* https://docs.meilisearch.com/reference/api/indexes.html#list-all-indexes
85+
* Gets indexes https://docs.meilisearch.com/reference/api/indexes.html#list-all-indexes
8886
*
89-
* @param query parameters accepted by the get indexes route
87+
* @param params query parameters accepted by the get indexes route
9088
* @return Results containing a list of indexes from the Meilisearch API
9189
* @throws MeilisearchException if an error occurs
9290
*/
@@ -99,8 +97,7 @@ public Results<Index> getIndexes(IndexesQuery params) throws MeilisearchExceptio
9997
}
10098

10199
/**
102-
* Gets all indexes
103-
* https://docs.meilisearch.com/reference/api/indexes.html#list-all-indexes
100+
* Gets all indexes https://docs.meilisearch.com/reference/api/indexes.html#list-all-indexes
104101
*
105102
* @return List of indexes from the Meilisearch API as String
106103
* @throws MeilisearchException if an error occurs

src/main/java/com/meilisearch/sdk/IndexesHandler.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.meilisearch.sdk;
22

33
import com.meilisearch.sdk.exceptions.MeilisearchException;
4-
import com.meilisearch.sdk.http.URLBuilder;
54
import com.meilisearch.sdk.model.IndexesQuery;
65
import com.meilisearch.sdk.model.Results;
76
import com.meilisearch.sdk.model.TaskInfo;
@@ -60,10 +59,7 @@ TaskInfo createIndex(String uid, String primaryKey) throws MeilisearchException
6059
* @throws MeilisearchException if an error occurs
6160
*/
6261
Index getIndex(String uid) throws MeilisearchException {
63-
URLBuilder urlb = new URLBuilder();
64-
urlb.addSubroute("indexes").addSubroute(uid);
65-
String urlPath = urlb.getURL();
66-
return httpClient.get(urlPath, Index.class);
62+
return httpClient.get(new IndexesQuery().toQuery(uid), Index.class);
6763
}
6864

6965
/**
@@ -84,7 +80,7 @@ Results<Index> getIndexes() throws MeilisearchException {
8480
* @throws MeilisearchException if an error occurs
8581
*/
8682
Results<Index> getIndexes(IndexesQuery params) throws MeilisearchException {
87-
return httpClient.get(param.toQuery(params), Results.class, Index.class);
83+
return httpClient.get(params.toQuery(params), Results.class, Index.class);
8884
}
8985

9086
/**
@@ -109,10 +105,7 @@ TaskInfo updatePrimaryKey(String uid, String primaryKey) throws MeilisearchExcep
109105
HashMap<String, String> index = new HashMap<String, String>();
110106
index.put("primaryKey", primaryKey);
111107

112-
URLBuilder urlb = new URLBuilder();
113-
urlb.addSubroute("indexes").addSubroute(uid);
114-
String urlPath = urlb.getURL();
115-
return httpClient.patch(urlPath, index, TaskInfo.class);
108+
return httpClient.patch(new IndexesQuery().toQuery(uid), index, TaskInfo.class);
116109
}
117110

118111
/**
@@ -123,9 +116,6 @@ TaskInfo updatePrimaryKey(String uid, String primaryKey) throws MeilisearchExcep
123116
* @throws MeilisearchException if an error occurs
124117
*/
125118
TaskInfo deleteIndex(String uid) throws MeilisearchException {
126-
URLBuilder urlb = new URLBuilder();
127-
urlb.addSubroute("indexes").addSubroute(uid);
128-
String urlPath = urlb.getURL();
129-
return httpClient.delete(urlPath, TaskInfo.class);
119+
return httpClient.delete(new IndexesQuery().toQuery(uid), TaskInfo.class);
130120
}
131121
}

src/main/java/com/meilisearch/sdk/model/IndexesQuery.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ public class IndexesQuery {
1919

2020
public IndexesQuery() {}
2121

22+
public String toQuery(String uid) {
23+
URLBuilder urlb = new URLBuilder();
24+
urlb.addSubroute("indexes").addSubroute(uid);
25+
return urlb.getURL();
26+
}
27+
2228
public String toQuery(IndexesQuery param) {
2329
URLBuilder urlb = new URLBuilder();
2430
urlb.addSubroute("indexes")

src/test/java/com/meilisearch/integration/ClientTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import com.meilisearch.sdk.model.TaskInfo;
1616
import com.meilisearch.sdk.utils.Movie;
1717
import java.util.Arrays;
18+
import org.junit.jupiter.api.AfterAll;
1819
import org.junit.jupiter.api.BeforeEach;
1920
import org.junit.jupiter.api.Tag;
2021
import org.junit.jupiter.api.Test;
@@ -33,6 +34,11 @@ public void initialize() {
3334
cleanup();
3435
}
3536

37+
@AfterAll
38+
static void cleanMeilisearch() {
39+
cleanup();
40+
}
41+
3642
/** Test Index creation without PrimaryKey */
3743
@Test
3844
public void testCreateIndexWithoutPrimaryKey() throws Exception {

0 commit comments

Comments
 (0)