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.

memberships_controller.rb 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. class Api::V1::MembershipsController < ApplicationController
  2. before_action :set_memberships, only: %i[show update destroy]
  3. before_action :check_login
  4. def index
  5. render json: MembershipSerializer.new(Membership.all).serializable_hash.to_json
  6. end
  7. def show
  8. render json: MembershipSerializer.new(@membership).serializable_hash.to_json
  9. end
  10. def create
  11. member_id = User.where(username: params[:membership][:username])[0].id
  12. team_id = Team.where(name: params[:membership][:team_name])[0].id
  13. membership = Membership.new(team_id: team_id, member_id: member_id, can_edit: false)
  14. if membership.save
  15. render json: MembershipSerializer.new(membership).serializable_hash.to_json, status: :created
  16. else
  17. render json: membership.errors, status: :unprocessable_entity
  18. end
  19. end
  20. def update
  21. if @membership.update(memberships_params)
  22. render json: MembershipSerializer.new(@membership).serializable_hash.to_json, status: :ok
  23. else
  24. render json: @membership.errors, status: :unprocessable_entity
  25. end
  26. end
  27. def destroy
  28. @membership.destroy
  29. head 204
  30. end
  31. private
  32. def memberships_params
  33. params.require(:membership).permit(:can_edit)
  34. end
  35. def set_memberships
  36. @membership = Membership.find(params[:id])
  37. end
  38. end