price-point-api/app/controllers/concerns/renderable.rb

20 lines
502 B
Ruby
Raw Permalink Normal View History

2026-06-10 15:51:32 +00:00
# frozen_string_literal: true
2026-06-10 16:16:28 +00:00
module Renderable
2026-06-10 15:51:32 +00:00
extend ActiveSupport::Concern
def render_success(data = nil, status = :ok, meta = {})
body = { success: true }
body[:data] = data if data
body[:meta] = meta if meta.present?
2026-06-10 16:16:28 +00:00
render json: body, status:
2026-06-10 15:51:32 +00:00
end
2026-06-10 16:16:28 +00:00
def render_error(message, status = :unprocessable_entity, details: nil)
body = { success: false, error: { message: } }
body[:error][:details] = details if details.present?
render json: body, status:
2026-06-10 15:51:32 +00:00
end
end