Action実装 WIP
This commit is contained in:
parent
9d449aa575
commit
4d3b7ac6d2
|
@ -29,6 +29,6 @@ public interface KSActions {
|
|||
/**
|
||||
* 履歴情報同期
|
||||
*/
|
||||
CompletableFuture<List<HistoryModel>> syncHistory();
|
||||
CompletableFuture<List<HistoryModel>> syncHistory(String childId);
|
||||
|
||||
}
|
||||
|
|
|
@ -10,12 +10,15 @@ import one.nem.kidshift.data.UserSettings;
|
|||
import one.nem.kidshift.data.retrofit.KidShiftApiService;
|
||||
import one.nem.kidshift.data.retrofit.model.child.ChildListResponse;
|
||||
import one.nem.kidshift.data.retrofit.model.converter.ChildModelConverter;
|
||||
import one.nem.kidshift.data.retrofit.model.converter.HistoryModelConverter;
|
||||
import one.nem.kidshift.data.retrofit.model.converter.ParentModelConverter;
|
||||
import one.nem.kidshift.data.retrofit.model.converter.TaskModelConverter;
|
||||
import one.nem.kidshift.data.retrofit.model.parent.ParentInfoResponse;
|
||||
import one.nem.kidshift.data.retrofit.model.task.HistoryListResponse;
|
||||
import one.nem.kidshift.data.retrofit.model.task.TaskListResponse;
|
||||
import one.nem.kidshift.data.room.utils.CacheWrapper;
|
||||
import one.nem.kidshift.model.ChildModel;
|
||||
import one.nem.kidshift.model.HistoryModel;
|
||||
import one.nem.kidshift.model.ParentModel;
|
||||
import one.nem.kidshift.model.tasks.TaskItemModel;
|
||||
import one.nem.kidshift.utils.KSLogger;
|
||||
|
@ -152,4 +155,31 @@ public class KSActionsImpl implements KSActions {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<List<HistoryModel>> syncHistory(String childId) {
|
||||
CompletableFuture<HistoryListResponse> callHistoryApi = CompletableFuture.supplyAsync(() -> {
|
||||
Call<HistoryListResponse> call = kidShiftApiService.getHistory(childId);
|
||||
try {
|
||||
Response<HistoryListResponse> response = call.execute();
|
||||
if (!response.isSuccessful()) {
|
||||
logger.error("Error fetching history list: " + response.errorBody().string());
|
||||
throw new RuntimeException("Error fetching history list: " + response.errorBody().string());
|
||||
}
|
||||
HistoryListResponse responseBody = response.body();
|
||||
return responseBody;
|
||||
} catch (Exception e) {
|
||||
logger.error("Error fetching history list");
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
|
||||
CompletableFuture<TaskListResponse> callTaskApi = fetchTaskListAsync();
|
||||
|
||||
return CompletableFuture.allOf(callHistoryApi, callTaskApi).thenApplyAsync(result -> {
|
||||
HistoryListResponse historyListResponse = callHistoryApi.join();
|
||||
TaskListResponse taskListResponse = callTaskApi.join();
|
||||
return HistoryModelConverter.historyListResponseAndTaskListResponseToHistoryModelList(historyListResponse, taskListResponse);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user