price-point-api/app/controllers/price_reports_controller.rb

57 lines
1.3 KiB
Ruby
Raw Permalink Normal View History

2026-05-17 11:12:43 +00:00
class PriceReportsController < ApplicationController
before_action :set_price_report, only: %i[ show update destroy ]
# GET /price_reports
def index
2026-05-30 16:15:24 +00:00
@product = Product.find(params[:product_id])
@price_reports = @product.price_reports
2026-05-17 11:12:43 +00:00
render json: @price_reports
end
# GET /price_reports/1
def show
render json: @price_report
end
# POST /price_reports
def create
@price_report = PriceReport.new(price_report_params)
if @price_report.save
render json: @price_report, status: :created, location: @price_report
else
render json: @price_report.errors, status: :unprocessable_content
end
end
# PATCH/PUT /price_reports/1
def update
if @price_report.update(price_report_params)
render json: @price_report
else
render json: @price_report.errors, status: :unprocessable_content
end
end
2026-05-30 16:15:24 +00:00
def upvote
end
2026-05-17 11:12:43 +00:00
# DELETE /price_reports/1
def destroy
@price_report.destroy!
end
private
# Use callbacks to share common setup or constraints between actions.
def set_price_report
@price_report = PriceReport.find(params.expect(:id))
end
# Only allow a list of trusted parameters through.
def price_report_params
2026-05-30 16:15:24 +00:00
params.require(:price_report).permit(:price, :discount_price, :store_id)
2026-05-17 11:12:43 +00:00
end
end