型修正, APIリクエスト実装
This commit is contained in:
parent
bef159028d
commit
b625918138
|
@ -31,7 +31,7 @@ public interface ChildData {
|
||||||
* 子ユーザー追加
|
* 子ユーザー追加
|
||||||
* @param child 子ユーザー情報
|
* @param child 子ユーザー情報
|
||||||
*/
|
*/
|
||||||
void addChild(ChildModel child);
|
CompletableFuture<ChildModel> addChild(ChildModel child);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 子ユーザー削除
|
* 子ユーザー削除
|
||||||
|
|
|
@ -10,6 +10,8 @@ import one.nem.kidshift.data.ChildData;
|
||||||
import one.nem.kidshift.data.KSActions;
|
import one.nem.kidshift.data.KSActions;
|
||||||
import one.nem.kidshift.data.retrofit.KidShiftApiService;
|
import one.nem.kidshift.data.retrofit.KidShiftApiService;
|
||||||
import one.nem.kidshift.data.retrofit.model.child.ChildLoginCodeResponse;
|
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.data.room.utils.CacheWrapper;
|
||||||
import one.nem.kidshift.model.ChildModel;
|
import one.nem.kidshift.model.ChildModel;
|
||||||
import one.nem.kidshift.model.callback.ChildModelCallback;
|
import one.nem.kidshift.model.callback.ChildModelCallback;
|
||||||
|
@ -92,8 +94,22 @@ public class ChildDataImpl implements ChildData {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue
Block a user