Action実装 WIP

This commit is contained in:
ろむねこ 2024-07-08 11:25:33 +09:00
parent 9d449aa575
commit 4d3b7ac6d2
Signed by: Fujimatsu
GPG Key ID: FA1F39A1BA37D168
2 changed files with 31 additions and 1 deletions

View File

@ -29,6 +29,6 @@ public interface KSActions {
/**
* 履歴情報同期
*/
CompletableFuture<List<HistoryModel>> syncHistory();
CompletableFuture<List<HistoryModel>> syncHistory(String childId);
}

View File

@ -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);
});
}
}