|
|
@@ -38,7 +38,7 @@ class PostsController < ApplicationController |
|
|
|
viewed = current_user&.viewed?(post) || false |
|
|
|
|
|
|
|
render json: (post |
|
|
|
.as_json(include: { tags: { only: [:id, :name, :category] } }) |
|
|
|
.as_json(include: { tags: { only: [:id, :name, :category, :post_count] } }) |
|
|
|
.merge(viewed: viewed)) |
|
|
|
end |
|
|
|
|
|
|
@@ -50,7 +50,7 @@ class PostsController < ApplicationController |
|
|
|
viewed = current_user&.viewed?(post) || false |
|
|
|
|
|
|
|
render json: (post |
|
|
|
.as_json(include: { tags: { only: [:id, :name, :category] } }) |
|
|
|
.as_json(include: { tags: { only: [:id, :name, :category, :post_count] } }) |
|
|
|
.merge(viewed: viewed)) |
|
|
|
end |
|
|
|
|
|
|
@@ -72,7 +72,7 @@ class PostsController < ApplicationController |
|
|
|
if post.save |
|
|
|
post.resized_thumbnail! |
|
|
|
post.tags = Tag.normalise_tags(tags_names) |
|
|
|
render json: post.as_json(include: { tags: { only: [:id, :name, :category] } }), |
|
|
|
render json: post.as_json(include: { tags: { only: [:id, :name, :category, :post_count] } }), |
|
|
|
status: :created |
|
|
|
else |
|
|
|
render json: { errors: post.errors.full_messages }, status: :unprocessable_entity |
|
|
@@ -104,7 +104,7 @@ class PostsController < ApplicationController |
|
|
|
post = Post.find(params[:id].to_i) |
|
|
|
tags = post.tags.where(category: 'nico').to_a + Tag.normalise_tags(tag_names) |
|
|
|
if post.update(title:, tags:) |
|
|
|
render json: post.as_json(include: { tags: { only: [:id, :name, :category] } }), |
|
|
|
render json: post.as_json(include: { tags: { only: [:id, :name, :category, :post_count] } }), |
|
|
|
status: :ok |
|
|
|
else |
|
|
|
render json: post.errors, status: :unprocessable_entity |
|
|
|