Sha256: 77d4bd40c61fc9ed70fbbd4d96b86cfb59c934fd595e67a602dedae6dd58d276

Contents?: true

Size: 1.4 KB

Versions: 4

Compression:

Stored size: 1.4 KB

Contents

module Unsakini
  class CommentsController < BaseController

    include LoggedInControllerConcern
    include PostOwnerControllerConcern
    include CommentOwnerControllerConcern
    include ::ActionController::Serialization

    before_action :ensure_post, only: [:index, :create]
    before_action :ensure_comment, only: [:show, :update, :destroy]
    before_action :ensure_comment_owner, only: [:update, :destroy]

    # Renders the comments belonging to the post
    #
    # `GET /api/boards/:board_id/posts/:post_id/`
    def index
      paginate json: @post.comments.page(params[:page]), per_page: 20
    end

    # Creates new comment belonging to the post
    #
    # `POST /api/boards/:board_id/posts/:post_id/`
    def create
      @comment = Comment.new(params.permit(:content))
      @comment.user = @user
      @comment.post = @post
      if @comment.save
        render json: @comment
      else
        render json: @comment.errors, status: 422
      end
    end

    # Updates a comment
    #
    # `PUT /api/boards/:board_id/posts/:post_id/comments/:id`
    def update
      if @comment.update(params.permit(:content))
        render json: @comment
      else
        render json: @comment.errors, status: 422
      end
    end

    # Deletes a comment
    #
    # `DELETE /api/boards/:board_id/posts/:post_id/comments/:id`
    def destroy
      @comment.destroy
      render json: {}, status: :ok
    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
unsakini-0.0.5 app/controllers/unsakini/comments_controller.rb
unsakini-0.0.5.pre.1 app/controllers/unsakini/comments_controller.rb
unsakini-0.0.4.pre.1 app/controllers/unsakini/comments_controller.rb
unsakini-0.0.4.3 app/controllers/unsakini/comments_controller.rb