diff --git a/app/src/main/java/com/example/nemophila/viewmodels/PostsViewModel.java b/app/src/main/java/com/example/nemophila/viewmodels/PostsViewModel.java index ba38203..dd8e411 100644 --- a/app/src/main/java/com/example/nemophila/viewmodels/PostsViewModel.java +++ b/app/src/main/java/com/example/nemophila/viewmodels/PostsViewModel.java @@ -22,7 +22,6 @@ //Field final private Retrofit retrofit; final private PostsRest postsRest; - private String pid; //LiveData final private MutableLiveData> accountPostsLiveData; @@ -37,7 +36,6 @@ .addConverterFactory(JacksonConverterFactory.create()) .build(); this.postsRest = retrofit.create(PostsRest.class); - this.pid = null; } //getter @@ -48,7 +46,8 @@ return this.shopPostsLiveData; } - //API通信メソッド + + //AccountのpostJsonを取得 public void getAccountPosts(String uid) { Call> call = postsRest.getAccountPosts(uid); call.enqueue(new Callback>() { @@ -57,13 +56,13 @@ if (response.isSuccessful()) { setAccountPostLiveData(response.body()); } else { - //レスポンスエラーを通知 + System.out.println("AccountPosts ResponseError"); } } @Override public void onFailure(Call> call, Throwable t) { - //通信エラーを通知 + System.out.println("AccountPosts NetWorkError: " + t); } }); } @@ -78,30 +77,28 @@ accountPostsLiveData.setValue(posts); } - //投稿作成 - public String createPost(String uid, String token, String sid, - String rate, String genre, String comment, - String image1, String image2, String image3) { - Call call = postsRest.postAccountPost(uid ,token, sid, rate, genre, comment, image1, image2, image3); - - call.enqueue(new Callback() { + //ShopのPostJsonを取得 + public void getShopPostJson(String sid) { + Call> call = postsRest.getShopPosts(sid); + call.enqueue(new Callback>() { @Override - public void onResponse(Call call, Response response) { + public void onResponse(Call> call, Response> response) { if (response.isSuccessful()) { - pid = response.body(); + ArrayList postJson = response.body(); + setShopPostLiveData(postJson); } else { - //レスポンスエラーを通知 + System.out.println("ShopPosts ResponseError"); } } @Override - public void onFailure(Call call, Throwable t) { - //通信エラーを通知 + public void onFailure(Call> call, Throwable t) { + System.out.println("ShopPosts NetWorkError: " + t); + System.out.println(t); + //通信エラー } }); - return pid; } - //PostJsonからPostを作成し,それをLiveDataにセット private void setShopPostLiveData(ArrayList postJson) { ArrayList posts = new ArrayList<>(); @@ -112,25 +109,25 @@ shopPostsLiveData.setValue(posts); } - //PostJsonを取得 - public void getShopPostJson(String sid) { - Call> call = postsRest.getShopPosts(sid); - call.enqueue(new Callback>() { + //投稿作成 + public void createPost(String uid, String token, String sid, + String rate, String genre, String comment, + String image1, String image2, String image3) { + Call call = postsRest.postAccountPost(uid ,token, sid, rate, genre, comment, image1, image2, image3); + + call.enqueue(new Callback() { @Override - public void onResponse(Call> call, Response> response) { + public void onResponse(Call call, Response response) { if (response.isSuccessful()) { - ArrayList postJson = response.body(); - setShopPostLiveData(postJson); + System.out.println("Success CreatePost" + response.body()); } else { - //レスポンスエラー + System.out.println("CreatePosts ResponseError"); } } @Override - public void onFailure(Call> call, Throwable t) { - System.out.println("networkError"); - System.out.println(t); - //通信エラー + public void onFailure(Call call, Throwable t) { + System.out.println("CreatePosts NetWorkError: " + t); } }); }