mirror of
https://github.com/wahyd4/libr-2.git
synced 2026-08-09 05:15:53 +10:00
Add bookmarked posts to post controller
This commit is contained in:
@@ -41,6 +41,11 @@ class Api::V1::PostsController < Api::V1::ApplicationController
|
||||
render json: Post.where(id: ids).page(params[:page]), each_serializer: EachPostSerializer
|
||||
end
|
||||
|
||||
def bookmarked_posts
|
||||
ids = Favorite.where(user_id: @current_user.id).order(:created_at).pluck(:favoritable_id)
|
||||
render json: Post.where(id: ids).page(params[:page]), each_serializer: EachPostSerializer
|
||||
end
|
||||
|
||||
def search
|
||||
params.permit(:keywords)
|
||||
render json: Post.where('title LIKE ?',"%#{params[:keywords]}%").page(params[:page]), each_serializer: EachPostSerializer
|
||||
|
||||
@@ -86,6 +86,7 @@ Rails.application.routes.draw do
|
||||
end
|
||||
|
||||
get '/posts/liked', to: 'posts#liked_posts'
|
||||
get '/posts/bookmarked', to: 'posts#bookmarked_posts'
|
||||
get '/posts/search', to: 'posts#search'
|
||||
|
||||
resources :posts, only: [:create, :index, :show] do
|
||||
|
||||
Reference in New Issue
Block a user