This commit is contained in:
rca 2024-07-03 23:12:33 +09:00
parent 8fc8f098d3
commit 1c620869df

View File

@ -8,21 +8,26 @@ import javax.inject.Inject;
import one.nem.kidshift.data.KSActions; import one.nem.kidshift.data.KSActions;
import one.nem.kidshift.data.TaskData; import one.nem.kidshift.data.TaskData;
import one.nem.kidshift.data.retrofit.KidShiftApiService;
import one.nem.kidshift.data.room.utils.CacheWrapper; import one.nem.kidshift.data.room.utils.CacheWrapper;
import one.nem.kidshift.model.callback.TaskItemModelCallback; import one.nem.kidshift.model.callback.TaskItemModelCallback;
import one.nem.kidshift.model.tasks.TaskItemModel; import one.nem.kidshift.model.tasks.TaskItemModel;
import one.nem.kidshift.utils.KSLogger; import one.nem.kidshift.utils.KSLogger;
import one.nem.kidshift.utils.factory.KSLoggerFactory; import one.nem.kidshift.utils.factory.KSLoggerFactory;
import retrofit2.Call;
import retrofit2.Response;
public class TaskDataImpl implements TaskData { public class TaskDataImpl implements TaskData {
private final KSActions ksActions; private final KSActions ksActions;
private final KidShiftApiService kidShiftApiService;
private final CacheWrapper cacheWrapper; private final CacheWrapper cacheWrapper;
private final KSLogger logger; private final KSLogger logger;
@Inject @Inject
public TaskDataImpl(KSActions ksActions, CacheWrapper cacheWrapper, KSLoggerFactory loggerFactory) { public TaskDataImpl(KSActions ksActions, KidShiftApiService kidShiftApiService, CacheWrapper cacheWrapper, KSLoggerFactory loggerFactory) {
this.ksActions = ksActions; this.ksActions = ksActions;
this.kidShiftApiService = kidShiftApiService;
this.cacheWrapper = cacheWrapper; this.cacheWrapper = cacheWrapper;
this.logger = loggerFactory.create("TaskDataImpl"); this.logger = loggerFactory.create("TaskDataImpl");
} }
@ -106,6 +111,19 @@ public class TaskDataImpl implements TaskData {
@Override @Override
public CompletableFuture<Void> recordTaskCompletion(String taskId, String childId) { public CompletableFuture<Void> recordTaskCompletion(String taskId, String childId) {
return CompletableFuture.supplyAsync(() -> {
Call<Void> call = kidShiftApiService.completeTask(taskId, childId);
try {
Response<Void> response = call.execute();
if (response.isSuccessful()) {
logger.info("タスク完了処理成功(taskId: " + taskId + ", childId: " + childId + ")");
return null;
} else {
throw new RuntimeException("HTTP Status: " + response.code());
}
} catch (Exception e) {
throw new RuntimeException(e);
}
});
} }
} }