Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions app/controllers/published_databases_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

# Controller for the PublishedDatabase resource.
class PublishedDatabasesController < ApplicationController
def index
add_total_stat(params)
published_databases = PublishedDatabaseResource.all(params)
respond_with(published_databases)
end

def add_total_stat(params)
# don't return stats
end
end
20 changes: 20 additions & 0 deletions app/resources/published_database_resource.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

# Public resource for the PublishedDatabase object.
class PublishedDatabaseResource < ApplicationResource
primary_endpoint '/published_databases', [:index]

attribute :url, :string
attribute :updated_at, :datetime
attribute :created_at, :datetime

def base_scope
latest_id = PublishedDatabase.order(created_at: :desc).select(:id).limit(1)
PublishedDatabase.where(id: latest_id)
end

# Only return the latest database.
def default_page_size
1
end
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
resources :formats, only: %i[index show]
resources :illustrators, only: %i[index show]
resources :printings, only: %i[index show]
resources :published_databases, only: [:index]
resources :restrictions, only: %i[index show]
resources :reviews, only: %i[index show]
resources :rulings, only: %i[index show]
Expand Down
23 changes: 23 additions & 0 deletions spec/resources/published_database_resource_reads_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe PublishedDatabaseResource, type: :resource do
describe 'serialization' do
fixtures :published_databases

let(:new_db) { published_databases(:latest_db) }

it 'works and only returns the latest database' do
render
data = jsonapi_data

expect(data.length).to eq(1)

record = data[0]
expect(record.url).to eq(new_db.url)
expect(Time.parse(record.created_at).to_i).to eq(new_db.created_at.to_i)
expect(record.jsonapi_type).to eq('published_databases')
end
end
end
Loading