* Change models and related files * Update controllers and specs * More renaming * Seek and destroy, I mean search and replace * Round up the stragglers * Ground control to Major Travis... * More fixes * PR feedback * Various fixes * Rename view * Fix list query builder * Unify request specs * Fix some API spec errors * Fix remaining API specs * Make spec conform to API * Fix leftover problems * Fix JS tests * Fix column name in select * Fix API specs * Fix search specs * Paging Mr. Travis
54 lines
1.4 KiB
Ruby
54 lines
1.4 KiB
Ruby
class Internal::ListingsController < Internal::ApplicationController
|
|
include ListingsToolkit
|
|
layout "internal"
|
|
|
|
def index
|
|
@listings =
|
|
Listing.includes(%i[user listing_category]).
|
|
page(params[:page]).order("bumped_at DESC").per(50)
|
|
|
|
@listings = @listings.published unless include_unpublished?
|
|
@listings = @listings.in_category(params[:filter]) if params[:filter].present?
|
|
end
|
|
|
|
def edit
|
|
@listing = Listing.find(params[:id])
|
|
end
|
|
|
|
def update
|
|
@listing = Listing.find(params[:id])
|
|
handle_publish_status if listing_params[:published]
|
|
bump_listing(@listing.cost) if listing_params[:action] == "bump"
|
|
update_listing_details
|
|
clear_listings_cache
|
|
flash[:success] = "Listing updated successfully"
|
|
redirect_to edit_internal_listing_path(@listing)
|
|
end
|
|
|
|
def destroy
|
|
@listing = Listing.find(params[:id])
|
|
@listing.destroy
|
|
flash[:warning] = "'#{@listing.title}' was destroyed successfully"
|
|
redirect_to internal_listings_path
|
|
end
|
|
|
|
private
|
|
|
|
ALLOWED_PARAMS = %i[
|
|
published body_markdown title category listing_category_id tag_list action
|
|
].freeze
|
|
private_constant :ALLOWED_PARAMS
|
|
|
|
def listing_params
|
|
params.require(:listing).permit(ALLOWED_PARAMS)
|
|
end
|
|
|
|
def handle_publish_status
|
|
unpublish_listing if listing_params[:published] == "0"
|
|
publish_listing if listing_params[:published] == "1"
|
|
end
|
|
|
|
def include_unpublished?
|
|
params[:include_unpublished] == "1"
|
|
end
|
|
end
|