Download app/controllers/api/v1/reactions_controller.rb from denise-oneill-inbox-ru/Rails-8-API-Image-Processing: direct link, hf CLI and curl.
- Browser
- Download file 974 Bytes
-
https://huggingface.co/spaces/denise-oneill-inbox-ru/Rails-8-API-Image-Processing/resolve/main/app/controllers/api/v1/reactions_controller.rb
- Command line
-
hf download hf://spaces/denise-oneill-inbox-ru/Rails-8-API-Image-Processing/app/controllers/api/v1/reactions_controller.rb
-
curl -L -o reactions_controller.rb https://huggingface.co/spaces/denise-oneill-inbox-ru/Rails-8-API-Image-Processing/resolve/main/app/controllers/api/v1/reactions_controller.rb
974 Bytes
| module Api | |
| module V1 | |
| class ReactionsController < BaseController | |
| before_action :set_post | |
| def create | |
| reaction = @post.reactions.find_or_initialize_by(user: current_user) | |
| reaction.kind = params[:kind] || "like" | |
| authorize reaction | |
| if reaction.save | |
| render json: { message: "Reaction added", kind: reaction.kind }, status: :created | |
| else | |
| render json: { errors: reaction.errors.full_messages }, status: :unprocessable_entity | |
| end | |
| end | |
| def destroy | |
| reaction = @post.reactions.find_by(user: current_user) | |
| if reaction | |
| authorize reaction | |
| reaction.destroy | |
| render json: { message: "Reaction removed" }, status: :ok | |
| else | |
| render json: { error: "Reaction not found" }, status: :not_found | |
| end | |
| end | |
| private | |
| def set_post | |
| @post = Post.friendly.find(params[:post_slug]) | |
| end | |
| end | |
| end | |
| end | |