API de comptabilité horaire.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

activities_controller.rb 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. class Api::V1::ActivitiesController < ApplicationController
  2. before_action :set_activity, only: %i[show update destroy]
  3. before_action :check_login
  4. before_action :check_owner, only: %i[update destroy]
  5. def index
  6. render json: Activity.all
  7. end
  8. def show
  9. render json: Activity.find(params[:id])
  10. end
  11. def create
  12. activity = current_user.created_activities.build(activity_params)
  13. if activity.save
  14. render json: activity, status: :created
  15. else
  16. render json: { errors: activity.errors }, status: :unprocessable_entity
  17. end
  18. end
  19. def update
  20. if @activity.update(activity_params)
  21. render json: @product
  22. else
  23. render json: @product.erros, status: :unprocessable_entity
  24. end
  25. end
  26. def destroy
  27. @activity.destroy
  28. head 204
  29. end
  30. private
  31. # Only allow a trusted parameter "white list" through.
  32. def activity_params
  33. params.require(:activity).permit(:name, :author_id, :description, :client)
  34. end
  35. def set_activity
  36. @activity = Activity.find(params[:id])
  37. end
  38. def check_owner
  39. head :forbidden unless @activity.author_id == current_user&.id
  40. end
  41. end