diff --git a/app/src/main/java/com/example/nemophila/entities/Post.java b/app/src/main/java/com/example/nemophila/entities/Post.java index fc17f1d..b97d9be 100644 --- a/app/src/main/java/com/example/nemophila/entities/Post.java +++ b/app/src/main/java/com/example/nemophila/entities/Post.java @@ -1,30 +1,29 @@ package com.example.nemophila.entities; public class Post { - private String id; + private String pid; + private String uid; + private String name; private String genre; - private String image1; - private String image2; - private String image3; + private String date; private int rate; private String comment; - private Account owner; //Getter - public String getId() { - return id; + public String getPid() { + return pid; + } + public String getUid() { + return uid; + } + public String getName() { + return name; } public String getGenre() { return genre; } - public String getImage1() { - return image1; - } - public String getImage2() { - return image2; - } - public String getImage3() { - return image3; + public String getDate() { + return date; } public int getRate() { return rate; @@ -32,25 +31,22 @@ public String getComment() { return comment; } - public Account getOwner() { - return owner; - } //Setter - public void setId(String id) { - this.id = id; + public void setPid(String pid) { + this.pid = pid; + } + public void setUid(String uid) { + this.uid = uid; + } + public void setName(String name) { + this.name = name; } public void setGenre(String genre) { this.genre = genre; } - public void setImage1(String image1) { - this.image1 = image1; - } - public void setImage2(String image2) { - this.image2 = image2; - } - public void setImage3(String image3) { - this.image3 = image3; + public void setDate(String date) { + this.date = date; } public void setRate(int rate) { this.rate = rate; @@ -58,7 +54,9 @@ public void setComment(String comment) { this.comment = comment; } - public void setOwner(Account owner) { - this.owner = owner; - } + +// public Post(PostJson pj) { +// this.pid = pj.getId(); +// this.uid = pj.getOwner() +// } } diff --git a/app/src/main/java/com/example/nemophila/entities/PostJson.java b/app/src/main/java/com/example/nemophila/entities/PostJson.java index 1a3573b..69fa816 100644 --- a/app/src/main/java/com/example/nemophila/entities/PostJson.java +++ b/app/src/main/java/com/example/nemophila/entities/PostJson.java @@ -1,22 +1,64 @@ package com.example.nemophila.entities; public class PostJson { - private String uid; - private String pid; + private String id; + private String genre; + private String image1; + private String image2; + private String image3; + private int rate; + private String comment; + private Account owner; - //setter - public void setUid(String uid) { - this.uid = uid; + //Getter + public String getId() { + return id; } - public void setPid(String pid) { - this.pid = pid; + public String getGenre() { + return genre; + } + public String getImage1() { + return image1; + } + public String getImage2() { + return image2; + } + public String getImage3() { + return image3; + } + public int getRate() { + return rate; + } + public String getComment() { + return comment; + } + public Account getOwner() { + return owner; } - //getter - public String getUid() { - return uid; + //Setter + public void setId(String id) { + this.id = id; } - public String getPid() { - return pid; + public void setGenre(String genre) { + this.genre = genre; + } + public void setImage1(String image1) { + this.image1 = image1; + } + public void setImage2(String image2) { + this.image2 = image2; + } + public void setImage3(String image3) { + this.image3 = image3; + } + public void setRate(int rate) { + this.rate = rate; + } + public void setComment(String comment) { + this.comment = comment; + } + public void setOwner(Account owner) { + this.owner = owner; } } diff --git a/app/src/main/java/com/example/nemophila/resources/PostsRest.java b/app/src/main/java/com/example/nemophila/resources/PostsRest.java index da76051..1791bd4 100644 --- a/app/src/main/java/com/example/nemophila/resources/PostsRest.java +++ b/app/src/main/java/com/example/nemophila/resources/PostsRest.java @@ -34,7 +34,7 @@ ); @GET("shops/{sid}/posts") - Call> getShopPosts( + Call> getShopPosts( @Path("sid") String sid ); } 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 887769c..aa3a344 100644 --- a/app/src/main/java/com/example/nemophila/viewmodels/PostsViewModel.java +++ b/app/src/main/java/com/example/nemophila/viewmodels/PostsViewModel.java @@ -23,25 +23,12 @@ final private Retrofit retrofit; final private PostsRest postsRest; private String pid; + private ArrayList postJson; //LiveData final private MutableLiveData> accountPostsLiveData; final private MutableLiveData> shopPostsLiveData; - //テスト用のリスト - private ArrayList testPostsList; - //テスト用のメソッド - private void createSamplePost() { - Post post1 = new Post(); - Post post2 = new Post(); - - post1.setId("ID1"); - post2.setId("ID2"); - - testPostsList.add(post1); - testPostsList.add(post2); - } - //コンストラクタ public PostsViewModel() { this.accountPostsLiveData = new MutableLiveData<>(); @@ -52,8 +39,7 @@ .build(); this.postsRest = retrofit.create(PostsRest.class); this.pid = null; - this.testPostsList = new ArrayList<>(); - createSamplePost(); + this.postJson = new ArrayList<>(); } //getter @@ -105,20 +91,28 @@ return pid; } - public void getShopPostJson(String sid) { - Call> call = postsRest.getShopPosts(sid); - call.enqueue(new Callback>() { + public void getShopPosts(String sid) { + ArrayList posts = new ArrayList<>(); + getShopPostJson(sid); + for(PostJson pj: postJson) { + + } + } + + private 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()) { - shopPostsLiveData.setValue(response.body()); + postJson = response.body(); } else { //レスポンスエラー } } @Override - public void onFailure(Call> call, Throwable t) { + public void onFailure(Call> call, Throwable t) { //通信エラー } });