price-point-api/app/controllers/price_reports_controller.rb
Mohammad Kanaan 5a9f9ee10c WIP 1
2026-05-30 19:15:24 +03:00

56 lines
1.3 KiB
Ruby

class PriceReportsController < ApplicationController
before_action :set_price_report, only: %i[ show update destroy ]
# GET /price_reports
def index
@product = Product.find(params[:product_id])
@price_reports = @product.price_reports
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
def upvote
end
# 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
params.require(:price_report).permit(:price, :discount_price, :store_id)
end
end