mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-13 04:00:21 +00:00
Create Api::BaseController to allow use of ActiveModelSerializers
Also add index action to Api::CustomersController
This commit is contained in:
13
app/controllers/api/base_controller.rb
Normal file
13
app/controllers/api/base_controller.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
# Base controller for OFN's API
|
||||
# Includes the minimum machinery required by ActiveModelSerializers
|
||||
module Api
|
||||
class BaseController < Spree::Api::BaseController
|
||||
# Need to include these because Spree::Api::BaseContoller inherits
|
||||
# from ActionController::Metal rather than ActionController::Base
|
||||
# and they are required by ActiveModelSerializers
|
||||
include ActionController::Serialization
|
||||
include ActionController::UrlFor
|
||||
include Rails.application.routes.url_helpers
|
||||
use_renderers :json
|
||||
end
|
||||
end
|
||||
@@ -1,13 +1,16 @@
|
||||
module Api
|
||||
class CustomersController < Spree::Api::BaseController
|
||||
respond_to :json
|
||||
class CustomersController < BaseController
|
||||
def index
|
||||
@customers = current_api_user.customers
|
||||
render json: @customers, each_serializer: CustomerSerializer
|
||||
end
|
||||
|
||||
def update
|
||||
@customer = Customer.find(params[:id])
|
||||
authorize! :update, @customer
|
||||
|
||||
if @customer.update_attributes(params[:customer])
|
||||
render text: @customer.id, :status => 200
|
||||
render json: @customer, serializer: CustomerSerializer, status: 200
|
||||
else
|
||||
invalid_resource!(@customer)
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
module Api
|
||||
class StatusesController < BaseController
|
||||
class StatusesController < ::BaseController
|
||||
respond_to :json
|
||||
|
||||
def job_queue
|
||||
|
||||
Reference in New Issue
Block a user