Merge pull request 'feature/complete_task' (#124) from feature/complete_task into main

Reviewed-on: #124
This commit is contained in:
Fujimatsu 2024-07-03 14:13:14 +00:00
commit d49ab35914
3 changed files with 25 additions and 5 deletions

View File

@ -55,5 +55,5 @@ public interface TaskData {
* @param taskId タスクID
* @param childId 子ID
*/
void recordTaskCompletion(String taskId, String childId);
CompletableFuture<Void> recordTaskCompletion(String taskId, String childId);
}

View File

@ -8,21 +8,26 @@ import javax.inject.Inject;
import one.nem.kidshift.data.KSActions;
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.model.callback.TaskItemModelCallback;
import one.nem.kidshift.model.tasks.TaskItemModel;
import one.nem.kidshift.utils.KSLogger;
import one.nem.kidshift.utils.factory.KSLoggerFactory;
import retrofit2.Call;
import retrofit2.Response;
public class TaskDataImpl implements TaskData {
private final KSActions ksActions;
private final KidShiftApiService kidShiftApiService;
private final CacheWrapper cacheWrapper;
private final KSLogger logger;
@Inject
public TaskDataImpl(KSActions ksActions, CacheWrapper cacheWrapper, KSLoggerFactory loggerFactory) {
public TaskDataImpl(KSActions ksActions, KidShiftApiService kidShiftApiService, CacheWrapper cacheWrapper, KSLoggerFactory loggerFactory) {
this.ksActions = ksActions;
this.kidShiftApiService = kidShiftApiService;
this.cacheWrapper = cacheWrapper;
this.logger = loggerFactory.create("TaskDataImpl");
}
@ -105,7 +110,21 @@ public class TaskDataImpl implements TaskData {
}
@Override
public 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 {
logger.error("タスク完了処理失敗: HTTP Status: " + response.code());
throw new RuntimeException("HTTP Status: " + response.code());
}
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}
}

View File

@ -20,6 +20,7 @@ import retrofit2.http.Headers;
import retrofit2.http.POST;
import retrofit2.http.PUT;
import retrofit2.http.Path;
import retrofit2.http.Query;
public interface KidShiftApiService {
@ -96,7 +97,7 @@ public interface KidShiftApiService {
*/
@POST("/parent/task/{id}/complete")
@Headers(AuthorizationInterceptor.HEADER_PLACEHOLDER)
Call<Void> completeTask(@Path("id") String id); // TODO-rca: OK responseをパース
Call<Void> completeTask(@Path("id") String id, @Query("childId") String childId);
// Child APIs