Use jsonapi-rails to serialize API responses
All checks were successful
Run unit tests / unit_tests (pull_request) Successful in 3m17s
All checks were successful
Run unit tests / unit_tests (pull_request) Successful in 3m17s
This commit is contained in:
parent
7592479b38
commit
716b819de2
4
Gemfile
4
Gemfile
@ -68,4 +68,6 @@ gem "money"
|
||||
gem 'acts-as-taggable-on'
|
||||
|
||||
gem "rubytree"
|
||||
gem 'react-rails'
|
||||
gem 'react-rails'
|
||||
gem 'rack-cors'
|
||||
gem 'jsonapi-rails'
|
15
Gemfile.lock
15
Gemfile.lock
@ -122,6 +122,17 @@ GEM
|
||||
actionview (>= 5.0.0)
|
||||
activesupport (>= 5.0.0)
|
||||
json (2.7.2)
|
||||
jsonapi-deserializable (0.2.0)
|
||||
jsonapi-parser (0.1.1)
|
||||
jsonapi-rails (0.4.1)
|
||||
jsonapi-parser (~> 0.1.0)
|
||||
jsonapi-rb (~> 0.5.0)
|
||||
jsonapi-rb (0.5.0)
|
||||
jsonapi-deserializable (~> 0.2.0)
|
||||
jsonapi-serializable (~> 0.3.0)
|
||||
jsonapi-renderer (0.2.2)
|
||||
jsonapi-serializable (0.3.1)
|
||||
jsonapi-renderer (~> 0.2.0)
|
||||
loofah (2.22.0)
|
||||
crass (~> 1.0.2)
|
||||
nokogiri (>= 1.12.0)
|
||||
@ -170,6 +181,8 @@ GEM
|
||||
nio4r (~> 2.0)
|
||||
racc (1.8.1)
|
||||
rack (3.1.7)
|
||||
rack-cors (2.0.2)
|
||||
rack (>= 2.0.0)
|
||||
rack-session (2.0.0)
|
||||
rack (>= 3.0.0)
|
||||
rack-test (2.1.0)
|
||||
@ -286,10 +299,12 @@ DEPENDENCIES
|
||||
faker
|
||||
importmap-rails
|
||||
jbuilder
|
||||
jsonapi-rails
|
||||
money
|
||||
pg (~> 1.1)
|
||||
pry
|
||||
puma (>= 5.0)
|
||||
rack-cors
|
||||
rails (~> 7.1.3, >= 7.1.3.2)
|
||||
react-rails
|
||||
redis (>= 4.0.1)
|
||||
|
@ -9,6 +9,11 @@ class GuestsController < ApplicationController
|
||||
.left_outer_joins(:affinity_groups)
|
||||
.order('tags.name' => :asc)
|
||||
.includes(:affinity_groups, :unbreakable_bonds)
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.json { render jsonapi: @guests }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /guests/1 or /guests/1.json
|
||||
|
9
app/serializers/serializable_guest.rb
Normal file
9
app/serializers/serializable_guest.rb
Normal file
@ -0,0 +1,9 @@
|
||||
class SerializableGuest < JSONAPI::Serializable::Resource
|
||||
type 'guest'
|
||||
|
||||
attributes :id, :email
|
||||
|
||||
attribute :name do
|
||||
"#{@object.first_name} #{@object.last_name}"
|
||||
end
|
||||
end
|
8
config/initializers/cors.rb
Normal file
8
config/initializers/cors.rb
Normal file
@ -0,0 +1,8 @@
|
||||
# config/initializers/cors.rb
|
||||
|
||||
Rails.application.config.middleware.insert_before 0, Rack::Cors do
|
||||
allow do
|
||||
origins '*'
|
||||
resource '*', headers: :any, methods: [:get, :post, :patch, :put, :delete]
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user