3
3
import java .util .List ;
4
4
import java .util .Map ;
5
5
6
- import com .fasterxml .jackson .core .JsonProcessingException ;
7
- import com .fasterxml .jackson .databind .ObjectMapper ;
8
- import com .javadiscord .jdi .core .api .utils .CacheUpdateHandler ;
6
+ import com .javadiscord .jdi .core .api .utils .CacheUpdater ;
9
7
import com .javadiscord .jdi .internal .api .DiscordRequest ;
10
8
import com .javadiscord .jdi .internal .api .DiscordRequestDispatcher ;
11
9
import com .javadiscord .jdi .internal .api .DiscordResponse ;
18
16
public class DiscordResponseParser {
19
17
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper ();
20
18
private final DiscordRequestDispatcher dispatcher ;
21
- private final CacheUpdateHandler cacheUpdateHandler ;
19
+ private final CacheUpdater cacheUpdater ;
22
20
23
21
public DiscordResponseParser (DiscordRequestDispatcher dispatcher , Cache cache ) {
24
22
this .dispatcher = dispatcher ;
25
- this .cacheUpdateHandler = new CacheUpdateHandler (cache );
23
+ this .cacheUpdater = new CacheUpdater (cache );
26
24
}
27
25
28
26
public <T > AsyncResponse <List <T >> callAndParseList (Class <T > clazz , DiscordRequest request ) {
@@ -34,6 +32,7 @@ public <T> AsyncResponse<List<T>> callAndParseList(Class<T> clazz, DiscordReques
34
32
try {
35
33
List <T > resultList = parseResponseFromList (clazz , response .body ());
36
34
asyncResponse .setResult (resultList );
35
+ cacheUpdater .updateCache (resultList );
37
36
} catch (Exception e ) {
38
37
asyncResponse .setException (e );
39
38
}
@@ -42,19 +41,6 @@ public <T> AsyncResponse<List<T>> callAndParseList(Class<T> clazz, DiscordReques
42
41
}
43
42
}
44
43
);
45
- response -> {
46
- if (isSuccessfulResponse (response )) {
47
- try {
48
- List <T > resultList = parseResponseFromList (clazz , response .body ());
49
- asyncResponse .setResult (resultList );
50
- cacheUpdateHandler .updateCache (resultList );
51
- } catch (Exception e ) {
52
- asyncResponse .setException (e );
53
- }
54
- } else {
55
- asyncResponse .setException (errorResponseException (response ));
56
- }
57
- });
58
44
future .onError (asyncResponse ::setException );
59
45
return asyncResponse ;
60
46
}
@@ -76,19 +62,6 @@ public <T> AsyncResponse<List<T>> callAndParseMap(String key, DiscordRequest req
76
62
}
77
63
}
78
64
);
79
- response -> {
80
- if (isSuccessfulResponse (response )) {
81
- try {
82
- List <T > resultList = parseResponseFromMap (key , response .body ());
83
- asyncResponse .setResult (resultList );
84
- cacheUpdateHandler .updateCache (resultList );
85
- } catch (Exception e ){
86
- asyncResponse .setException (e );
87
- }
88
- } else {
89
- asyncResponse .setException (errorResponseException (response ));
90
- }
91
- });
92
65
future .onError (asyncResponse ::setException );
93
66
return asyncResponse ;
94
67
}
@@ -137,7 +110,7 @@ private <T> void success(
137
110
result = OBJECT_MAPPER .readValue (response .body (), type );
138
111
}
139
112
asyncResponse .setResult (result );
140
- cacheUpdateHandler .updateCache (result );
113
+ cacheUpdater .updateCache (result );
141
114
} catch (JsonProcessingException e ) {
142
115
asyncResponse .setException (e );
143
116
}
0 commit comments