Sha256: 5b9962a921988664ac971a19b7e0548664f7671c862358cb912a4ac9914a9c39

Contents?: true

Size: 1.54 KB

Versions: 11

Compression:

Stored size: 1.54 KB

Contents

require_dependency "social_networking/application_controller"

module SocialNetworking
  # Manage Participants.
  class ProfilesController < ApplicationController
    rescue_from ActiveRecord::RecordNotFound, with: :record_not_found

    def index
      group_participants = current_participant.active_group.active_participants
      render json: Serializers::ProfileSerializer.from_collection(Profile
        .where(participant_id: group_participants.pluck(:id)))
    end

    def show
      if params[:id]
        profile = Profile.find(params[:id])
      else
        profile = Profile
                  .find_or_initialize_by(
                    participant_id: current_participant.id) do |profile_new|
          begin
            SharedItem.create(
              item: profile_new,
              action_type: Profile::Actions.created)
          rescue ActiveRecord::StatementInvalid
            logger.info("Shared item already created for existing profile.")
          end
        end
      end

      render json: Serializers::ProfileSerializer.new(profile).to_serialized
    end

    def update
      profile = current_participant.social_networking_profile
      if profile.update(profile_params)
        render json: Serializers::ProfileSerializer.new(profile).to_serialized
      else
        render json: { error: profile.errors.full_messages }, status: 400
      end
    end

    private

    def profile_params
      params.permit(:icon_name)
    end

    def record_not_found
      render json: { error: "profile not found" }, status: 404
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
social_networking-0.11.8 app/controllers/social_networking/profiles_controller.rb
social_networking-0.11.7 app/controllers/social_networking/profiles_controller.rb
social_networking-0.11.6 app/controllers/social_networking/profiles_controller.rb
social_networking-0.11.5 app/controllers/social_networking/profiles_controller.rb
social_networking-0.11.4 app/controllers/social_networking/profiles_controller.rb
social_networking-0.11.3 app/controllers/social_networking/profiles_controller.rb
social_networking-0.11.2 app/controllers/social_networking/profiles_controller.rb
social_networking-0.11.1 app/controllers/social_networking/profiles_controller.rb
social_networking-0.11.0 app/controllers/social_networking/profiles_controller.rb
social_networking-0.10.0 app/controllers/social_networking/profiles_controller.rb
social_networking-0.9.3 app/controllers/social_networking/profiles_controller.rb