class Api::V4::FeedItemsController < Api::V4::ApplicationController
  before_action :set_user, only: %i[index]
  before_action :validate_user, only: %i[index]

  def index
    runs_by_twitch_follows = Run.includes(:game, :category, :user).where(
      users: { twitch: current_user.twitch.follows },
    ).where.not(
      games: { name: [nil, ""] },
    ).order("runs.created_at DESC").limit(6)

    render json: Api::V4::FeedItemBlueprint.render(
      runs_by_twitch_follows.map do |run|
        {
          type: :run,
          run: run,
        }
      end
    )
  end
end

class Api::V4::FeedItemsController < Api::V4::ApplicationController
  before_action :set_user, only: %i[index]
  before_action :set_feed_items
  before_action :validate_user, only: %i[index]

  def index
    render json: Api::V4::FeedItemBlueprint.render(@feed_items, root: :feed_items)
  end

  private

  def set_feed_items
    @feed_items = Run.includes(:game, :category, :user).where(
      users: { twitch: current_user.twitch.follows },
    ).where.not(
      games: { name: [nil, ""] },
    ).order("runs.created_at DESC").limit(6).map { |run| { type: :run, run: run } }
  end
end

Make feed items have a root element
Make feed items have a root element
