From aa0e1ac1c7de02b746f85672668902a3df25823b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Victor=20Geonizeli?= Date: Mon, 28 Feb 2022 12:40:17 -0300 Subject: [PATCH] change json contract --- app/views/posts/_post.json.jbuilder | 6 +++--- app/views/posts/_quoted_post.json.jbuilder | 2 ++ app/views/posts/_user.json.jbuilder | 3 +++ app/views/users/_user.json.jbuilder | 7 ++++++- 4 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 app/views/posts/_quoted_post.json.jbuilder create mode 100644 app/views/posts/_user.json.jbuilder diff --git a/app/views/posts/_post.json.jbuilder b/app/views/posts/_post.json.jbuilder index 47cac0d..b65d3f2 100644 --- a/app/views/posts/_post.json.jbuilder +++ b/app/views/posts/_post.json.jbuilder @@ -1,6 +1,6 @@ -json.extract! post, :id, :content, :created_at, :updated_at +json.extract! post, :id, :content, :created_at -json.quoted_post(post.quoted_post, partial: 'posts/post', as: :post) if post.quoted_post -json.user(post.user, partial: 'users/user', as: :user) if post.user +json.quoted_post(post.quoted_post, partial: 'posts/quoted_post', as: :post) if post.quoted_post +json.user(post.user, partial: 'posts/user', as: :user) json.url post_url(post, format: :json) \ No newline at end of file diff --git a/app/views/posts/_quoted_post.json.jbuilder b/app/views/posts/_quoted_post.json.jbuilder new file mode 100644 index 0000000..1c3accc --- /dev/null +++ b/app/views/posts/_quoted_post.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! post, :id, :content, :created_at +json.user(post.user, partial: 'posts/user', as: :user) diff --git a/app/views/posts/_user.json.jbuilder b/app/views/posts/_user.json.jbuilder new file mode 100644 index 0000000..ab6af84 --- /dev/null +++ b/app/views/posts/_user.json.jbuilder @@ -0,0 +1,3 @@ +json.extract! user, :id, :username + +json.url user_url(user, format: :json) diff --git a/app/views/users/_user.json.jbuilder b/app/views/users/_user.json.jbuilder index c88f34b..96813bf 100644 --- a/app/views/users/_user.json.jbuilder +++ b/app/views/users/_user.json.jbuilder @@ -1,2 +1,7 @@ -json.extract! user, :id, :username, :created_at, :updated_at +json.extract! user, :id, :username +json.joined_at user.created_at.strftime("%B %d, %Y") +json.following_count user.following.count +json.follower_count user.followers.count +json.posts_count user.posts.count + json.url user_url(user, format: :json)