class PostsController < ApplicationController
  before_action :authenticate_user!
  
  def index
    # posts = Post.order(created_at: :desc)
    render json: { status: 'SUCCESS', message: 'Loaded posts', data: {test: :index, user: current_user} }
  end
  
  def show
    render json: { status: 'SUCCESS', message: 'Loaded the post', data: {test: :show} }
  end
  
  def create
    # post = Post.new(post_params)
    # if post.save
    #   render json: { status: 'SUCCESS', data: post }
    # else
    #   render json: { status: 'ERROR', data: post.errors }
    # end
    render json: { status: 'SUCCESS', data: {test: :create} }
  end
  
  def destroy
    # @post.destroy
    render json: { status: 'SUCCESS', message: 'Deleted the post', data: {test: :destory} }
  end
  
  def update
    # if @post.update(post_params)
    #   render json: { status: 'SUCCESS', message: 'Updated the post', data: @post }
    # else
    #   render json: { status: 'SUCCESS', message: 'Not updated', data: @post.errors }
    # end
    render json: { status: 'SUCCESS', message: 'Not updated', data: {test: :update} }
  end
  
  private
  
  # def set_post
  #   @post = Post.find(params[:id])
  # end
  
  # def post_params
  #   params.require(:post).permit(:title)
  # end
end
