型修正, APIリクエスト実装

This commit is contained in:
ろむねこ 2024-07-05 11:37:30 +09:00
parent bef159028d
commit b625918138
Signed by: Fujimatsu
GPG Key ID: FA1F39A1BA37D168
2 changed files with 19 additions and 3 deletions

View File

@ -31,7 +31,7 @@ public interface ChildData {
* 子ユーザー追加
* @param child 子ユーザー情報
*/
void addChild(ChildModel child);
CompletableFuture<ChildModel> addChild(ChildModel child);
/**
* 子ユーザー削除

View File

@ -10,6 +10,8 @@ import one.nem.kidshift.data.ChildData;
import one.nem.kidshift.data.KSActions;
import one.nem.kidshift.data.retrofit.KidShiftApiService;
import one.nem.kidshift.data.retrofit.model.child.ChildLoginCodeResponse;
import one.nem.kidshift.data.retrofit.model.child.ChildResponse;
import one.nem.kidshift.data.retrofit.model.converter.ChildModelConverter;
import one.nem.kidshift.data.room.utils.CacheWrapper;
import one.nem.kidshift.model.ChildModel;
import one.nem.kidshift.model.callback.ChildModelCallback;
@ -92,8 +94,22 @@ public class ChildDataImpl implements ChildData {
}
@Override
public void addChild(ChildModel child) {
public CompletableFuture<ChildModel> addChild(ChildModel child) {
return CompletableFuture.supplyAsync(() -> {
Call<ChildResponse> call = kidShiftApiService.addChild(ChildModelConverter.childModelToChildAddRequest(child));
try {
Response<ChildResponse> response = call.execute();
if (response.isSuccessful()) {
assert response.body() != null;
logger.info("子供追加成功(childId: " + response.body().getId() + ")");
return ChildModelConverter.childResponseToChildModel(response.body());
} else {
throw new RuntimeException("HTTP Status: " + response.code());
}
} catch (Exception e) {
throw new RuntimeException(e);
}
});
}
@Override