diff --git a/app/controllers/api/v0/comments_controller.rb b/app/controllers/api/v0/comments_controller.rb index 7bb7bf6d0..cd84f0e79 100644 --- a/app/controllers/api/v0/comments_controller.rb +++ b/app/controllers/api/v0/comments_controller.rb @@ -3,7 +3,7 @@ module Api module V0 class CommentsController < Api::V0::BaseController - before_action only: %i[reate destroy] do + before_action only: %i[create destroy] do require_access_token %w[read write] end @@ -16,18 +16,22 @@ module Api end def create - @comment = CommentService.new(post_id: params[:post_id], text: params[:text], user: current_user).create_comment + @comment = comment_service.create(params[:post_id], params[:text]) render json: CommentPresenter.new(@comment), status: 201 end def destroy - service = CommentService.new(comment_id: params[:id], user: current_user) - if service.destroy_comment - render json: I18n.t("comments.destroy.success", id: params[:id]), status: 200 + if comment_service.destroy(params[:id]) + head :no_content else render json: I18n.t("comments.destroy.fail"), status: 403 end end + + def comment_service + @comment_service ||= CommentService.new(current_user) + end + end end end diff --git a/app/controllers/api/v0/likes_controller.rb b/app/controllers/api/v0/likes_controller.rb index 555e84854..cb846d4b7 100644 --- a/app/controllers/api/v0/likes_controller.rb +++ b/app/controllers/api/v0/likes_controller.rb @@ -27,7 +27,7 @@ module Api def destroy @like = Like.find_by!(id: params[:id], author_id: current_user.person.id) current_user.retract(@like) - render nothing: true, status: 204 + head :no_content, status: 204 end private diff --git a/app/controllers/api/v0/messages_controller.rb b/app/controllers/api/v0/messages_controller.rb index 549278192..46070a775 100644 --- a/app/controllers/api/v0/messages_controller.rb +++ b/app/controllers/api/v0/messages_controller.rb @@ -26,7 +26,7 @@ module Api def index conversation = conversation_service.find!(params[:conversation_id]) - conversation.set_read(user) + conversation.set_read(current_user) render json: conversation.messages.map {|x| message_json(x) }, status: 201 end diff --git a/app/controllers/api/v0/posts_controller.rb b/app/controllers/api/v0/posts_controller.rb index 6393e0e4f..a33456afa 100644 --- a/app/controllers/api/v0/posts_controller.rb +++ b/app/controllers/api/v0/posts_controller.rb @@ -20,7 +20,7 @@ module Api end def create - @status_message = StatusMessageCreationService.new(params, current_user).status_message + @status_message = StatusMessageCreationService.new(current_user).create(normalized_params) render json: PostPresenter.new(@status_message, current_user) end @@ -29,6 +29,31 @@ module Api post_service.retract_post render nothing: true, status: 204 end + + def normalized_params + params.permit( + :location_address, + :location_coords, + :poll_question, + status_message: %i[text provider_display_name], + poll_answers: [] + ).to_h.merge( + services: [*params[:services]].compact, + aspect_ids: normalize_aspect_ids, + public: [*params[:aspect_ids]].first == "public", + photos: [*params[:photos]].compact + ) + end + + def normalize_aspect_ids + aspect_ids = [*params[:aspect_ids]] + if aspect_ids.first == "all_aspects" + current_user.aspect_ids + else + aspect_ids + end + end + end end end