Merge pull request 'モデル修正' (#101) from feature/model_fix into main
Reviewed-on: #101
This commit is contained in:
commit
54dcac0931
|
@ -9,6 +9,7 @@ import javax.inject.Inject;
|
|||
import one.nem.kidshift.data.ChildData;
|
||||
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.model.ChildModel;
|
||||
import one.nem.kidshift.utils.KSLogger;
|
||||
import retrofit2.Call;
|
||||
|
@ -41,13 +42,8 @@ public class ChildDataImpl implements ChildData {
|
|||
|
||||
ChildListResponse body = response.body();
|
||||
if (body == null) return null;
|
||||
return body.getList().stream().map(child -> {
|
||||
ChildModel model = new ChildModel();
|
||||
model.setDisplayName(child.getName().isEmpty() ? child.getId() : child.getName());
|
||||
model.setInternalId(child.getId());
|
||||
// 他のプロパティも処理する
|
||||
return model;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
return ChildModelConverter.childListResponseToChildModelList(body);
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage());
|
||||
return null;
|
||||
|
|
|
@ -7,6 +7,7 @@ import javax.inject.Inject;
|
|||
import one.nem.kidshift.data.KSActions;
|
||||
import one.nem.kidshift.data.UserSettings;
|
||||
import one.nem.kidshift.data.retrofit.KidShiftApiService;
|
||||
import one.nem.kidshift.data.retrofit.model.converter.ParentModelConverter;
|
||||
import one.nem.kidshift.data.retrofit.model.parent.ParentInfoResponse;
|
||||
import one.nem.kidshift.data.retrofit.model.task.TaskListResponse;
|
||||
import one.nem.kidshift.model.ParentModel;
|
||||
|
@ -58,7 +59,7 @@ public class KSActionsImpl implements KSActions {
|
|||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<ParentModel> syncParent() {
|
||||
public CompletableFuture<ParentModel> syncParent() { // TODO-rca: null対処, キャッシュ対応
|
||||
logger.info("syncParent called and started");
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
logger.info("fetching...");
|
||||
|
@ -70,13 +71,7 @@ public class KSActionsImpl implements KSActions {
|
|||
throw new RuntimeException("Error fetching parent info: " + response.errorBody().string());
|
||||
}
|
||||
ParentInfoResponse responseBody = response.body();
|
||||
ParentModel parent = new ParentModel();
|
||||
// TODO: 詰め替えをどこかにまとめる, 他のプロパティも処理する
|
||||
parent.setInternalId(responseBody.getId());
|
||||
parent.setEmail(responseBody.getEmail());
|
||||
parent.setDisplayName(responseBody.getEmail()); // Workaround
|
||||
logger.info("Parent fetched with status: " + response.code());
|
||||
logger.debug("Parent: " + parent);
|
||||
ParentModel parent = ParentModelConverter.parentInfoResponseToParentModel(responseBody);
|
||||
// Save to cache
|
||||
userSettings.getCache().setParent(parent);
|
||||
logger.info("Parent saved to cache");
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package one.nem.kidshift.data.retrofit.model.converter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import one.nem.kidshift.data.retrofit.model.child.ChildAddRequest;
|
||||
import one.nem.kidshift.data.retrofit.model.child.ChildListResponse;
|
||||
import one.nem.kidshift.data.retrofit.model.child.ChildResponse;
|
||||
import one.nem.kidshift.model.ChildModel;
|
||||
|
||||
public class ChildModelConverter {
|
||||
|
||||
public static ChildAddRequest childModelToChildAddRequest(ChildModel childModel) {
|
||||
ChildAddRequest request = new ChildAddRequest();
|
||||
request.setName(childModel.getName());
|
||||
return request;
|
||||
}
|
||||
|
||||
public static List<ChildModel> childListResponseToChildModelList(ChildListResponse childListResponse) {
|
||||
return childListResponse.getList().stream().map(ChildModelConverter::childResponseToChildModel).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static ChildModel childResponseToChildModel(ChildResponse childResponse) {
|
||||
return new ChildModel(childResponse.getId(), childResponse.getName());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package one.nem.kidshift.data.retrofit.model.converter;
|
||||
|
||||
import one.nem.kidshift.data.retrofit.model.parent.ParentInfoResponse;
|
||||
import one.nem.kidshift.model.ParentModel;
|
||||
|
||||
public class ParentModelConverter {
|
||||
|
||||
public static ParentModel parentInfoResponseToParentModel(ParentInfoResponse parentInfoResponse) {
|
||||
return new ParentModel(parentInfoResponse.getId(), parentInfoResponse.getDisplayName(), parentInfoResponse.getEmail());
|
||||
}
|
||||
|
||||
public static ParentInfoResponse parentModelToParentInfoResponse(ParentModel parentModel) {
|
||||
return new ParentInfoResponse(parentModel.getId(), parentModel.getName(), parentModel.getEmail());
|
||||
}
|
||||
|
||||
}
|
|
@ -41,7 +41,7 @@ public class ChildListAdapter extends RecyclerView.Adapter<ChildListAdapter.Main
|
|||
|
||||
public void onBindViewHolder(@NonNull MainViewHolder holder,int position){
|
||||
ChildModel childData = this.childDataList.get(position);
|
||||
holder.childname.setText(childData.getDisplayName());
|
||||
holder.childname.setText(childData.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -42,7 +42,7 @@ public class SettingAdapter extends RecyclerView.Adapter<SettingAdapter.MainView
|
|||
@Override
|
||||
public void onBindViewHolder(@NonNull MainViewHolder holder, int position){
|
||||
ChildModel childData = this.childDataList.get(position);
|
||||
holder.childname.setText(childData.getDisplayName());
|
||||
holder.childname.setText(childData.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -120,7 +120,7 @@ public class SettingMainFragment extends Fragment {
|
|||
|
||||
if (parent == null) {
|
||||
parent = new ParentModel(); // Workaround(非ログインデバッグ用)
|
||||
parent.setDisplayName("親の名前");
|
||||
parent.setName("親の名前");
|
||||
parent.setEmail("親のアドレス");
|
||||
}
|
||||
|
||||
|
@ -137,7 +137,7 @@ public class SettingMainFragment extends Fragment {
|
|||
TextView username = view.findViewById(R.id.username);
|
||||
TextView useradress = view.findViewById(R.id.useradress);
|
||||
|
||||
username.setText(finalParent.getDisplayName());
|
||||
username.setText(finalParent.getName());
|
||||
useradress.setText(finalParent.getEmail());
|
||||
|
||||
RecyclerView recyclerView = view.findViewById(R.id.childrecyclerview);
|
||||
|
@ -160,7 +160,7 @@ public class SettingMainFragment extends Fragment {
|
|||
TextView username = view.findViewById(R.id.username);
|
||||
TextView useradress = view.findViewById(R.id.useradress);
|
||||
|
||||
username.setText(parent.getDisplayName());
|
||||
username.setText(parent.getName());
|
||||
useradress.setText(parent.getEmail());
|
||||
|
||||
RecyclerView recyclerView = view.findViewById(R.id.childrecyclerview);
|
||||
|
|
|
@ -1,50 +1,18 @@
|
|||
package one.nem.kidshift.model;
|
||||
|
||||
// TODO: parent, childを共通クラスから継承させる
|
||||
public class ChildModel {
|
||||
String internalId;
|
||||
String displayName;
|
||||
String homeGroupId;
|
||||
public class ChildModel extends UserBaseModel {
|
||||
|
||||
public ChildModel(String internalId, String displayName, String homeGroupId) {
|
||||
this.internalId = internalId;
|
||||
this.displayName = displayName;
|
||||
this.homeGroupId = homeGroupId;
|
||||
// Additional fields
|
||||
|
||||
public ChildModel(String id, String name) {
|
||||
super(id, name);
|
||||
}
|
||||
|
||||
public ChildModel(String internalId, String displayName) {
|
||||
this.internalId = internalId;
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
public ChildModel(String internalId) {
|
||||
this.internalId = internalId;
|
||||
public ChildModel(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public ChildModel() {
|
||||
}
|
||||
|
||||
public String getInternalId() {
|
||||
return internalId;
|
||||
}
|
||||
|
||||
public void setInternalId(String internalId) {
|
||||
this.internalId = internalId;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
public void setDisplayName(String displayName) {
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
public String getHomeGroupId() {
|
||||
return homeGroupId;
|
||||
}
|
||||
|
||||
public void setHomeGroupId(String homeGroupId) {
|
||||
this.homeGroupId = homeGroupId;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,65 +1,33 @@
|
|||
package one.nem.kidshift.model;
|
||||
|
||||
// TODO: parent, childを共通クラスから継承させる
|
||||
public class ParentModel {
|
||||
String internalId;
|
||||
String displayName;
|
||||
String homeGroupId;
|
||||
String email;
|
||||
public class ParentModel extends UserBaseModel {
|
||||
|
||||
public ParentModel(String internalId, String displayName, String homeGroupId, String email) {
|
||||
this.internalId = internalId;
|
||||
this.displayName = displayName;
|
||||
this.homeGroupId = homeGroupId;
|
||||
|
||||
private String email;
|
||||
|
||||
public ParentModel(String id, String name, String email) {
|
||||
super(id, name);
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public ParentModel(String internalId, String displayName, String homeGroupId) {
|
||||
this.internalId = internalId;
|
||||
this.displayName = displayName;
|
||||
this.homeGroupId = homeGroupId;
|
||||
private ParentModel(UserBaseModel userBaseModel, String email) {
|
||||
super(userBaseModel.getId().isEmpty() ? null : userBaseModel.getId(), userBaseModel.getName());
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public ParentModel(String internalId, String displayName) {
|
||||
this.internalId = internalId;
|
||||
this.displayName = displayName;
|
||||
public ParentModel(String name, String email) {
|
||||
super(name);
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public ParentModel() {
|
||||
}
|
||||
|
||||
// Getter
|
||||
|
||||
public String getInternalId() {
|
||||
return internalId;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
public String getHomeGroupId() {
|
||||
return homeGroupId;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
// Setter
|
||||
|
||||
public void setInternalId(String internalId) {
|
||||
this.internalId = internalId;
|
||||
}
|
||||
|
||||
public void setDisplayName(String displayName) {
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
public void setHomeGroupId(String homeGroupId) {
|
||||
this.homeGroupId = homeGroupId;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package one.nem.kidshift.model;
|
||||
|
||||
public class UserBaseModel {
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
|
||||
public UserBaseModel(String id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public UserBaseModel(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public UserBaseModel() {
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user