Help with endpoint for a non-ActiveRecord model without a database table
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 20/100
調査の方向性
CalendarEventモデルの例とApi::V3::CalendarEventsControllerから始め、次にJSONAPI::ResourceSerializerがマッピングされたActiveModel配列をどのように処理するかを追跡します。204 No Contentレスポンスを再現し、ActiveRecordではないモデルに対するresourceとserializerの挙動を調査します。サポートされているシリアライズ方法を特定するか、必要な統合変更を文書化できれば完了です。
索引モデルが issue の本文から書いたものです。
説明
I have a non-ActiveRercord model without a database table I am trying to create an API endpoint for. The data for this model is populated dynamically with custom SQL and provides generic relations to real ActiveRecords.
Because of all the magic happening with JSONAPI Resources I am having a hard time serializing the array of ActiveModels successfully. Am wondering what the best approach for this might be? I've tried some monkey patching without success and would appreciate guidance
model example
class CalendarEvent
include ActiveModel::Model
attr_accessor(
:id,
:title,
# etc etc
)
def self.modelize(record)
return CalendarEvent.new(record)
end
def self.records(person_id, start_date, end_date, options = {})
sql = "select 'some custom sql' from various_table where serious_magic_happens"
records = ActiveRecord::Base.connection.execute(sql)
records = records.map{ |r| self.modelize(r) } # returns an Array of CalendarEvent::Class
end
end
controller attempt
class Api::V3::CalendarEventsController < Api::V3::ApiController
def index
records = CalendarEvent.records(1686, '2017-07-01', '2017-07-31')
resources = records.map { |r| Api::V3::CalendarEventResource.new(r, nil) }
JSONAPI::ResourceSerializer.new(Api::V3::CalendarEventResource).serialize_to_hash(resources)
end
end
The above controller returns a 204 No Content even though I am passing serialize_to_hash an array ... am I misunderstanding how this should work ? Or is there a better way?
Thanks!
- 主要言語
- Ruby
- スター
- 2.3k
- フォーク
- 546
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
JSONAPI-Resources/jsonapi-resources のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 50/100
JSONAPI-Resources/jsonapi-resources#1488 · コメント 1 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 42/100
JSONAPI-Resources/jsonapi-resources#1479 · コメント 2 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 30/100
JSONAPI-Resources/jsonapi-resources#1477 · コメント 3 件 · リアクション 1 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
JSONAPI-Resources/jsonapi-resources の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
bug
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
riscv/riscv-unified-db#2626 ·
-
Component: GLib
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
ds-drift
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
we-promise/sure#3693 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
simp/pupmod-simp-simp#395 ·