/
tofflin
/
music_project
Обзор
Документация
Войти
/
tofflin
/
music_project
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
app/controllers/subscriptions_controller.rb
46 строк
1 KB
tofflin
пофиксила баги в контроллерах, добавила users_controller.rb
10 июн 2025, 18:51
10 июн 2025, 18:51
cb0e7fb
Код
Авторство
О чём код?
class SubscriptionsController < ApplicationController include UserSetup before_action :authenticate_user! before_action :set_user, only: [:subscribe, :unsubscribe, :check_subscription] include Rails.application.routes.url_helpers def subscribe return render json: { error: "Cannot subscribe to yourself" }, status: :unprocessable_entity if current_user == @user if current_user.subscribe(@user) render json: { message: "Successfully subscribed", subscribed: true, subscribers_count: @user.reload.subscribers_count }, status: :ok else render json: { error: current_user.errors.full_messages.join(", ") || "Unable to subscribe" }, status: :unprocessable_entity end end def unsubscribe return render json: { error: "Cannot unsubscribe from yourself" }, status: :unprocessable_entity if current_user == @user if current_user.unsubscribe(@user) render json: { message: "Successfully unsubscribed", subscribed: false, subscribers_count: @user.reload.subscribers_count }, status: :ok else render json: { error: current_user.errors.full_messages.join(", ") || "Unable to unsubscribe" }, status: :unprocessable_entity end end def check_subscription render json: { subscribed: current_user.subscribed?(@user) }, status: :ok end end