2019-12-11 12:04:02 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class BookmarksController < ApplicationController
|
|
|
|
requires_login
|
|
|
|
|
|
|
|
def create
|
|
|
|
params.require(:post_id)
|
|
|
|
|
2020-03-12 08:16:00 +08:00
|
|
|
bookmark_manager = BookmarkManager.new(current_user)
|
|
|
|
bookmark = bookmark_manager.create(
|
2019-12-11 12:04:02 +08:00
|
|
|
post_id: params[:post_id],
|
|
|
|
name: params[:name],
|
2020-03-12 08:16:00 +08:00
|
|
|
reminder_type: params[:reminder_type],
|
2020-05-07 11:37:39 +08:00
|
|
|
reminder_at: params[:reminder_at],
|
|
|
|
options: {
|
|
|
|
delete_when_reminder_sent: params[:delete_when_reminder_sent]
|
|
|
|
}
|
2019-12-11 12:04:02 +08:00
|
|
|
)
|
|
|
|
|
2020-03-12 08:16:00 +08:00
|
|
|
if bookmark_manager.errors.empty?
|
2020-04-20 11:30:04 +08:00
|
|
|
return render json: success_json.merge(id: bookmark.id)
|
2020-03-12 08:16:00 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
render json: failed_json.merge(errors: bookmark_manager.errors.full_messages), status: 400
|
2019-12-11 12:04:02 +08:00
|
|
|
end
|
2020-02-13 14:26:02 +08:00
|
|
|
|
|
|
|
def destroy
|
|
|
|
params.require(:id)
|
2020-04-20 11:30:04 +08:00
|
|
|
result = BookmarkManager.new(current_user).destroy(params[:id])
|
|
|
|
render json: success_json.merge(result)
|
2020-02-13 14:26:02 +08:00
|
|
|
end
|
2020-04-17 09:08:07 +08:00
|
|
|
|
|
|
|
def update
|
|
|
|
params.require(:id)
|
|
|
|
|
|
|
|
bookmark_manager = BookmarkManager.new(current_user)
|
|
|
|
bookmark_manager.update(
|
|
|
|
bookmark_id: params[:id],
|
|
|
|
name: params[:name],
|
|
|
|
reminder_type: params[:reminder_type],
|
2020-05-07 11:37:39 +08:00
|
|
|
reminder_at: params[:reminder_at],
|
|
|
|
options: {
|
|
|
|
delete_when_reminder_sent: params[:delete_when_reminder_sent]
|
|
|
|
}
|
2020-04-17 09:08:07 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
if bookmark_manager.errors.empty?
|
|
|
|
return render json: success_json
|
|
|
|
end
|
|
|
|
|
|
|
|
render json: failed_json.merge(errors: bookmark_manager.errors.full_messages), status: 400
|
|
|
|
end
|
2019-12-11 12:04:02 +08:00
|
|
|
end
|