0

I'm working on a rapid react js on rails prototype for a possible gig. I have finished the react UI portion and working on backend. The prototype monitors over 500 blogs and creates "lumps" which are just preview of articles. Sources are different types of blogs, and there are over 100 of those sources. When click on Sources, it pulls up all the "lumps" and displays them.

I'm having issue as returning all the "lumps" includes and just want all the new ones for the day. Currently, most sources have 500 to 1000 lumps, just want to limit the amount to the current day. I just have not found the proper code or query that will allow me to limit the results.

Using Rails6, fastjson_api and Ruby 3.02

**Source Controller**
module Api
    module V1
        class SourcesController < ApplicationController

        def show
            source = Source.find(params[:id])
            render json: SourceSerializer.new(source,options).serialized_json
         end

         def options            
            @options ||= { include: %i[lumps] }
         end


  end


          

**Source Serializer**
class SourceSerializer
  include FastJsonapi::ObjectSerializer
  attributes :title, :description, :image, :sourcetype, :category, :subcategory, :username, :first_name, :last_name, :email

 has_many :lumps
 has_many :urls
end


**Lump Serializer**

class LumpSerializer
  include FastJsonapi::ObjectSerializer
  attributes :body, :preview, :title, :link, :image, :description, :image
end

**Source Model**

class Source < ApplicationRecord
  has_many :lumps
  has_many :urls
  has_many :user_sources
  has_many :users, through: :user_sources
  validates :username, presence: true, uniqueness: {case_sensitive: false },
  length: {minimum: 3, maximum:25}
  VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
end

**Lump Model**
class Lump < ApplicationRecord
  belongs_to :source   
end

DaBus
  • 1
  • 1

1 Answers1

0

Simple answer, created a new verb in Source_Controller, added a route, and created date limited query. Passed the query to LumpSerializer and was done.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
DaBus
  • 1
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 28 '22 at 01:44
  • I'm using axios to pull data from fastjsonapi, there is one to many relationship, the source pulls all the included "lumps". There are several "sources" that have as many as 3K results. I want limit the included results to just new daily results, which are normally below 50 results a day. – DaBus Mar 30 '22 at 13:35