testy/app/controllers/stores_controller.rb
Mohammad Kanaan 2cc3c1a7dd
Some checks are pending
CI / scan_ruby (push) Waiting to run
CI / lint (push) Waiting to run
CI / test (push) Waiting to run
initial commit
2026-05-17 14:12:43 +03:00

51 lines
1 KiB
Ruby

class StoresController < ApplicationController
before_action :set_store, only: %i[ show update destroy ]
# GET /stores
def index
@stores = Store.all
render json: @stores
end
# GET /stores/1
def show
render json: @store
end
# POST /stores
def create
@store = Store.new(store_params)
if @store.save
render json: @store, status: :created, location: @store
else
render json: @store.errors, status: :unprocessable_content
end
end
# PATCH/PUT /stores/1
def update
if @store.update(store_params)
render json: @store
else
render json: @store.errors, status: :unprocessable_content
end
end
# DELETE /stores/1
def destroy
@store.destroy!
end
private
# Use callbacks to share common setup or constraints between actions.
def set_store
@store = Store.find(params.expect(:id))
end
# Only allow a list of trusted parameters through.
def store_params
params.expect(store: [ :name, :latitude, :longitude, :chain_id ])
end
end