mirror of
https://github.com/astuto/astuto.git
synced 2025-12-15 03:07:52 +01:00
Post follow and updates notifications V1 (#111)
* It is now possible to follow a post in order to receive updates about it * Notifications are now sent when updates are published * Post status changes are now tracked * Update sidebar now shows the post status history * Mark a comment as a post update using the comment form * ... more ...
This commit is contained in:
committed by
GitHub
parent
ce7be1b30c
commit
dad382d2b1
53
app/controllers/follows_controller.rb
Normal file
53
app/controllers/follows_controller.rb
Normal file
@@ -0,0 +1,53 @@
|
||||
class FollowsController < ApplicationController
|
||||
before_action :authenticate_user!, only: [:create, :destroy]
|
||||
|
||||
def index
|
||||
unless user_signed_in?
|
||||
render json: { }
|
||||
return
|
||||
end
|
||||
|
||||
follow = Follow.find_by(follow_params)
|
||||
render json: follow
|
||||
end
|
||||
|
||||
def create
|
||||
follow = Follow.new(follow_params)
|
||||
|
||||
if follow.save
|
||||
render json: {
|
||||
id: follow.id
|
||||
}, status: :created
|
||||
else
|
||||
render json: {
|
||||
error: I18n.t('errors.follows.create', message: follow.errors.full_messages)
|
||||
}, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
follow = Follow.find_by(follow_params)
|
||||
id = follow.id
|
||||
|
||||
return if follow.nil?
|
||||
|
||||
if follow.destroy
|
||||
render json: {
|
||||
id: id,
|
||||
}, status: :accepted
|
||||
else
|
||||
render json: {
|
||||
error: I18n.t('errors.follow.destroy', message: follow.errors.full_messages)
|
||||
}, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def follow_params
|
||||
{
|
||||
post_id: params[:post_id],
|
||||
user_id: current_user.id,
|
||||
}
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user