API de comptabilité horaire.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

activities_controller.rb 1.1KB

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